Issue6335: RecordInlineCell tree refactor with RecordInlineCellContext (#6537)
Fixes [#6335](https://github.com/twentyhq/twenty/issues/6335) This pull request is for issue [#6335](https://github.com/twentyhq/twenty/issues/6335): Refactor RecordInlineCell tree with a Context to avoid props drilling. For the refactoring, this PR made changes as below: - Created new script RecordInlineCellContext.tsx: Defining a context to pass in useContext() - Updated RecordInlineCell.tsx: Passing the necessary props as context values, wrapping with RecordInlineCellContext.Provider - Updated RecordInlineCellContainer.tsx: Passing the props to RecordInlineContainer as RecordInlineCellContext - Updated RecordInlineCellDisplayMode.tsx: retrieves values from useRecordInlineCellContext instead of directly assigning them - RecordInlineCellValue.tsx: Removed values passed through <RecordInlineCellDisplayMode> as they are now retrieved through useRecordInlineCellContext + Removed the null check for RecordInlineCellContextProps. Using RecordInlineCellContext, I believe the context goes to the top of the hierarchy and passed to the required layers without going through several layers. However, please let me know if I understood the issue incorrectly or it is not solved properly. Thank you in advance for your review! --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@ -14,6 +14,7 @@ import { FieldContext } from '@/object-record/record-field/contexts/FieldContext
|
||||
import { FieldFocusContextProvider } from '@/object-record/record-field/contexts/FieldFocusContextProvider';
|
||||
import { RecordFieldInputScope } from '@/object-record/record-field/scopes/RecordFieldInputScope';
|
||||
import { RecordInlineCellContainer } from '@/object-record/record-inline-cell/components/RecordInlineCellContainer';
|
||||
import { RecordInlineCellContext } from '@/object-record/record-inline-cell/components/RecordInlineCellContext';
|
||||
import { useInlineCell } from '@/object-record/record-inline-cell/hooks/useInlineCell';
|
||||
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
||||
|
||||
@ -65,30 +66,36 @@ export const ActivityTargetsInlineCell = ({
|
||||
<FieldFocusContextProvider>
|
||||
{ActivityTargetsContextProvider && (
|
||||
<ActivityTargetsContextProvider>
|
||||
<RecordInlineCellContainer
|
||||
buttonIcon={IconPencil}
|
||||
customEditHotkeyScope={{
|
||||
scope: ActivityEditorHotkeyScope.ActivityTargets,
|
||||
<RecordInlineCellContext.Provider
|
||||
value={{
|
||||
buttonIcon: IconPencil,
|
||||
customEditHotkeyScope: {
|
||||
scope: ActivityEditorHotkeyScope.ActivityTargets,
|
||||
},
|
||||
IconLabel: showLabel ? IconArrowUpRight : undefined,
|
||||
showLabel: showLabel,
|
||||
readonly: readonly,
|
||||
labelWidth: fieldDefinition?.labelWidth,
|
||||
editModeContent: (
|
||||
<ActivityTargetInlineCellEditMode
|
||||
activity={activity}
|
||||
activityTargetWithTargetRecords={
|
||||
activityTargetObjectRecords
|
||||
}
|
||||
activityObjectNameSingular={activityObjectNameSingular}
|
||||
/>
|
||||
),
|
||||
label: 'Relations',
|
||||
displayModeContent: (
|
||||
<ActivityTargetChips
|
||||
activityTargetObjectRecords={activityTargetObjectRecords}
|
||||
maxWidth={maxWidth}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
IconLabel={showLabel ? IconArrowUpRight : undefined}
|
||||
showLabel={showLabel}
|
||||
readonly={readonly}
|
||||
labelWidth={fieldDefinition?.labelWidth}
|
||||
editModeContent={
|
||||
<ActivityTargetInlineCellEditMode
|
||||
activity={activity}
|
||||
activityTargetWithTargetRecords={activityTargetObjectRecords}
|
||||
activityObjectNameSingular={activityObjectNameSingular}
|
||||
/>
|
||||
}
|
||||
label="Relations"
|
||||
displayModeContent={
|
||||
<ActivityTargetChips
|
||||
activityTargetObjectRecords={activityTargetObjectRecords}
|
||||
maxWidth={maxWidth}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
>
|
||||
<RecordInlineCellContainer />
|
||||
</RecordInlineCellContext.Provider>
|
||||
</ActivityTargetsContextProvider>
|
||||
)}
|
||||
</FieldFocusContextProvider>
|
||||
|
||||
Reference in New Issue
Block a user