-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: RightDrawer doesn't save context values when clickedOutside (#7729)
## Description - This PR fixes #7728 ## Changes https://github.com/user-attachments/assets/1e66cab3-9009-4c01-9ac6-22651b0ff5e7 --------- Co-authored-by: bosiraphael <[email protected]> Co-authored-by: Lucas Bordeau <[email protected]>
- Loading branch information
1 parent
7f51eb8
commit 18d04de
Showing
3 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...modules/object-record/record-right-drawer/components/RightDrawerTitleRecordInlineCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { FieldContext } from '@/object-record/record-field/contexts/FieldContext'; | ||
import { usePersistField } from '@/object-record/record-field/hooks/usePersistField'; | ||
import { useRecordFieldInput } from '@/object-record/record-field/hooks/useRecordFieldInput'; | ||
import { RecordInlineCell } from '@/object-record/record-inline-cell/components/RecordInlineCell'; | ||
import { useInlineCell } from '@/object-record/record-inline-cell/hooks/useInlineCell'; | ||
import { useListenRightDrawerClose } from '@/ui/layout/right-drawer/hooks/useListenRightDrawerClose'; | ||
import { useContext } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
// TODO: this should be better implemented if we refactor field input so that it's easier to implement logic like that | ||
// Idea : maybe we could use draftValue instead of the newValue in the events | ||
// Idea : we can remove all our listeners in the many input types and replace them with a onClose event that gives the event type | ||
// (tab, shift-tab, click-outside, escape, enter) and the newValue, that will reduce the boilerplate | ||
// and also the need to have our difficult to understand persist logic | ||
// the goal would be that we could easily call usePersistField anywhere under a FieldContext and it would work | ||
export const RightDrawerTitleRecordInlineCell = () => { | ||
const { closeInlineCell } = useInlineCell(); | ||
const persistField = usePersistField(); | ||
|
||
const { recordId, fieldDefinition } = useContext(FieldContext); | ||
|
||
const { getDraftValueSelector } = useRecordFieldInput<unknown>( | ||
`${recordId}-${fieldDefinition.metadata.fieldName}`, | ||
); | ||
|
||
const draftValue = useRecoilValue(getDraftValueSelector()); | ||
|
||
useListenRightDrawerClose(() => { | ||
persistField(draftValue); | ||
closeInlineCell(); | ||
}); | ||
|
||
return <RecordInlineCell />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters