-
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.
8978 add navigation inside the command menu for showpage (#9103)
Closes #8978 - Added new options in the actions config files: `shortLabel`, `availableOn` - Added two actions: Navigate to previous records and Navigate to next records - Modified `useRecordShowPagePagination` to loop on records when we are on first record and we hit previous or when we are on last record and we hit next - Introduced a new component state `contextStoreCurrentViewTypeComponentState`
- Loading branch information
1 parent
bb8c763
commit b033a50
Showing
22 changed files
with
528 additions
and
146 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
...cord-actions/single-record/components/ShowPageSingleRecordActionMenuEntrySetterEffect.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,76 @@ | ||
import { getActionConfig } from '@/action-menu/actions/record-actions/single-record/utils/getActionConfig'; | ||
import { ActionAvailableOn } from '@/action-menu/actions/types/actionAvailableOn'; | ||
import { useActionMenuEntries } from '@/action-menu/hooks/useActionMenuEntries'; | ||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState'; | ||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; | ||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled'; | ||
import { useEffect } from 'react'; | ||
import { isDefined } from 'twenty-ui'; | ||
|
||
export const ShowPageSingleRecordActionMenuEntrySetterEffect = ({ | ||
objectMetadataItem, | ||
}: { | ||
objectMetadataItem: ObjectMetadataItem; | ||
}) => { | ||
const isPageHeaderV2Enabled = useIsFeatureEnabled( | ||
'IS_PAGE_HEADER_V2_ENABLED', | ||
); | ||
|
||
const actionConfig = getActionConfig( | ||
objectMetadataItem, | ||
isPageHeaderV2Enabled, | ||
); | ||
|
||
const { addActionMenuEntry, removeActionMenuEntry } = useActionMenuEntries(); | ||
|
||
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2( | ||
contextStoreTargetedRecordsRuleComponentState, | ||
); | ||
|
||
const selectedRecordId = | ||
contextStoreTargetedRecordsRule.mode === 'selection' | ||
? contextStoreTargetedRecordsRule.selectedRecordIds[0] | ||
: undefined; | ||
|
||
if (!isDefined(selectedRecordId)) { | ||
throw new Error('Selected record ID is required'); | ||
} | ||
|
||
const actionMenuEntries = Object.values(actionConfig ?? {}) | ||
.filter((action) => | ||
action.availableOn?.includes(ActionAvailableOn.SHOW_PAGE), | ||
) | ||
.map((action) => { | ||
const { shouldBeRegistered, onClick, ConfirmationModal } = | ||
action.actionHook({ | ||
recordId: selectedRecordId, | ||
objectMetadataItem, | ||
}); | ||
|
||
if (shouldBeRegistered) { | ||
return { | ||
...action, | ||
onClick, | ||
ConfirmationModal, | ||
}; | ||
} | ||
|
||
return undefined; | ||
}) | ||
.filter(isDefined); | ||
|
||
useEffect(() => { | ||
for (const action of actionMenuEntries) { | ||
addActionMenuEntry(action); | ||
} | ||
|
||
return () => { | ||
for (const action of actionMenuEntries) { | ||
removeActionMenuEntry(action.key); | ||
} | ||
}; | ||
}, [actionMenuEntries, addActionMenuEntry, removeActionMenuEntry]); | ||
|
||
return null; | ||
}; |
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
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
15 changes: 15 additions & 0 deletions
15
...u/actions/record-actions/single-record/hooks/useNavigateToNextRecordSingleRecordAction.ts
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,15 @@ | ||
import { SingleRecordActionHookWithObjectMetadataItem } from '@/action-menu/actions/types/singleRecordActionHook'; | ||
import { useRecordShowPagePagination } from '@/object-record/record-show/hooks/useRecordShowPagePagination'; | ||
|
||
export const useNavigateToNextRecordSingleRecordAction: SingleRecordActionHookWithObjectMetadataItem = | ||
({ recordId, objectMetadataItem }) => { | ||
const { navigateToNextRecord } = useRecordShowPagePagination( | ||
objectMetadataItem.nameSingular, | ||
recordId, | ||
); | ||
|
||
return { | ||
shouldBeRegistered: true, | ||
onClick: navigateToNextRecord, | ||
}; | ||
}; |
15 changes: 15 additions & 0 deletions
15
...tions/record-actions/single-record/hooks/useNavigateToPreviousRecordSingleRecordAction.ts
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,15 @@ | ||
import { SingleRecordActionHookWithObjectMetadataItem } from '@/action-menu/actions/types/singleRecordActionHook'; | ||
import { useRecordShowPagePagination } from '@/object-record/record-show/hooks/useRecordShowPagePagination'; | ||
|
||
export const useNavigateToPreviousRecordSingleRecordAction: SingleRecordActionHookWithObjectMetadataItem = | ||
({ recordId, objectMetadataItem }) => { | ||
const { navigateToPreviousRecord } = useRecordShowPagePagination( | ||
objectMetadataItem.nameSingular, | ||
recordId, | ||
); | ||
|
||
return { | ||
shouldBeRegistered: true, | ||
onClick: navigateToPreviousRecord, | ||
}; | ||
}; |
Oops, something went wrong.