8414 add records selection context inside the command menu (#8610)
Closes #8414 https://github.com/user-attachments/assets/a6aeb50a-b57d-43db-a839-4627c49b4155
This commit is contained in:
@ -1,4 +1,8 @@
|
||||
import { useActionMenuEntries } from '@/action-menu/hooks/useActionMenuEntries';
|
||||
import {
|
||||
ActionMenuEntryScope,
|
||||
ActionMenuEntryType,
|
||||
} from '@/action-menu/types/ActionMenuEntry';
|
||||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useAllActiveWorkflowVersions } from '@/workflow/hooks/useAllActiveWorkflowVersions';
|
||||
@ -28,9 +32,9 @@ export const WorkflowRunActionEffect = () => {
|
||||
activeWorkflowVersion,
|
||||
] of activeWorkflowVersions.entries()) {
|
||||
addActionMenuEntry({
|
||||
type: 'workflow-run',
|
||||
type: ActionMenuEntryType.WorkflowRun,
|
||||
key: `workflow-run-${activeWorkflowVersion.id}`,
|
||||
scope: 'global',
|
||||
scope: ActionMenuEntryScope.Global,
|
||||
label: capitalize(activeWorkflowVersion.workflow.name),
|
||||
position: index,
|
||||
Icon: IconSettingsAutomation,
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext';
|
||||
import { useActionMenuEntries } from '@/action-menu/hooks/useActionMenuEntries';
|
||||
import {
|
||||
ActionMenuEntryScope,
|
||||
ActionMenuEntryType,
|
||||
} from '@/action-menu/types/ActionMenuEntry';
|
||||
import { contextStoreFiltersComponentState } from '@/context-store/states/contextStoreFiltersComponentState';
|
||||
import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-store/states/contextStoreNumberOfSelectedRecordsComponentState';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
@ -105,8 +109,8 @@ export const DeleteRecordsActionEffect = ({
|
||||
useEffect(() => {
|
||||
if (canDelete) {
|
||||
addActionMenuEntry({
|
||||
type: 'standard',
|
||||
scope: 'record-selection',
|
||||
type: ActionMenuEntryType.Standard,
|
||||
scope: ActionMenuEntryScope.RecordSelection,
|
||||
key: 'delete',
|
||||
label: 'Delete',
|
||||
position,
|
||||
|
||||
@ -4,6 +4,10 @@ import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||
import { IconDatabaseExport } from 'twenty-ui';
|
||||
|
||||
import {
|
||||
ActionMenuEntryScope,
|
||||
ActionMenuEntryType,
|
||||
} from '@/action-menu/types/ActionMenuEntry';
|
||||
import {
|
||||
displayedExportProgress,
|
||||
useExportRecords,
|
||||
@ -31,8 +35,11 @@ export const ExportRecordsActionEffect = ({
|
||||
|
||||
useEffect(() => {
|
||||
addActionMenuEntry({
|
||||
type: 'standard',
|
||||
scope: 'record-selection',
|
||||
type: ActionMenuEntryType.Standard,
|
||||
scope:
|
||||
contextStoreNumberOfSelectedRecords > 0
|
||||
? ActionMenuEntryScope.RecordSelection
|
||||
: ActionMenuEntryScope.Global,
|
||||
key: 'export',
|
||||
position,
|
||||
label: displayedExportProgress(progress),
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
import { useActionMenuEntries } from '@/action-menu/hooks/useActionMenuEntries';
|
||||
import {
|
||||
ActionMenuEntryScope,
|
||||
ActionMenuEntryType,
|
||||
} from '@/action-menu/types/ActionMenuEntry';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { useCreateFavorite } from '@/favorites/hooks/useCreateFavorite';
|
||||
import { useDeleteFavorite } from '@/favorites/hooks/useDeleteFavorite';
|
||||
@ -50,8 +54,8 @@ export const ManageFavoritesActionEffect = ({
|
||||
}
|
||||
|
||||
addActionMenuEntry({
|
||||
type: 'standard',
|
||||
scope: 'record-selection',
|
||||
type: ActionMenuEntryType.Standard,
|
||||
scope: ActionMenuEntryScope.RecordSelection,
|
||||
key: 'manage-favorites',
|
||||
label: isFavorite ? 'Remove from favorites' : 'Add to favorites',
|
||||
position,
|
||||
|
||||
@ -7,6 +7,7 @@ import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-sto
|
||||
import { useObjectMetadataItemById } from '@/object-metadata/hooks/useObjectMetadataItemById';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||
import { isDefined } from 'twenty-ui';
|
||||
|
||||
const noSelectionRecordActionEffects = [ExportRecordsActionEffect];
|
||||
|
||||
@ -21,25 +22,33 @@ const multipleRecordActionEffects = [
|
||||
];
|
||||
|
||||
export const RecordActionMenuEntriesSetter = () => {
|
||||
const contextStoreNumberOfSelectedRecords = useRecoilComponentValueV2(
|
||||
contextStoreNumberOfSelectedRecordsComponentState,
|
||||
);
|
||||
|
||||
const contextStoreCurrentObjectMetadataId = useRecoilComponentValueV2(
|
||||
contextStoreCurrentObjectMetadataIdComponentState,
|
||||
);
|
||||
|
||||
if (!isDefined(contextStoreCurrentObjectMetadataId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ActionEffects objectMetadataItemId={contextStoreCurrentObjectMetadataId} />
|
||||
);
|
||||
};
|
||||
|
||||
const ActionEffects = ({
|
||||
objectMetadataItemId,
|
||||
}: {
|
||||
objectMetadataItemId: string;
|
||||
}) => {
|
||||
const { objectMetadataItem } = useObjectMetadataItemById({
|
||||
objectId: contextStoreCurrentObjectMetadataId ?? '',
|
||||
objectId: objectMetadataItemId,
|
||||
});
|
||||
|
||||
const isWorkflowEnabled = useIsFeatureEnabled('IS_WORKFLOW_ENABLED');
|
||||
const contextStoreNumberOfSelectedRecords = useRecoilComponentValueV2(
|
||||
contextStoreNumberOfSelectedRecordsComponentState,
|
||||
);
|
||||
|
||||
if (!objectMetadataItem) {
|
||||
throw new Error(
|
||||
`Object metadata item not found for id ${contextStoreCurrentObjectMetadataId}`,
|
||||
);
|
||||
}
|
||||
const isWorkflowEnabled = useIsFeatureEnabled('IS_WORKFLOW_ENABLED');
|
||||
|
||||
const actions =
|
||||
contextStoreNumberOfSelectedRecords === 0
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
import { useActionMenuEntries } from '@/action-menu/hooks/useActionMenuEntries';
|
||||
import {
|
||||
ActionMenuEntryScope,
|
||||
ActionMenuEntryType,
|
||||
} from '@/action-menu/types/ActionMenuEntry';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
@ -55,9 +59,9 @@ export const WorkflowRunRecordActionEffect = ({
|
||||
activeWorkflowVersion,
|
||||
] of activeWorkflowVersions.entries()) {
|
||||
addActionMenuEntry({
|
||||
type: 'workflow-run',
|
||||
type: ActionMenuEntryType.WorkflowRun,
|
||||
key: `workflow-run-${activeWorkflowVersion.id}`,
|
||||
scope: 'record-selection',
|
||||
scope: ActionMenuEntryScope.RecordSelection,
|
||||
label: capitalize(activeWorkflowVersion.workflow.name),
|
||||
position: index,
|
||||
Icon: IconSettingsAutomation,
|
||||
|
||||
Reference in New Issue
Block a user