refactor(command-menu-item): rename Actions to CommandMenuItem (#18489)
actions are being renamed to command menu item, they will be migrated to server and will be served as headless front components --------- Co-authored-by: Raphaël Bosi <71827178+bosiraphael@users.noreply.github.com>
This commit is contained in:
+204
@@ -0,0 +1,204 @@
|
||||
import { MultipleRecordsCommandKeys } from '@/command-menu-item/record/multiple-records/types/MultipleRecordsCommandKeys';
|
||||
import { NoSelectionRecordCommandKeys } from '@/command-menu-item/record/no-selection/types/NoSelectionRecordCommandKeys';
|
||||
import { CancelDashboardSingleRecordCommand } from '@/command-menu-item/record/single-record/dashboard/components/CancelDashboardSingleRecordCommand';
|
||||
import { DuplicateDashboardSingleRecordCommand } from '@/command-menu-item/record/single-record/dashboard/components/DuplicateDashboardSingleRecordCommand';
|
||||
import { EditDashboardSingleRecordCommand } from '@/command-menu-item/record/single-record/dashboard/components/EditDashboardSingleRecordCommand';
|
||||
import { SaveDashboardSingleRecordCommand } from '@/command-menu-item/record/single-record/dashboard/components/SaveDashboardSingleRecordCommand';
|
||||
import { DashboardSingleRecordCommandKeys } from '@/command-menu-item/record/single-record/dashboard/types/DashboardSingleRecordCommandKeys';
|
||||
import { SingleRecordCommandKeys } from '@/command-menu-item/record/single-record/types/SingleRecordCommandKeys';
|
||||
import { inheritCommandMenuItemsFromDefaultConfig } from '@/command-menu-item/record/utils/inheritCommandMenuItemsFromDefaultConfig';
|
||||
import { CommandMenuItemScope } from '@/command-menu-item/types/CommandMenuItemScope';
|
||||
import { CommandMenuItemType } from '@/command-menu-item/types/CommandMenuItemType';
|
||||
import { CommandMenuItemViewType } from 'twenty-shared/types';
|
||||
import { PageLayoutSingleRecordActionKeys } from '@/page-layout/actions/PageLayoutSingleRecordActionKeys';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
IconCancel,
|
||||
IconCopyPlus,
|
||||
IconDeviceFloppy,
|
||||
IconPencil,
|
||||
} from 'twenty-ui/display';
|
||||
|
||||
export const DASHBOARD_COMMAND_MENU_ITEMS_CONFIG =
|
||||
inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {
|
||||
[PageLayoutSingleRecordActionKeys.EDIT_LAYOUT]: {
|
||||
key: PageLayoutSingleRecordActionKeys.EDIT_LAYOUT,
|
||||
label: msg`Edit Dashboard`,
|
||||
shortLabel: msg`Edit`,
|
||||
isPinned: true,
|
||||
position: 3,
|
||||
Icon: IconPencil,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, objectPermissions }) =>
|
||||
isDefined(selectedRecord) &&
|
||||
!selectedRecord?.isRemote &&
|
||||
!isDefined(selectedRecord?.deletedAt) &&
|
||||
isDefined(selectedRecord?.pageLayoutId) &&
|
||||
objectPermissions.canUpdateObjectRecords,
|
||||
availableOn: [CommandMenuItemViewType.SHOW_PAGE],
|
||||
component: <EditDashboardSingleRecordCommand />,
|
||||
},
|
||||
[PageLayoutSingleRecordActionKeys.SAVE_LAYOUT]: {
|
||||
key: PageLayoutSingleRecordActionKeys.SAVE_LAYOUT,
|
||||
label: msg`Save Dashboard`,
|
||||
shortLabel: msg`Save`,
|
||||
isPinned: true,
|
||||
isPrimaryCTA: true,
|
||||
position: 4,
|
||||
Icon: IconDeviceFloppy,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, objectPermissions }) =>
|
||||
isDefined(selectedRecord) &&
|
||||
!selectedRecord?.isRemote &&
|
||||
!isDefined(selectedRecord?.deletedAt) &&
|
||||
isDefined(selectedRecord?.pageLayoutId) &&
|
||||
objectPermissions.canUpdateObjectRecords,
|
||||
availableOn: [CommandMenuItemViewType.PAGE_EDIT_MODE],
|
||||
component: <SaveDashboardSingleRecordCommand />,
|
||||
},
|
||||
[PageLayoutSingleRecordActionKeys.CANCEL_LAYOUT_EDITION]: {
|
||||
key: PageLayoutSingleRecordActionKeys.CANCEL_LAYOUT_EDITION,
|
||||
label: msg`Cancel Edition`,
|
||||
shortLabel: msg`Cancel`,
|
||||
isPinned: true,
|
||||
position: 5,
|
||||
Icon: IconCancel,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, objectPermissions }) =>
|
||||
isDefined(selectedRecord) &&
|
||||
!selectedRecord?.isRemote &&
|
||||
!isDefined(selectedRecord?.deletedAt) &&
|
||||
isDefined(selectedRecord?.pageLayoutId) &&
|
||||
objectPermissions.canUpdateObjectRecords,
|
||||
availableOn: [CommandMenuItemViewType.PAGE_EDIT_MODE],
|
||||
component: <CancelDashboardSingleRecordCommand />,
|
||||
},
|
||||
[DashboardSingleRecordCommandKeys.DUPLICATE_DASHBOARD]: {
|
||||
key: DashboardSingleRecordCommandKeys.DUPLICATE_DASHBOARD,
|
||||
label: msg`Duplicate Dashboard`,
|
||||
shortLabel: msg`Duplicate`,
|
||||
isPinned: false,
|
||||
position: 6,
|
||||
Icon: IconCopyPlus,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, objectPermissions }) =>
|
||||
isDefined(selectedRecord) &&
|
||||
!selectedRecord?.isRemote &&
|
||||
!isDefined(selectedRecord?.deletedAt) &&
|
||||
objectPermissions.canUpdateObjectRecords,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
],
|
||||
component: <DuplicateDashboardSingleRecordCommand />,
|
||||
},
|
||||
},
|
||||
commandKeys: [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
SingleRecordCommandKeys.REMOVE_FROM_FAVORITES,
|
||||
SingleRecordCommandKeys.DELETE,
|
||||
SingleRecordCommandKeys.DESTROY,
|
||||
SingleRecordCommandKeys.RESTORE,
|
||||
MultipleRecordsCommandKeys.DELETE,
|
||||
MultipleRecordsCommandKeys.DESTROY,
|
||||
MultipleRecordsCommandKeys.RESTORE,
|
||||
NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS,
|
||||
NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS,
|
||||
SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW,
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD,
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD,
|
||||
NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_PEOPLE,
|
||||
NoSelectionRecordCommandKeys.GO_TO_COMPANIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_SETTINGS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_TASKS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_NOTES,
|
||||
],
|
||||
propertiesToOverwrite: {
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD]: {
|
||||
position: 0,
|
||||
label: msg`Navigate to next dashboard`,
|
||||
},
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD]: {
|
||||
position: 1,
|
||||
label: msg`Navigate to previous dashboard`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: {
|
||||
position: 2,
|
||||
label: msg`Create new dashboard`,
|
||||
},
|
||||
[SingleRecordCommandKeys.DELETE]: {
|
||||
position: 7,
|
||||
label: msg`Delete dashboard`,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.DELETE]: {
|
||||
position: 12,
|
||||
label: msg`Delete dashboards`,
|
||||
},
|
||||
[SingleRecordCommandKeys.ADD_TO_FAVORITES]: {
|
||||
position: 8,
|
||||
isPinned: true,
|
||||
},
|
||||
[SingleRecordCommandKeys.REMOVE_FROM_FAVORITES]: {
|
||||
position: 9,
|
||||
isPinned: true,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW]: {
|
||||
position: 10,
|
||||
label: msg`Export dashboard`,
|
||||
},
|
||||
[SingleRecordCommandKeys.DESTROY]: {
|
||||
position: 11,
|
||||
label: msg`Permanently destroy dashboard`,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.DESTROY]: {
|
||||
position: 13,
|
||||
label: msg`Permanently destroy dashboards`,
|
||||
},
|
||||
[SingleRecordCommandKeys.RESTORE]: {
|
||||
position: 14,
|
||||
label: msg`Restore dashboard`,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.RESTORE]: {
|
||||
position: 15,
|
||||
label: msg`Restore dashboards`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS]: {
|
||||
position: 22,
|
||||
label: msg`See deleted dashboards`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS]: {
|
||||
position: 23,
|
||||
label: msg`Hide deleted dashboards`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS]: {
|
||||
position: 24,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_PEOPLE]: {
|
||||
position: 25,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_COMPANIES]: {
|
||||
position: 26,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES]: {
|
||||
position: 27,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_SETTINGS]: {
|
||||
position: 28,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_TASKS]: {
|
||||
position: 29,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_NOTES]: {
|
||||
position: 30,
|
||||
},
|
||||
},
|
||||
});
|
||||
+843
@@ -0,0 +1,843 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { DeleteMultipleRecordsCommand } from '@/command-menu-item/record/multiple-records/components/DeleteMultipleRecordsCommand';
|
||||
import { DestroyMultipleRecordsCommand } from '@/command-menu-item/record/multiple-records/components/DestroyMultipleRecordsCommand';
|
||||
import { ExportMultipleRecordsCommand } from '@/command-menu-item/record/multiple-records/components/ExportMultipleRecordsCommand';
|
||||
import { MergeMultipleRecordsCommand } from '@/command-menu-item/record/multiple-records/components/MergeMultipleRecordsCommand';
|
||||
import { RestoreMultipleRecordsCommand } from '@/command-menu-item/record/multiple-records/components/RestoreMultipleRecordsCommand';
|
||||
import { UpdateMultipleRecordsCommand } from '@/command-menu-item/record/multiple-records/components/UpdateMultipleRecordsCommand';
|
||||
import { MultipleRecordsCommandKeys } from '@/command-menu-item/record/multiple-records/types/MultipleRecordsCommandKeys';
|
||||
import { CreateNewIndexRecordNoSelectionRecordCommand } from '@/command-menu-item/record/no-selection/components/CreateNewIndexRecordNoSelectionRecordCommand';
|
||||
import { CreateNewViewNoSelectionRecordCommand } from '@/command-menu-item/record/no-selection/components/CreateNewViewNoSelectionRecordCommand';
|
||||
import { HideDeletedRecordsNoSelectionRecordCommand } from '@/command-menu-item/record/no-selection/components/HideDeletedRecordsNoSelectionRecordCommand';
|
||||
import { ImportRecordsNoSelectionRecordCommand } from '@/command-menu-item/record/no-selection/components/ImportRecordsNoSelectionRecordCommand';
|
||||
import { SeeDeletedRecordsNoSelectionRecordCommand } from '@/command-menu-item/record/no-selection/components/SeeDeletedRecordsNoSelectionRecordCommand';
|
||||
import { NoSelectionRecordCommandKeys } from '@/command-menu-item/record/no-selection/types/NoSelectionRecordCommandKeys';
|
||||
import { AddToFavoritesSingleRecordCommand } from '@/command-menu-item/record/single-record/components/AddToFavoritesSingleRecordCommand';
|
||||
import { DeleteSingleRecordCommand } from '@/command-menu-item/record/single-record/components/DeleteSingleRecordCommand';
|
||||
import { DestroySingleRecordCommand } from '@/command-menu-item/record/single-record/components/DestroySingleRecordCommand';
|
||||
import { ExportNoteSingleRecordCommand } from '@/command-menu-item/record/single-record/components/ExportNoteSingleRecordCommand';
|
||||
import { ExportSingleRecordCommand } from '@/command-menu-item/record/single-record/components/ExportSingleRecordCommand';
|
||||
import { NavigateToNextRecordSingleRecordCommand } from '@/command-menu-item/record/single-record/components/NavigateToNextRecordSingleRecordCommand';
|
||||
import { NavigateToPreviousRecordSingleRecordCommand } from '@/command-menu-item/record/single-record/components/NavigateToPreviousRecordSingleRecordCommand';
|
||||
import { RemoveFromFavoritesSingleRecordCommand } from '@/command-menu-item/record/single-record/components/RemoveFromFavoritesSingleRecordCommand';
|
||||
import { RestoreSingleRecordCommand } from '@/command-menu-item/record/single-record/components/RestoreSingleRecordCommand';
|
||||
import { CancelRecordPageLayoutSingleRecordCommand } from '@/command-menu-item/record/single-record/record-page-layout/components/CancelRecordPageLayoutSingleRecordCommand';
|
||||
import { EditRecordPageLayoutSingleRecordCommand } from '@/command-menu-item/record/single-record/record-page-layout/components/EditRecordPageLayoutSingleRecordCommand';
|
||||
import { SaveRecordPageLayoutSingleRecordCommand } from '@/command-menu-item/record/single-record/record-page-layout/components/SaveRecordPageLayoutSingleRecordCommand';
|
||||
import { RecordPageLayoutSingleRecordCommandKeys } from '@/command-menu-item/record/single-record/record-page-layout/types/RecordPageLayoutSingleRecordCommandKeys';
|
||||
import { SingleRecordCommandKeys } from '@/command-menu-item/record/single-record/types/SingleRecordCommandKeys';
|
||||
import { type CommandMenuItemConfig } from '@/command-menu-item/types/CommandMenuItemConfig';
|
||||
import { CommandMenuItemScope } from '@/command-menu-item/types/CommandMenuItemScope';
|
||||
import { CommandMenuItemType } from '@/command-menu-item/types/CommandMenuItemType';
|
||||
import {
|
||||
CommandMenuItemViewType,
|
||||
CoreObjectNameSingular,
|
||||
AppPath,
|
||||
SettingsPath,
|
||||
} from 'twenty-shared/types';
|
||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||
import {
|
||||
BACKEND_BATCH_REQUEST_MAX_COUNT,
|
||||
MUTATION_MAX_MERGE_RECORDS,
|
||||
} from 'twenty-shared/constants';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import {
|
||||
IconArrowMerge,
|
||||
IconBuildingSkyscraper,
|
||||
IconCancel,
|
||||
IconCheckbox,
|
||||
IconChevronDown,
|
||||
IconChevronUp,
|
||||
IconDeviceFloppy,
|
||||
IconEdit,
|
||||
IconEyeOff,
|
||||
IconFileExport,
|
||||
IconFileImport,
|
||||
IconHeart,
|
||||
IconHeartOff,
|
||||
IconLayout,
|
||||
IconLayoutDashboard,
|
||||
IconPencil,
|
||||
IconPlus,
|
||||
IconRefresh,
|
||||
IconRotate2,
|
||||
IconSettings,
|
||||
IconSettingsAutomation,
|
||||
IconTargetArrow,
|
||||
IconTrash,
|
||||
IconTrashX,
|
||||
IconUser,
|
||||
} from 'twenty-ui/display';
|
||||
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
PermissionFlagType,
|
||||
FeatureFlagKey,
|
||||
} from '~/generated-metadata/graphql';
|
||||
|
||||
export const DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG: Record<
|
||||
| NoSelectionRecordCommandKeys
|
||||
| SingleRecordCommandKeys
|
||||
| MultipleRecordsCommandKeys
|
||||
| RecordPageLayoutSingleRecordCommandKeys,
|
||||
CommandMenuItemConfig
|
||||
> = {
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD,
|
||||
label: msg`Navigate to next record`,
|
||||
position: 0,
|
||||
isPinned: true,
|
||||
Icon: IconChevronDown,
|
||||
shouldBeRegistered: ({ isInSidePanel }) => !isInSidePanel,
|
||||
availableOn: [CommandMenuItemViewType.SHOW_PAGE],
|
||||
component: <NavigateToNextRecordSingleRecordCommand />,
|
||||
},
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD,
|
||||
label: msg`Navigate to previous record`,
|
||||
position: 1,
|
||||
isPinned: true,
|
||||
Icon: IconChevronUp,
|
||||
shouldBeRegistered: ({ isInSidePanel }) => !isInSidePanel,
|
||||
availableOn: [CommandMenuItemViewType.SHOW_PAGE],
|
||||
component: <NavigateToPreviousRecordSingleRecordCommand />,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
label: msg`Create new record`,
|
||||
shortLabel: msg`New record`,
|
||||
position: 2,
|
||||
isPinned: true,
|
||||
Icon: IconPlus,
|
||||
shouldBeRegistered: ({ objectPermissions, hasAnySoftDeleteFilterOnView }) =>
|
||||
(objectPermissions.canUpdateObjectRecords &&
|
||||
!hasAnySoftDeleteFilterOnView) ??
|
||||
false,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION],
|
||||
component: <CreateNewIndexRecordNoSelectionRecordCommand />,
|
||||
},
|
||||
[SingleRecordCommandKeys.DELETE]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.DELETE,
|
||||
label: msg`Delete`,
|
||||
shortLabel: msg`Delete`,
|
||||
position: 3,
|
||||
Icon: IconTrash,
|
||||
accent: 'default',
|
||||
isPinned: true,
|
||||
shouldBeRegistered: ({
|
||||
selectedRecord,
|
||||
hasAnySoftDeleteFilterOnView,
|
||||
objectPermissions,
|
||||
}) =>
|
||||
(isDefined(selectedRecord) &&
|
||||
!selectedRecord.isRemote &&
|
||||
!hasAnySoftDeleteFilterOnView &&
|
||||
objectPermissions.canSoftDeleteObjectRecords &&
|
||||
!isDefined(selectedRecord?.deletedAt)) ??
|
||||
false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
],
|
||||
component: <DeleteSingleRecordCommand />,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.DELETE]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: MultipleRecordsCommandKeys.DELETE,
|
||||
label: msg`Delete records`,
|
||||
shortLabel: msg`Delete`,
|
||||
position: 4,
|
||||
Icon: IconTrash,
|
||||
accent: 'default',
|
||||
isPinned: true,
|
||||
shouldBeRegistered: ({
|
||||
objectPermissions,
|
||||
isRemote,
|
||||
hasAnySoftDeleteFilterOnView,
|
||||
numberOfSelectedRecords,
|
||||
}) =>
|
||||
(objectPermissions.canSoftDeleteObjectRecords &&
|
||||
!isRemote &&
|
||||
!hasAnySoftDeleteFilterOnView &&
|
||||
isDefined(numberOfSelectedRecords) &&
|
||||
numberOfSelectedRecords < BACKEND_BATCH_REQUEST_MAX_COUNT) ??
|
||||
false,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION],
|
||||
component: <DeleteMultipleRecordsCommand />,
|
||||
},
|
||||
[SingleRecordCommandKeys.RESTORE]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.RESTORE,
|
||||
label: msg`Restore record`,
|
||||
shortLabel: msg`Restore`,
|
||||
position: 5,
|
||||
Icon: IconRefresh,
|
||||
accent: 'default',
|
||||
isPinned: true,
|
||||
shouldBeRegistered: ({
|
||||
selectedRecord,
|
||||
objectPermissions,
|
||||
isRemote,
|
||||
isShowPage,
|
||||
hasAnySoftDeleteFilterOnView,
|
||||
}) =>
|
||||
(!isRemote &&
|
||||
isDefined(selectedRecord?.deletedAt) &&
|
||||
objectPermissions.canSoftDeleteObjectRecords &&
|
||||
((isDefined(isShowPage) && isShowPage) ||
|
||||
(isDefined(hasAnySoftDeleteFilterOnView) &&
|
||||
hasAnySoftDeleteFilterOnView))) ??
|
||||
false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <RestoreSingleRecordCommand />,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.RESTORE]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: MultipleRecordsCommandKeys.RESTORE,
|
||||
label: msg`Restore records`,
|
||||
shortLabel: msg`Restore`,
|
||||
position: 6,
|
||||
Icon: IconRefresh,
|
||||
accent: 'default',
|
||||
isPinned: true,
|
||||
shouldBeRegistered: ({
|
||||
objectPermissions,
|
||||
isRemote,
|
||||
hasAnySoftDeleteFilterOnView,
|
||||
numberOfSelectedRecords,
|
||||
}) =>
|
||||
(objectPermissions.canSoftDeleteObjectRecords &&
|
||||
!isRemote &&
|
||||
isDefined(hasAnySoftDeleteFilterOnView) &&
|
||||
hasAnySoftDeleteFilterOnView &&
|
||||
isDefined(numberOfSelectedRecords) &&
|
||||
numberOfSelectedRecords < BACKEND_BATCH_REQUEST_MAX_COUNT) ??
|
||||
false,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION],
|
||||
component: <RestoreMultipleRecordsCommand />,
|
||||
},
|
||||
[SingleRecordCommandKeys.DESTROY]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.DESTROY,
|
||||
label: msg`Permanently destroy record`,
|
||||
shortLabel: msg`Destroy`,
|
||||
position: 7,
|
||||
Icon: IconTrashX,
|
||||
accent: 'danger',
|
||||
isPinned: true,
|
||||
shouldBeRegistered: ({ selectedRecord, objectPermissions, isRemote }) =>
|
||||
(objectPermissions.canDestroyObjectRecords &&
|
||||
!isRemote &&
|
||||
isDefined(selectedRecord?.deletedAt)) ??
|
||||
false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
],
|
||||
component: <DestroySingleRecordCommand />,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.DESTROY]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: MultipleRecordsCommandKeys.DESTROY,
|
||||
label: msg`Permanently destroy records`,
|
||||
shortLabel: msg`Destroy`,
|
||||
position: 8,
|
||||
Icon: IconTrashX,
|
||||
accent: 'danger',
|
||||
isPinned: true,
|
||||
shouldBeRegistered: ({
|
||||
objectPermissions,
|
||||
isRemote,
|
||||
hasAnySoftDeleteFilterOnView,
|
||||
numberOfSelectedRecords,
|
||||
}) =>
|
||||
(objectPermissions.canDestroyObjectRecords &&
|
||||
!isRemote &&
|
||||
isDefined(hasAnySoftDeleteFilterOnView) &&
|
||||
hasAnySoftDeleteFilterOnView &&
|
||||
isDefined(numberOfSelectedRecords) &&
|
||||
numberOfSelectedRecords < BACKEND_BATCH_REQUEST_MAX_COUNT) ??
|
||||
false,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION],
|
||||
component: <DestroyMultipleRecordsCommand />,
|
||||
},
|
||||
|
||||
[SingleRecordCommandKeys.ADD_TO_FAVORITES]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
label: msg`Add to favorites`,
|
||||
shortLabel: msg`Add to favorites`,
|
||||
position: 9,
|
||||
isPinned: true,
|
||||
Icon: IconHeart,
|
||||
shouldBeRegistered: ({
|
||||
selectedRecord,
|
||||
isFavorite,
|
||||
hasAnySoftDeleteFilterOnView,
|
||||
}) =>
|
||||
!selectedRecord?.isRemote &&
|
||||
!isFavorite &&
|
||||
!isDefined(selectedRecord?.deletedAt) &&
|
||||
!hasAnySoftDeleteFilterOnView,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
],
|
||||
component: <AddToFavoritesSingleRecordCommand />,
|
||||
},
|
||||
[SingleRecordCommandKeys.REMOVE_FROM_FAVORITES]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.REMOVE_FROM_FAVORITES,
|
||||
label: msg`Remove from favorites`,
|
||||
shortLabel: msg`Remove from favorites`,
|
||||
isPinned: true,
|
||||
position: 10,
|
||||
Icon: IconHeartOff,
|
||||
shouldBeRegistered: ({
|
||||
selectedRecord,
|
||||
isFavorite,
|
||||
hasAnySoftDeleteFilterOnView,
|
||||
}) =>
|
||||
isDefined(selectedRecord) &&
|
||||
!selectedRecord?.isRemote &&
|
||||
isDefined(isFavorite) &&
|
||||
isFavorite &&
|
||||
!isDefined(selectedRecord?.deletedAt) &&
|
||||
!hasAnySoftDeleteFilterOnView,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
],
|
||||
component: <RemoveFromFavoritesSingleRecordCommand />,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_NOTE_TO_PDF]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.EXPORT_NOTE_TO_PDF,
|
||||
label: msg`Export to PDF`,
|
||||
shortLabel: msg`Export`,
|
||||
position: 11,
|
||||
isPinned: false,
|
||||
Icon: IconFileExport,
|
||||
shouldBeRegistered: ({ selectedRecord, isNoteOrTask }) =>
|
||||
isDefined(isNoteOrTask) &&
|
||||
isNoteOrTask &&
|
||||
isNonEmptyString(selectedRecord?.bodyV2?.blocknote),
|
||||
availableOn: [CommandMenuItemViewType.SHOW_PAGE],
|
||||
component: <ExportNoteSingleRecordCommand />,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX,
|
||||
label: msg`Export`,
|
||||
shortLabel: msg`Export`,
|
||||
position: 12,
|
||||
Icon: IconFileExport,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: ({ selectedRecord }) =>
|
||||
isDefined(selectedRecord) && !selectedRecord.isRemote,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION],
|
||||
component: <ExportMultipleRecordsCommand />,
|
||||
requiredPermissionFlag: PermissionFlagType.EXPORT_CSV,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW,
|
||||
label: msg`Export`,
|
||||
shortLabel: msg`Export`,
|
||||
position: 13,
|
||||
Icon: IconFileExport,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: ({ selectedRecord }) =>
|
||||
isDefined(selectedRecord) && !selectedRecord.isRemote,
|
||||
availableOn: [CommandMenuItemViewType.SHOW_PAGE],
|
||||
component: <ExportSingleRecordCommand />,
|
||||
requiredPermissionFlag: PermissionFlagType.EXPORT_CSV,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.UPDATE]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: MultipleRecordsCommandKeys.UPDATE,
|
||||
label: msg`Update records`,
|
||||
shortLabel: msg`Update`,
|
||||
position: 14,
|
||||
Icon: IconEdit,
|
||||
accent: 'default',
|
||||
isPinned: true,
|
||||
shouldBeRegistered: ({ objectPermissions, isRemote }) =>
|
||||
objectPermissions.canUpdateObjectRecords && !isRemote,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION],
|
||||
component: <UpdateMultipleRecordsCommand />,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.MERGE]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: MultipleRecordsCommandKeys.MERGE,
|
||||
label: msg`Merge records`,
|
||||
shortLabel: msg`Merge`,
|
||||
position: 15,
|
||||
Icon: IconArrowMerge,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: ({
|
||||
objectMetadataItem,
|
||||
numberOfSelectedRecords,
|
||||
objectPermissions,
|
||||
}) =>
|
||||
isDefined(objectMetadataItem?.duplicateCriteria) &&
|
||||
isDefined(numberOfSelectedRecords) &&
|
||||
Boolean(objectPermissions.canUpdateObjectRecords) &&
|
||||
Boolean(objectPermissions.canDestroyObjectRecords) &&
|
||||
numberOfSelectedRecords <= MUTATION_MAX_MERGE_RECORDS,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION],
|
||||
component: <MergeMultipleRecordsCommand />,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.EXPORT]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: MultipleRecordsCommandKeys.EXPORT,
|
||||
label: msg`Export records`,
|
||||
shortLabel: msg`Export`,
|
||||
position: 16,
|
||||
Icon: IconFileExport,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: () => true,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION],
|
||||
component: <ExportMultipleRecordsCommand />,
|
||||
requiredPermissionFlag: PermissionFlagType.EXPORT_CSV,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.IMPORT_RECORDS]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: NoSelectionRecordCommandKeys.IMPORT_RECORDS,
|
||||
label: msg`Import records`,
|
||||
shortLabel: msg`Import`,
|
||||
position: 17,
|
||||
Icon: IconFileImport,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: ({ hasAnySoftDeleteFilterOnView }) =>
|
||||
!hasAnySoftDeleteFilterOnView,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION],
|
||||
component: <ImportRecordsNoSelectionRecordCommand />,
|
||||
requiredPermissionFlag: PermissionFlagType.IMPORT_CSV,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.EXPORT_VIEW]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: NoSelectionRecordCommandKeys.EXPORT_VIEW,
|
||||
label: msg`Export view`,
|
||||
shortLabel: msg`Export`,
|
||||
position: 18,
|
||||
Icon: IconFileExport,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: () => true,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION],
|
||||
component: <ExportMultipleRecordsCommand />,
|
||||
requiredPermissionFlag: PermissionFlagType.EXPORT_CSV,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS,
|
||||
label: msg`See deleted records`,
|
||||
shortLabel: msg`Deleted records`,
|
||||
position: 19,
|
||||
Icon: IconRotate2,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: ({ hasAnySoftDeleteFilterOnView }) =>
|
||||
!hasAnySoftDeleteFilterOnView,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION],
|
||||
component: <SeeDeletedRecordsNoSelectionRecordCommand />,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_VIEW]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: NoSelectionRecordCommandKeys.CREATE_NEW_VIEW,
|
||||
label: msg`Create View`,
|
||||
shortLabel: msg`Create View`,
|
||||
position: 20,
|
||||
Icon: IconLayout,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: ({ hasAnySoftDeleteFilterOnView }) =>
|
||||
!hasAnySoftDeleteFilterOnView,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION],
|
||||
component: <CreateNewViewNoSelectionRecordCommand />,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS,
|
||||
label: msg`Hide deleted records`,
|
||||
shortLabel: msg`Hide deleted`,
|
||||
position: 21,
|
||||
Icon: IconEyeOff,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: ({ hasAnySoftDeleteFilterOnView }) =>
|
||||
isDefined(hasAnySoftDeleteFilterOnView) && hasAnySoftDeleteFilterOnView,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION],
|
||||
component: <HideDeletedRecordsNoSelectionRecordCommand />,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS,
|
||||
label: msg`Go to Workflows`,
|
||||
shortLabel: msg`See Workflows`,
|
||||
position: 22,
|
||||
Icon: IconSettingsAutomation,
|
||||
accent: 'default',
|
||||
isPinned: false,
|
||||
shouldBeRegistered: ({
|
||||
objectMetadataItem,
|
||||
viewType,
|
||||
getTargetObjectReadPermission,
|
||||
}) =>
|
||||
getTargetObjectReadPermission(CoreObjectNameSingular.Workflow) &&
|
||||
(objectMetadataItem?.nameSingular !== CoreObjectNameSingular.Workflow ||
|
||||
viewType === CommandMenuItemViewType.SHOW_PAGE),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.PAGE_EDIT_MODE,
|
||||
],
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.Workflow }}
|
||||
/>
|
||||
),
|
||||
hotKeys: ['G', 'W'],
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_PEOPLE]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionRecordCommandKeys.GO_TO_PEOPLE,
|
||||
label: msg`Go to People`,
|
||||
shortLabel: msg`People`,
|
||||
position: 23,
|
||||
Icon: IconUser,
|
||||
isPinned: false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.PAGE_EDIT_MODE,
|
||||
],
|
||||
shouldBeRegistered: ({
|
||||
objectMetadataItem,
|
||||
viewType,
|
||||
getTargetObjectReadPermission,
|
||||
}) =>
|
||||
getTargetObjectReadPermission(CoreObjectNameSingular.Person) &&
|
||||
(objectMetadataItem?.nameSingular !== CoreObjectNameSingular.Person ||
|
||||
viewType === CommandMenuItemViewType.SHOW_PAGE),
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.Person }}
|
||||
/>
|
||||
),
|
||||
hotKeys: ['G', 'P'],
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_COMPANIES]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionRecordCommandKeys.GO_TO_COMPANIES,
|
||||
label: msg`Go to Companies`,
|
||||
shortLabel: msg`Companies`,
|
||||
position: 24,
|
||||
Icon: IconBuildingSkyscraper,
|
||||
isPinned: false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.PAGE_EDIT_MODE,
|
||||
],
|
||||
shouldBeRegistered: ({
|
||||
objectMetadataItem,
|
||||
viewType,
|
||||
getTargetObjectReadPermission,
|
||||
}) =>
|
||||
getTargetObjectReadPermission(CoreObjectNameSingular.Company) &&
|
||||
(objectMetadataItem?.nameSingular !== CoreObjectNameSingular.Company ||
|
||||
viewType === CommandMenuItemViewType.SHOW_PAGE),
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.Company }}
|
||||
/>
|
||||
),
|
||||
hotKeys: ['G', 'C'],
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS,
|
||||
label: msg`Go to Dashboards`,
|
||||
shortLabel: msg`Dashboards`,
|
||||
position: 25,
|
||||
Icon: IconLayoutDashboard,
|
||||
isPinned: false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
],
|
||||
shouldBeRegistered: ({
|
||||
objectMetadataItem,
|
||||
viewType,
|
||||
getTargetObjectReadPermission,
|
||||
}) =>
|
||||
getTargetObjectReadPermission(CoreObjectNameSingular.Dashboard) &&
|
||||
(objectMetadataItem?.nameSingular !== CoreObjectNameSingular.Dashboard ||
|
||||
viewType === CommandMenuItemViewType.SHOW_PAGE),
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.Dashboard }}
|
||||
/>
|
||||
),
|
||||
hotKeys: ['G', 'D'],
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES,
|
||||
label: msg`Go to Opportunities`,
|
||||
shortLabel: msg`Opportunities`,
|
||||
position: 26,
|
||||
Icon: IconTargetArrow,
|
||||
isPinned: false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.PAGE_EDIT_MODE,
|
||||
],
|
||||
shouldBeRegistered: ({
|
||||
objectMetadataItem,
|
||||
viewType,
|
||||
getTargetObjectReadPermission,
|
||||
}) =>
|
||||
getTargetObjectReadPermission(CoreObjectNameSingular.Opportunity) &&
|
||||
(objectMetadataItem?.nameSingular !==
|
||||
CoreObjectNameSingular.Opportunity ||
|
||||
viewType === CommandMenuItemViewType.SHOW_PAGE),
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.Opportunity }}
|
||||
/>
|
||||
),
|
||||
hotKeys: ['G', 'O'],
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_SETTINGS]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionRecordCommandKeys.GO_TO_SETTINGS,
|
||||
label: msg`Go to Settings`,
|
||||
shortLabel: msg`Settings`,
|
||||
position: 27,
|
||||
Icon: IconSettings,
|
||||
isPinned: false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
],
|
||||
shouldBeRegistered: () => true,
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.SettingsCatchAll}
|
||||
params={{
|
||||
'*': SettingsPath.ProfilePage,
|
||||
}}
|
||||
/>
|
||||
),
|
||||
hotKeys: ['G', 'S'],
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_TASKS]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionRecordCommandKeys.GO_TO_TASKS,
|
||||
label: msg`Go to Tasks`,
|
||||
shortLabel: msg`Tasks`,
|
||||
position: 28,
|
||||
Icon: IconCheckbox,
|
||||
isPinned: false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.PAGE_EDIT_MODE,
|
||||
],
|
||||
shouldBeRegistered: ({
|
||||
objectMetadataItem,
|
||||
viewType,
|
||||
getTargetObjectReadPermission,
|
||||
}) =>
|
||||
getTargetObjectReadPermission(CoreObjectNameSingular.Task) &&
|
||||
(objectMetadataItem?.nameSingular !== CoreObjectNameSingular.Task ||
|
||||
viewType === CommandMenuItemViewType.SHOW_PAGE),
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.Task }}
|
||||
/>
|
||||
),
|
||||
hotKeys: ['G', 'T'],
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_NOTES]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionRecordCommandKeys.GO_TO_NOTES,
|
||||
label: msg`Go to Notes`,
|
||||
shortLabel: msg`Notes`,
|
||||
position: 29,
|
||||
Icon: IconCheckbox,
|
||||
isPinned: false,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.PAGE_EDIT_MODE,
|
||||
],
|
||||
shouldBeRegistered: ({
|
||||
objectMetadataItem,
|
||||
viewType,
|
||||
getTargetObjectReadPermission,
|
||||
}) =>
|
||||
getTargetObjectReadPermission(CoreObjectNameSingular.Note) &&
|
||||
(objectMetadataItem?.nameSingular !== CoreObjectNameSingular.Note ||
|
||||
viewType === CommandMenuItemViewType.SHOW_PAGE),
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.Note }}
|
||||
/>
|
||||
),
|
||||
hotKeys: ['G', 'N'],
|
||||
},
|
||||
|
||||
[RecordPageLayoutSingleRecordCommandKeys.EDIT_RECORD_PAGE_LAYOUT]: {
|
||||
key: RecordPageLayoutSingleRecordCommandKeys.EDIT_RECORD_PAGE_LAYOUT,
|
||||
label: msg`Edit Page Layout`,
|
||||
shortLabel: msg`Edit Layout`,
|
||||
isPinned: true,
|
||||
position: 30,
|
||||
Icon: IconPencil,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
requiredPermissionFlag: PermissionFlagType.LAYOUTS,
|
||||
shouldBeRegistered: ({
|
||||
selectedRecord,
|
||||
objectPermissions,
|
||||
objectMetadataItem,
|
||||
isFeatureFlagEnabled,
|
||||
}) =>
|
||||
isFeatureFlagEnabled(
|
||||
FeatureFlagKey.IS_RECORD_PAGE_LAYOUT_EDITING_ENABLED,
|
||||
) &&
|
||||
isDefined(selectedRecord) &&
|
||||
!selectedRecord?.isRemote &&
|
||||
!isDefined(selectedRecord?.deletedAt) &&
|
||||
objectPermissions.canUpdateObjectRecords &&
|
||||
objectMetadataItem?.nameSingular !== CoreObjectNameSingular.Dashboard,
|
||||
availableOn: [CommandMenuItemViewType.SHOW_PAGE],
|
||||
component: <EditRecordPageLayoutSingleRecordCommand />,
|
||||
},
|
||||
[RecordPageLayoutSingleRecordCommandKeys.SAVE_RECORD_PAGE_LAYOUT]: {
|
||||
key: RecordPageLayoutSingleRecordCommandKeys.SAVE_RECORD_PAGE_LAYOUT,
|
||||
label: msg`Save Page Layout`,
|
||||
shortLabel: msg`Save`,
|
||||
isPinned: true,
|
||||
isPrimaryCTA: true,
|
||||
position: 31,
|
||||
Icon: IconDeviceFloppy,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
requiredPermissionFlag: PermissionFlagType.LAYOUTS,
|
||||
shouldBeRegistered: ({
|
||||
selectedRecord,
|
||||
objectPermissions,
|
||||
objectMetadataItem,
|
||||
isFeatureFlagEnabled,
|
||||
}) =>
|
||||
isFeatureFlagEnabled(
|
||||
FeatureFlagKey.IS_RECORD_PAGE_LAYOUT_EDITING_ENABLED,
|
||||
) &&
|
||||
isDefined(selectedRecord) &&
|
||||
!selectedRecord?.isRemote &&
|
||||
!isDefined(selectedRecord?.deletedAt) &&
|
||||
objectPermissions.canUpdateObjectRecords &&
|
||||
objectMetadataItem?.nameSingular !== CoreObjectNameSingular.Dashboard,
|
||||
availableOn: [CommandMenuItemViewType.PAGE_EDIT_MODE],
|
||||
component: <SaveRecordPageLayoutSingleRecordCommand />,
|
||||
},
|
||||
[RecordPageLayoutSingleRecordCommandKeys.CANCEL_RECORD_PAGE_LAYOUT_EDITION]: {
|
||||
key: RecordPageLayoutSingleRecordCommandKeys.CANCEL_RECORD_PAGE_LAYOUT_EDITION,
|
||||
label: msg`Cancel Edition`,
|
||||
shortLabel: msg`Cancel`,
|
||||
isPinned: true,
|
||||
position: 32,
|
||||
Icon: IconCancel,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
requiredPermissionFlag: PermissionFlagType.LAYOUTS,
|
||||
shouldBeRegistered: ({
|
||||
selectedRecord,
|
||||
objectPermissions,
|
||||
objectMetadataItem,
|
||||
isFeatureFlagEnabled,
|
||||
}) =>
|
||||
isFeatureFlagEnabled(
|
||||
FeatureFlagKey.IS_RECORD_PAGE_LAYOUT_EDITING_ENABLED,
|
||||
) &&
|
||||
isDefined(selectedRecord) &&
|
||||
!selectedRecord?.isRemote &&
|
||||
!isDefined(selectedRecord?.deletedAt) &&
|
||||
objectPermissions.canUpdateObjectRecords &&
|
||||
objectMetadataItem?.nameSingular !== CoreObjectNameSingular.Dashboard,
|
||||
availableOn: [CommandMenuItemViewType.PAGE_EDIT_MODE],
|
||||
component: <CancelRecordPageLayoutSingleRecordCommand />,
|
||||
},
|
||||
};
|
||||
+390
@@ -0,0 +1,390 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { MultipleRecordsCommandKeys } from '@/command-menu-item/record/multiple-records/types/MultipleRecordsCommandKeys';
|
||||
import { NoSelectionRecordCommandKeys } from '@/command-menu-item/record/no-selection/types/NoSelectionRecordCommandKeys';
|
||||
import { NoSelectionWorkflowRecordCommandKeys } from '@/command-menu-item/record/no-selection/workflow/types/NoSelectionWorkflowRecordCommandKeys';
|
||||
import { SingleRecordCommandKeys } from '@/command-menu-item/record/single-record/types/SingleRecordCommandKeys';
|
||||
import { ActivateWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/ActivateWorkflowSingleRecordCommand';
|
||||
import { AddNodeWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/AddNodeWorkflowSingleRecordCommand';
|
||||
import { DeactivateWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/DeactivateWorkflowSingleRecordCommand';
|
||||
import { DiscardDraftWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/DiscardDraftWorkflowSingleRecordCommand';
|
||||
import { DuplicateWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/DuplicateWorkflowSingleRecordCommand';
|
||||
import { SeeActiveVersionWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/SeeActiveVersionWorkflowSingleRecordCommand';
|
||||
import { SeeRunsWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/SeeRunsWorkflowSingleRecordCommand';
|
||||
import { SeeVersionsWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/SeeVersionsWorkflowSingleRecordCommand';
|
||||
import { TestWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/TestWorkflowSingleRecordCommand';
|
||||
import { TidyUpWorkflowSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow/components/TidyUpWorkflowSingleRecordCommand';
|
||||
import { WorkflowSingleRecordCommandKeys } from '@/command-menu-item/record/single-record/workflow/types/WorkflowSingleRecordCommandKeys';
|
||||
import { inheritCommandMenuItemsFromDefaultConfig } from '@/command-menu-item/record/utils/inheritCommandMenuItemsFromDefaultConfig';
|
||||
import { CommandMenuItemScope } from '@/command-menu-item/types/CommandMenuItemScope';
|
||||
import { CommandMenuItemType } from '@/command-menu-item/types/CommandMenuItemType';
|
||||
import { CommandMenuItemViewType, AppPath } from 'twenty-shared/types';
|
||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||
import {
|
||||
type WorkflowStep,
|
||||
type WorkflowTrigger,
|
||||
type WorkflowWithCurrentVersion,
|
||||
} from '@/workflow/types/Workflow';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
IconCopy,
|
||||
IconHistoryToggle,
|
||||
IconNoteOff,
|
||||
IconPlayerPause,
|
||||
IconPlayerPlay,
|
||||
IconPlus,
|
||||
IconPower,
|
||||
IconReorder,
|
||||
IconVersions,
|
||||
} from 'twenty-ui/display';
|
||||
|
||||
const areWorkflowTriggerAndStepsDefined = (
|
||||
workflowWithCurrentVersion: WorkflowWithCurrentVersion | undefined,
|
||||
): workflowWithCurrentVersion is WorkflowWithCurrentVersion & {
|
||||
currentVersion: {
|
||||
trigger: WorkflowTrigger;
|
||||
steps: Array<WorkflowStep>;
|
||||
};
|
||||
} => {
|
||||
return (
|
||||
isDefined(workflowWithCurrentVersion?.currentVersion?.trigger) &&
|
||||
isDefined(workflowWithCurrentVersion.currentVersion?.steps) &&
|
||||
workflowWithCurrentVersion.currentVersion.steps.length > 0
|
||||
);
|
||||
};
|
||||
|
||||
export const WORKFLOW_COMMAND_MENU_ITEMS_CONFIG =
|
||||
inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {
|
||||
[WorkflowSingleRecordCommandKeys.ACTIVATE]: {
|
||||
key: WorkflowSingleRecordCommandKeys.ACTIVATE,
|
||||
label: msg`Activate Workflow`,
|
||||
shortLabel: msg`Activate`,
|
||||
isPinned: true,
|
||||
isPrimaryCTA: true,
|
||||
position: 3,
|
||||
Icon: IconPower,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) &&
|
||||
(workflowWithCurrentVersion.currentVersion.status === 'DRAFT' ||
|
||||
!workflowWithCurrentVersion.versions?.some(
|
||||
(version) => version.status === 'ACTIVE',
|
||||
)) &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <ActivateWorkflowSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowSingleRecordCommandKeys.DEACTIVATE]: {
|
||||
key: WorkflowSingleRecordCommandKeys.DEACTIVATE,
|
||||
label: msg`Deactivate Workflow`,
|
||||
shortLabel: msg`Deactivate`,
|
||||
isPinned: true,
|
||||
position: 4,
|
||||
Icon: IconPlayerPause,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
isDefined(workflowWithCurrentVersion) &&
|
||||
workflowWithCurrentVersion.currentVersion.status === 'ACTIVE' &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <DeactivateWorkflowSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowSingleRecordCommandKeys.DISCARD_DRAFT]: {
|
||||
key: WorkflowSingleRecordCommandKeys.DISCARD_DRAFT,
|
||||
label: msg`Discard Draft`,
|
||||
shortLabel: msg`Discard Draft`,
|
||||
isPinned: true,
|
||||
position: 5,
|
||||
Icon: IconNoteOff,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
isDefined(workflowWithCurrentVersion) &&
|
||||
workflowWithCurrentVersion.versions.length > 1 &&
|
||||
workflowWithCurrentVersion.currentVersion.status === 'DRAFT' &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <DiscardDraftWorkflowSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowSingleRecordCommandKeys.TEST]: {
|
||||
key: WorkflowSingleRecordCommandKeys.TEST,
|
||||
label: msg`Test Workflow`,
|
||||
shortLabel: msg`Test`,
|
||||
isPinned: true,
|
||||
position: 6,
|
||||
Icon: IconPlayerPlay,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) &&
|
||||
((workflowWithCurrentVersion.currentVersion.trigger.type ===
|
||||
'MANUAL' &&
|
||||
!isDefined(
|
||||
workflowWithCurrentVersion.currentVersion.trigger.settings
|
||||
.objectType,
|
||||
)) ||
|
||||
workflowWithCurrentVersion.currentVersion.trigger.type ===
|
||||
'WEBHOOK' ||
|
||||
workflowWithCurrentVersion.currentVersion.trigger.type ===
|
||||
'CRON') &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <TestWorkflowSingleRecordCommand />,
|
||||
},
|
||||
|
||||
[WorkflowSingleRecordCommandKeys.SEE_ACTIVE_VERSION]: {
|
||||
key: WorkflowSingleRecordCommandKeys.SEE_ACTIVE_VERSION,
|
||||
label: msg`See active version`,
|
||||
shortLabel: msg`See active version`,
|
||||
isPinned: false,
|
||||
position: 7,
|
||||
Icon: IconVersions,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ workflowWithCurrentVersion, selectedRecord }) =>
|
||||
(workflowWithCurrentVersion?.statuses?.includes('ACTIVE') || false) &&
|
||||
(workflowWithCurrentVersion?.statuses?.includes('DRAFT') || false) &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <SeeActiveVersionWorkflowSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowSingleRecordCommandKeys.SEE_RUNS]: {
|
||||
key: WorkflowSingleRecordCommandKeys.SEE_RUNS,
|
||||
label: msg`See runs`,
|
||||
shortLabel: msg`See runs`,
|
||||
isPinned: true,
|
||||
position: 8,
|
||||
Icon: IconHistoryToggle,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
isDefined(workflowWithCurrentVersion) &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <SeeRunsWorkflowSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowSingleRecordCommandKeys.SEE_VERSIONS]: {
|
||||
key: WorkflowSingleRecordCommandKeys.SEE_VERSIONS,
|
||||
label: msg`See versions history`,
|
||||
shortLabel: msg`See versions`,
|
||||
isPinned: false,
|
||||
position: 9,
|
||||
Icon: IconVersions,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
isDefined(workflowWithCurrentVersion) &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <SeeVersionsWorkflowSingleRecordCommand />,
|
||||
},
|
||||
|
||||
[WorkflowSingleRecordCommandKeys.ADD_NODE]: {
|
||||
key: WorkflowSingleRecordCommandKeys.ADD_NODE,
|
||||
label: msg`Add a node`,
|
||||
shortLabel: msg`Add a node`,
|
||||
isPinned: true,
|
||||
position: 10,
|
||||
Icon: IconPlus,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [CommandMenuItemViewType.SHOW_PAGE],
|
||||
component: <AddNodeWorkflowSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowSingleRecordCommandKeys.TIDY_UP]: {
|
||||
key: WorkflowSingleRecordCommandKeys.TIDY_UP,
|
||||
label: msg`Tidy up workflow`,
|
||||
shortLabel: msg`Tidy up`,
|
||||
isPinned: false,
|
||||
position: 11,
|
||||
Icon: IconReorder,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [CommandMenuItemViewType.SHOW_PAGE],
|
||||
component: <TidyUpWorkflowSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowSingleRecordCommandKeys.DUPLICATE_WORKFLOW]: {
|
||||
key: WorkflowSingleRecordCommandKeys.DUPLICATE_WORKFLOW,
|
||||
label: msg`Duplicate Workflow`,
|
||||
shortLabel: msg`Duplicate`,
|
||||
isPinned: false,
|
||||
position: 12,
|
||||
Icon: IconCopy,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
isDefined(workflowWithCurrentVersion) &&
|
||||
isDefined(workflowWithCurrentVersion.currentVersion) &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <DuplicateWorkflowSingleRecordCommand />,
|
||||
},
|
||||
[NoSelectionWorkflowRecordCommandKeys.GO_TO_RUNS]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionWorkflowRecordCommandKeys.GO_TO_RUNS,
|
||||
label: msg`Go to runs`,
|
||||
shortLabel: msg`See runs`,
|
||||
position: 22,
|
||||
Icon: IconHistoryToggle,
|
||||
accent: 'default',
|
||||
isPinned: true,
|
||||
shouldBeRegistered: ({ hasAnySoftDeleteFilterOnView }) =>
|
||||
!hasAnySoftDeleteFilterOnView,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION],
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.WorkflowRun }}
|
||||
/>
|
||||
),
|
||||
},
|
||||
},
|
||||
commandKeys: [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD,
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD,
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
SingleRecordCommandKeys.REMOVE_FROM_FAVORITES,
|
||||
SingleRecordCommandKeys.DELETE,
|
||||
SingleRecordCommandKeys.DESTROY,
|
||||
SingleRecordCommandKeys.RESTORE,
|
||||
SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX,
|
||||
SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW,
|
||||
MultipleRecordsCommandKeys.DELETE,
|
||||
MultipleRecordsCommandKeys.DESTROY,
|
||||
MultipleRecordsCommandKeys.RESTORE,
|
||||
MultipleRecordsCommandKeys.EXPORT,
|
||||
NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS,
|
||||
NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_PEOPLE,
|
||||
NoSelectionRecordCommandKeys.GO_TO_COMPANIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_SETTINGS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_TASKS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_NOTES,
|
||||
],
|
||||
propertiesToOverwrite: {
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD]: {
|
||||
position: 0,
|
||||
label: msg`Navigate to next workflow`,
|
||||
},
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD]: {
|
||||
position: 1,
|
||||
label: msg`Navigate to previous workflow`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: {
|
||||
position: 2,
|
||||
label: msg`Create new workflow`,
|
||||
},
|
||||
[SingleRecordCommandKeys.DELETE]: {
|
||||
position: 12,
|
||||
label: msg`Delete workflow`,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.DELETE]: {
|
||||
position: 13,
|
||||
label: msg`Delete workflows`,
|
||||
},
|
||||
[SingleRecordCommandKeys.ADD_TO_FAVORITES]: {
|
||||
position: 14,
|
||||
isPinned: false,
|
||||
},
|
||||
[SingleRecordCommandKeys.REMOVE_FROM_FAVORITES]: {
|
||||
position: 15,
|
||||
isPinned: false,
|
||||
},
|
||||
[SingleRecordCommandKeys.DESTROY]: {
|
||||
position: 16,
|
||||
label: msg`Permanently destroy workflow`,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX]: {
|
||||
position: 17,
|
||||
label: msg`Export workflow`,
|
||||
shouldBeRegistered: ({ selectedRecord }) =>
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW]: {
|
||||
position: 18,
|
||||
label: msg`Export workflow`,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.EXPORT]: {
|
||||
position: 19,
|
||||
label: msg`Export workflows`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.EXPORT_VIEW]: {
|
||||
position: 20,
|
||||
label: msg`Export view`,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.DESTROY]: {
|
||||
position: 21,
|
||||
label: msg`Permanently destroy workflows`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS]: {
|
||||
position: 22,
|
||||
label: msg`See deleted workflows`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS]: {
|
||||
position: 23,
|
||||
label: msg`Hide deleted workflows`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.IMPORT_RECORDS]: {
|
||||
position: 24,
|
||||
label: msg`Import workflows`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_PEOPLE]: {
|
||||
position: 25,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_COMPANIES]: {
|
||||
position: 26,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES]: {
|
||||
position: 27,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS]: {
|
||||
position: 28,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_SETTINGS]: {
|
||||
position: 29,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_TASKS]: {
|
||||
position: 30,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_NOTES]: {
|
||||
position: 31,
|
||||
},
|
||||
},
|
||||
});
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
import { MultipleRecordsCommandKeys } from '@/command-menu-item/record/multiple-records/types/MultipleRecordsCommandKeys';
|
||||
import { NoSelectionRecordCommandKeys } from '@/command-menu-item/record/no-selection/types/NoSelectionRecordCommandKeys';
|
||||
import { SingleRecordCommandKeys } from '@/command-menu-item/record/single-record/types/SingleRecordCommandKeys';
|
||||
import { SeeVersionWorkflowRunSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow-runs/components/SeeVersionWorkflowRunSingleRecordCommand';
|
||||
import { SeeWorkflowWorkflowRunSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow-runs/components/SeeWorkflowWorkflowRunSingleRecordCommand';
|
||||
import { StopWorkflowRunSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow-runs/components/StopWorkflowRunSingleRecordCommand';
|
||||
import { WorkflowRunSingleRecordCommandKeys } from '@/command-menu-item/record/single-record/workflow-runs/types/WorkflowRunSingleRecordCommandKeys';
|
||||
import { inheritCommandMenuItemsFromDefaultConfig } from '@/command-menu-item/record/utils/inheritCommandMenuItemsFromDefaultConfig';
|
||||
import { CommandMenuItemScope } from '@/command-menu-item/types/CommandMenuItemScope';
|
||||
import { CommandMenuItemType } from '@/command-menu-item/types/CommandMenuItemType';
|
||||
import { CommandMenuItemViewType } from 'twenty-shared/types';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import {
|
||||
IconPlayerStop,
|
||||
IconSettingsAutomation,
|
||||
IconVersions,
|
||||
} from 'twenty-ui/display';
|
||||
|
||||
export const WORKFLOW_RUNS_COMMAND_MENU_ITEMS_CONFIG =
|
||||
inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {
|
||||
[WorkflowRunSingleRecordCommandKeys.SEE_VERSION]: {
|
||||
key: WorkflowRunSingleRecordCommandKeys.SEE_VERSION,
|
||||
label: msg`See version`,
|
||||
shortLabel: msg`See version`,
|
||||
position: 0,
|
||||
isPinned: true,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
Icon: IconVersions,
|
||||
shouldBeRegistered: () => true,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <SeeVersionWorkflowRunSingleRecordCommand />,
|
||||
},
|
||||
|
||||
[WorkflowRunSingleRecordCommandKeys.SEE_WORKFLOW]: {
|
||||
key: WorkflowRunSingleRecordCommandKeys.SEE_WORKFLOW,
|
||||
label: msg`See workflow`,
|
||||
shortLabel: msg`See workflow`,
|
||||
position: 1,
|
||||
isPinned: true,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
Icon: IconSettingsAutomation,
|
||||
shouldBeRegistered: () => true,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <SeeWorkflowWorkflowRunSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowRunSingleRecordCommandKeys.STOP]: {
|
||||
key: WorkflowRunSingleRecordCommandKeys.STOP,
|
||||
label: msg`Stop`,
|
||||
shortLabel: msg`Stop`,
|
||||
position: 2,
|
||||
isPinned: true,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
Icon: IconPlayerStop,
|
||||
shouldBeRegistered: ({ selectedRecord, isSelectAll }) => {
|
||||
if (isSelectAll === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const stoppableStatuses = ['NOT_STARTED', 'ENQUEUED', 'RUNNING'];
|
||||
return stoppableStatuses.includes(selectedRecord?.status);
|
||||
},
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
],
|
||||
component: <StopWorkflowRunSingleRecordCommand />,
|
||||
},
|
||||
},
|
||||
commandKeys: [
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
SingleRecordCommandKeys.REMOVE_FROM_FAVORITES,
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD,
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD,
|
||||
SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX,
|
||||
SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW,
|
||||
MultipleRecordsCommandKeys.EXPORT,
|
||||
NoSelectionRecordCommandKeys.EXPORT_VIEW,
|
||||
NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS,
|
||||
NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_PEOPLE,
|
||||
NoSelectionRecordCommandKeys.GO_TO_COMPANIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_SETTINGS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_TASKS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_NOTES,
|
||||
],
|
||||
propertiesToOverwrite: {
|
||||
[SingleRecordCommandKeys.ADD_TO_FAVORITES]: {
|
||||
isPinned: false,
|
||||
position: 3,
|
||||
},
|
||||
[SingleRecordCommandKeys.REMOVE_FROM_FAVORITES]: {
|
||||
isPinned: false,
|
||||
position: 4,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX]: {
|
||||
position: 5,
|
||||
label: msg`Export run`,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW]: {
|
||||
position: 5,
|
||||
label: msg`Export run`,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.EXPORT]: {
|
||||
position: 6,
|
||||
label: msg`Export runs`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.EXPORT_VIEW]: {
|
||||
position: 7,
|
||||
label: msg`Export view`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS]: {
|
||||
position: 8,
|
||||
label: msg`See deleted runs`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS]: {
|
||||
position: 9,
|
||||
label: msg`Hide deleted runs`,
|
||||
},
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD]: {
|
||||
position: 10,
|
||||
},
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD]: {
|
||||
position: 11,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS]: {
|
||||
position: 12,
|
||||
isPinned: true,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_PEOPLE]: {
|
||||
position: 13,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_COMPANIES]: {
|
||||
position: 14,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES]: {
|
||||
position: 15,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS]: {
|
||||
position: 16,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_SETTINGS]: {
|
||||
position: 17,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_TASKS]: {
|
||||
position: 18,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_NOTES]: {
|
||||
position: 19,
|
||||
},
|
||||
},
|
||||
});
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { MultipleRecordsCommandKeys } from '@/command-menu-item/record/multiple-records/types/MultipleRecordsCommandKeys';
|
||||
import { NoSelectionRecordCommandKeys } from '@/command-menu-item/record/no-selection/types/NoSelectionRecordCommandKeys';
|
||||
import { NoSelectionWorkflowRecordCommandKeys } from '@/command-menu-item/record/no-selection/workflow/types/NoSelectionWorkflowRecordCommandKeys';
|
||||
import { SingleRecordCommandKeys } from '@/command-menu-item/record/single-record/types/SingleRecordCommandKeys';
|
||||
import { SeeRunsWorkflowVersionSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow-versions/components/SeeRunsWorkflowVersionSingleRecordCommand';
|
||||
import { SeeVersionsWorkflowVersionSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow-versions/components/SeeVersionsWorkflowVersionSingleRecordCommand';
|
||||
import { SeeWorkflowWorkflowVersionSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow-versions/components/SeeWorkflowWorkflowVersionSingleRecordCommand';
|
||||
import { UseAsDraftWorkflowVersionSingleRecordCommand } from '@/command-menu-item/record/single-record/workflow-versions/components/UseAsDraftWorkflowVersionSingleRecordCommand';
|
||||
import { WorkflowVersionSingleRecordCommandKeys } from '@/command-menu-item/record/single-record/workflow-versions/types/WorkflowVersionSingleRecordCommandKeys';
|
||||
import { inheritCommandMenuItemsFromDefaultConfig } from '@/command-menu-item/record/utils/inheritCommandMenuItemsFromDefaultConfig';
|
||||
import { CommandMenuItemScope } from '@/command-menu-item/types/CommandMenuItemScope';
|
||||
import { CommandMenuItemType } from '@/command-menu-item/types/CommandMenuItemType';
|
||||
import { CommandMenuItemViewType, AppPath } from 'twenty-shared/types';
|
||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
IconHistoryToggle,
|
||||
IconPencil,
|
||||
IconSettingsAutomation,
|
||||
IconVersions,
|
||||
} from 'twenty-ui/display';
|
||||
|
||||
export const WORKFLOW_VERSIONS_COMMAND_MENU_ITEMS_CONFIG =
|
||||
inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {
|
||||
[WorkflowVersionSingleRecordCommandKeys.SEE_RUNS]: {
|
||||
key: WorkflowVersionSingleRecordCommandKeys.SEE_RUNS,
|
||||
label: msg`See runs`,
|
||||
shortLabel: msg`See runs`,
|
||||
position: 1,
|
||||
isPinned: true,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
Icon: IconHistoryToggle,
|
||||
shouldBeRegistered: ({ workflowWithCurrentVersion }) =>
|
||||
isDefined(workflowWithCurrentVersion),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <SeeRunsWorkflowVersionSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowVersionSingleRecordCommandKeys.SEE_WORKFLOW]: {
|
||||
key: WorkflowVersionSingleRecordCommandKeys.SEE_WORKFLOW,
|
||||
label: msg`See workflow`,
|
||||
shortLabel: msg`See workflow`,
|
||||
position: 2,
|
||||
isPinned: true,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
Icon: IconSettingsAutomation,
|
||||
shouldBeRegistered: ({ selectedRecord }) =>
|
||||
isDefined(selectedRecord?.workflow?.id),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <SeeWorkflowWorkflowVersionSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowVersionSingleRecordCommandKeys.USE_AS_DRAFT]: {
|
||||
key: WorkflowVersionSingleRecordCommandKeys.USE_AS_DRAFT,
|
||||
label: msg`Use as draft`,
|
||||
shortLabel: msg`Use as draft`,
|
||||
position: 3,
|
||||
isPinned: true,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
Icon: IconPencil,
|
||||
shouldBeRegistered: ({ selectedRecord }) =>
|
||||
isDefined(selectedRecord) && selectedRecord.status !== 'DRAFT',
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <UseAsDraftWorkflowVersionSingleRecordCommand />,
|
||||
},
|
||||
[WorkflowVersionSingleRecordCommandKeys.SEE_VERSIONS]: {
|
||||
key: WorkflowVersionSingleRecordCommandKeys.SEE_VERSIONS,
|
||||
label: msg`See versions history`,
|
||||
shortLabel: msg`See versions`,
|
||||
position: 4,
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
Icon: IconVersions,
|
||||
shouldBeRegistered: ({ workflowWithCurrentVersion }) =>
|
||||
isDefined(workflowWithCurrentVersion),
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
],
|
||||
component: <SeeVersionsWorkflowVersionSingleRecordCommand />,
|
||||
},
|
||||
[NoSelectionWorkflowRecordCommandKeys.GO_TO_RUNS]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionWorkflowRecordCommandKeys.GO_TO_RUNS,
|
||||
label: msg`Go to runs`,
|
||||
shortLabel: msg`See runs`,
|
||||
position: 14,
|
||||
Icon: IconHistoryToggle,
|
||||
accent: 'default',
|
||||
isPinned: true,
|
||||
shouldBeRegistered: () => true,
|
||||
availableOn: [CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION],
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.WorkflowRun }}
|
||||
/>
|
||||
),
|
||||
},
|
||||
},
|
||||
commandKeys: [
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD,
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD,
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
SingleRecordCommandKeys.REMOVE_FROM_FAVORITES,
|
||||
SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX,
|
||||
SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW,
|
||||
MultipleRecordsCommandKeys.EXPORT,
|
||||
NoSelectionRecordCommandKeys.EXPORT_VIEW,
|
||||
NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS,
|
||||
NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_PEOPLE,
|
||||
NoSelectionRecordCommandKeys.GO_TO_COMPANIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_SETTINGS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_TASKS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_NOTES,
|
||||
],
|
||||
propertiesToOverwrite: {
|
||||
[SingleRecordCommandKeys.ADD_TO_FAVORITES]: {
|
||||
position: 5,
|
||||
isPinned: false,
|
||||
},
|
||||
[SingleRecordCommandKeys.REMOVE_FROM_FAVORITES]: {
|
||||
position: 6,
|
||||
isPinned: false,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX]: {
|
||||
position: 7,
|
||||
label: msg`Export version`,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW]: {
|
||||
position: 7,
|
||||
label: msg`Export version`,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.EXPORT]: {
|
||||
position: 8,
|
||||
label: msg`Export versions`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.EXPORT_VIEW]: {
|
||||
position: 9,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS]: {
|
||||
position: 10,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS]: {
|
||||
position: 11,
|
||||
},
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD]: {
|
||||
position: 12,
|
||||
label: msg`Navigate to previous version`,
|
||||
},
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD]: {
|
||||
position: 13,
|
||||
label: msg`Navigate to next version`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS]: {
|
||||
position: 15,
|
||||
isPinned: true,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_PEOPLE]: {
|
||||
position: 16,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_COMPANIES]: {
|
||||
position: 17,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES]: {
|
||||
position: 18,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS]: {
|
||||
position: 19,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_SETTINGS]: {
|
||||
position: 20,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_TASKS]: {
|
||||
position: 21,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_NOTES]: {
|
||||
position: 22,
|
||||
},
|
||||
},
|
||||
});
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { MultipleRecordsCommandKeys } from '@/command-menu-item/record/multiple-records/types/MultipleRecordsCommandKeys';
|
||||
import { NoSelectionRecordCommandKeys } from '@/command-menu-item/record/no-selection/types/NoSelectionRecordCommandKeys';
|
||||
import { SingleRecordCommandKeys } from '@/command-menu-item/record/single-record/types/SingleRecordCommandKeys';
|
||||
import { inheritCommandMenuItemsFromDefaultConfig } from '@/command-menu-item/record/utils/inheritCommandMenuItemsFromDefaultConfig';
|
||||
import { CommandMenuItemScope } from '@/command-menu-item/types/CommandMenuItemScope';
|
||||
import { CommandMenuItemType } from '@/command-menu-item/types/CommandMenuItemType';
|
||||
import {
|
||||
CommandMenuItemViewType,
|
||||
AppPath,
|
||||
SettingsPath,
|
||||
} from 'twenty-shared/types';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { IconSettings } from 'twenty-ui/display';
|
||||
|
||||
export const WORKSPACE_MEMBERS_COMMAND_MENU_ITEMS_CONFIG =
|
||||
inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {
|
||||
[NoSelectionRecordCommandKeys.GO_TO_SETTINGS]: {
|
||||
type: CommandMenuItemType.Navigation,
|
||||
scope: CommandMenuItemScope.Global,
|
||||
key: NoSelectionRecordCommandKeys.GO_TO_SETTINGS,
|
||||
label: msg`Manage members in settings`,
|
||||
shortLabel: msg`Manage in settings`,
|
||||
position: 14,
|
||||
Icon: IconSettings,
|
||||
isPinned: true,
|
||||
availableOn: [
|
||||
CommandMenuItemViewType.INDEX_PAGE_NO_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_SINGLE_RECORD_SELECTION,
|
||||
CommandMenuItemViewType.INDEX_PAGE_BULK_SELECTION,
|
||||
CommandMenuItemViewType.SHOW_PAGE,
|
||||
],
|
||||
shouldBeRegistered: () => true,
|
||||
component: (
|
||||
<CommandLink
|
||||
to={AppPath.SettingsCatchAll}
|
||||
params={{
|
||||
'*': SettingsPath.WorkspaceMembersPage,
|
||||
}}
|
||||
/>
|
||||
),
|
||||
hotKeys: ['G', 'S'],
|
||||
},
|
||||
},
|
||||
commandKeys: [
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
SingleRecordCommandKeys.REMOVE_FROM_FAVORITES,
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD,
|
||||
SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD,
|
||||
SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX,
|
||||
SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW,
|
||||
MultipleRecordsCommandKeys.EXPORT,
|
||||
NoSelectionRecordCommandKeys.EXPORT_VIEW,
|
||||
NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS,
|
||||
NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_PEOPLE,
|
||||
NoSelectionRecordCommandKeys.GO_TO_COMPANIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES,
|
||||
NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_TASKS,
|
||||
NoSelectionRecordCommandKeys.GO_TO_NOTES,
|
||||
],
|
||||
propertiesToOverwrite: {
|
||||
[SingleRecordCommandKeys.ADD_TO_FAVORITES]: {
|
||||
isPinned: false,
|
||||
position: 0,
|
||||
},
|
||||
[SingleRecordCommandKeys.REMOVE_FROM_FAVORITES]: {
|
||||
isPinned: false,
|
||||
position: 1,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_INDEX]: {
|
||||
position: 2,
|
||||
label: msg`Export member`,
|
||||
},
|
||||
[SingleRecordCommandKeys.EXPORT_FROM_RECORD_SHOW]: {
|
||||
position: 2,
|
||||
label: msg`Export member`,
|
||||
},
|
||||
[MultipleRecordsCommandKeys.EXPORT]: {
|
||||
position: 3,
|
||||
label: msg`Export members`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.EXPORT_VIEW]: {
|
||||
position: 4,
|
||||
label: msg`Export view`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.SEE_DELETED_RECORDS]: {
|
||||
position: 5,
|
||||
label: msg`See deleted members`,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.HIDE_DELETED_RECORDS]: {
|
||||
position: 6,
|
||||
label: msg`Hide deleted members`,
|
||||
},
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_PREVIOUS_RECORD]: {
|
||||
position: 7,
|
||||
},
|
||||
[SingleRecordCommandKeys.NAVIGATE_TO_NEXT_RECORD]: {
|
||||
position: 8,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_WORKFLOWS]: {
|
||||
position: 9,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_PEOPLE]: {
|
||||
position: 10,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_COMPANIES]: {
|
||||
position: 11,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_OPPORTUNITIES]: {
|
||||
position: 12,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_DASHBOARDS]: {
|
||||
position: 13,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_TASKS]: {
|
||||
position: 15,
|
||||
},
|
||||
[NoSelectionRecordCommandKeys.GO_TO_NOTES]: {
|
||||
position: 16,
|
||||
},
|
||||
},
|
||||
});
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { CommandConfigContext } from '@/command-menu-item/contexts/CommandConfigContext';
|
||||
import { computeProgressText } from '@/command-menu-item/utils/computeProgressText';
|
||||
import { getCommandMenuItemLabel } from '@/command-menu-item/utils/getCommandMenuItemLabel';
|
||||
import { contextStoreAnyFieldFilterValueComponentState } from '@/context-store/states/contextStoreAnyFieldFilterValueComponentState';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { contextStoreFilterGroupsComponentState } from '@/context-store/states/contextStoreFilterGroupsComponentState';
|
||||
import { contextStoreFiltersComponentState } from '@/context-store/states/contextStoreFiltersComponentState';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { computeContextStoreFilters } from '@/context-store/utils/computeContextStoreFilters';
|
||||
import { DEFAULT_QUERY_PAGE_SIZE } from '@/object-record/constants/DefaultQueryPageSize';
|
||||
import { useIncrementalDeleteManyRecords } from '@/object-record/hooks/useIncrementalDeleteManyRecords';
|
||||
import { useRemoveSelectedRecordsFromRecordBoard } from '@/object-record/record-board/hooks/useRemoveSelectedRecordsFromRecordBoard';
|
||||
import { useFilterValueDependencies } from '@/object-record/record-filter/hooks/useFilterValueDependencies';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
import { useContext } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const DeleteMultipleRecordsCommand = () => {
|
||||
const { recordIndexId, objectMetadataItem } =
|
||||
useRecordIndexIdFromCurrentContextStore();
|
||||
|
||||
const contextStoreCurrentViewId = useAtomComponentStateValue(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
);
|
||||
|
||||
if (!contextStoreCurrentViewId) {
|
||||
throw new Error('Current view ID is not defined');
|
||||
}
|
||||
|
||||
const { resetTableRowSelection } = useResetTableRowSelection(recordIndexId);
|
||||
|
||||
const contextStoreTargetedRecordsRule = useAtomComponentStateValue(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
);
|
||||
|
||||
const contextStoreFilters = useAtomComponentStateValue(
|
||||
contextStoreFiltersComponentState,
|
||||
);
|
||||
|
||||
const contextStoreFilterGroups = useAtomComponentStateValue(
|
||||
contextStoreFilterGroupsComponentState,
|
||||
);
|
||||
|
||||
const contextStoreAnyFieldFilterValue = useAtomComponentStateValue(
|
||||
contextStoreAnyFieldFilterValueComponentState,
|
||||
);
|
||||
|
||||
const { removeSelectedRecordsFromRecordBoard } =
|
||||
useRemoveSelectedRecordsFromRecordBoard(recordIndexId);
|
||||
|
||||
const { filterValueDependencies } = useFilterValueDependencies();
|
||||
|
||||
const graphqlFilter = computeContextStoreFilters({
|
||||
contextStoreTargetedRecordsRule,
|
||||
contextStoreFilters,
|
||||
contextStoreFilterGroups,
|
||||
objectMetadataItem,
|
||||
filterValueDependencies,
|
||||
contextStoreAnyFieldFilterValue,
|
||||
});
|
||||
|
||||
const { incrementalDeleteManyRecords, progress } =
|
||||
useIncrementalDeleteManyRecords({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
filter: graphqlFilter,
|
||||
pageSize: DEFAULT_QUERY_PAGE_SIZE,
|
||||
delayInMsBetweenMutations: 50,
|
||||
});
|
||||
|
||||
const actionConfig = useContext(CommandConfigContext);
|
||||
|
||||
if (!isDefined(actionConfig)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const originalLabel = getCommandMenuItemLabel(actionConfig.label);
|
||||
|
||||
const originalShortLabel = getCommandMenuItemLabel(
|
||||
actionConfig.shortLabel ?? '',
|
||||
);
|
||||
|
||||
const progressText = computeProgressText(progress);
|
||||
|
||||
const actionConfigWithProgress = {
|
||||
...actionConfig,
|
||||
label: `${originalLabel}${progressText}`,
|
||||
shortLabel: `${originalShortLabel}${progressText}`,
|
||||
};
|
||||
|
||||
const handleDeleteClick = async () => {
|
||||
removeSelectedRecordsFromRecordBoard();
|
||||
resetTableRowSelection();
|
||||
await incrementalDeleteManyRecords();
|
||||
};
|
||||
|
||||
return (
|
||||
<CommandConfigContext.Provider value={actionConfigWithProgress}>
|
||||
<Command onClick={handleDeleteClick} />
|
||||
</CommandConfigContext.Provider>
|
||||
);
|
||||
};
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
import { CommandModal } from '@/command-menu-item/display/components/CommandModal';
|
||||
import { CommandConfigContext } from '@/command-menu-item/contexts/CommandConfigContext';
|
||||
import { computeProgressText } from '@/command-menu-item/utils/computeProgressText';
|
||||
import { getCommandMenuItemLabel } from '@/command-menu-item/utils/getCommandMenuItemLabel';
|
||||
import { contextStoreAnyFieldFilterValueComponentState } from '@/context-store/states/contextStoreAnyFieldFilterValueComponentState';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { contextStoreFilterGroupsComponentState } from '@/context-store/states/contextStoreFilterGroupsComponentState';
|
||||
import { contextStoreFiltersComponentState } from '@/context-store/states/contextStoreFiltersComponentState';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { computeContextStoreFilters } from '@/context-store/utils/computeContextStoreFilters';
|
||||
import { DEFAULT_QUERY_PAGE_SIZE } from '@/object-record/constants/DefaultQueryPageSize';
|
||||
import { useIncrementalDestroyManyRecords } from '@/object-record/hooks/useIncrementalDestroyManyRecords';
|
||||
import { useRemoveSelectedRecordsFromRecordBoard } from '@/object-record/record-board/hooks/useRemoveSelectedRecordsFromRecordBoard';
|
||||
import { useFilterValueDependencies } from '@/object-record/record-filter/hooks/useFilterValueDependencies';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { useContext } from 'react';
|
||||
import { type RecordGqlOperationFilter } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const DestroyMultipleRecordsCommand = () => {
|
||||
const { recordIndexId, objectMetadataItem } =
|
||||
useRecordIndexIdFromCurrentContextStore();
|
||||
|
||||
const contextStoreCurrentViewId = useAtomComponentStateValue(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
);
|
||||
|
||||
if (!contextStoreCurrentViewId) {
|
||||
throw new Error('Current view ID is not defined');
|
||||
}
|
||||
|
||||
const { resetTableRowSelection } = useResetTableRowSelection(recordIndexId);
|
||||
const { removeSelectedRecordsFromRecordBoard } =
|
||||
useRemoveSelectedRecordsFromRecordBoard(recordIndexId);
|
||||
|
||||
const contextStoreTargetedRecordsRule = useAtomComponentStateValue(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
);
|
||||
|
||||
const contextStoreFilters = useAtomComponentStateValue(
|
||||
contextStoreFiltersComponentState,
|
||||
);
|
||||
|
||||
const contextStoreFilterGroups = useAtomComponentStateValue(
|
||||
contextStoreFilterGroupsComponentState,
|
||||
);
|
||||
|
||||
const contextStoreAnyFieldFilterValue = useAtomComponentStateValue(
|
||||
contextStoreAnyFieldFilterValueComponentState,
|
||||
);
|
||||
|
||||
const { filterValueDependencies } = useFilterValueDependencies();
|
||||
|
||||
const deletedAtFilter: RecordGqlOperationFilter = {
|
||||
deletedAt: { is: 'NOT_NULL' },
|
||||
};
|
||||
const graphqlFilter = {
|
||||
...computeContextStoreFilters({
|
||||
contextStoreTargetedRecordsRule,
|
||||
contextStoreFilters,
|
||||
contextStoreFilterGroups,
|
||||
objectMetadataItem,
|
||||
filterValueDependencies,
|
||||
contextStoreAnyFieldFilterValue,
|
||||
}),
|
||||
...deletedAtFilter,
|
||||
};
|
||||
|
||||
const { incrementalDestroyManyRecords, progress } =
|
||||
useIncrementalDestroyManyRecords({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
filter: graphqlFilter,
|
||||
pageSize: DEFAULT_QUERY_PAGE_SIZE,
|
||||
delayInMsBetweenMutations: 50,
|
||||
});
|
||||
|
||||
const actionConfig = useContext(CommandConfigContext);
|
||||
|
||||
if (!isDefined(actionConfig)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const originalLabel = getCommandMenuItemLabel(actionConfig.label);
|
||||
|
||||
const originalShortLabel = getCommandMenuItemLabel(
|
||||
actionConfig.shortLabel ?? '',
|
||||
);
|
||||
|
||||
const progressText = computeProgressText(progress);
|
||||
|
||||
const actionConfigWithProgress = {
|
||||
...actionConfig,
|
||||
label: `${originalLabel}${progressText}`,
|
||||
shortLabel: `${originalShortLabel}${progressText}`,
|
||||
};
|
||||
|
||||
const handleDestroyClick = async () => {
|
||||
removeSelectedRecordsFromRecordBoard();
|
||||
resetTableRowSelection();
|
||||
await incrementalDestroyManyRecords();
|
||||
};
|
||||
|
||||
return (
|
||||
<CommandConfigContext.Provider value={actionConfigWithProgress}>
|
||||
<CommandModal
|
||||
title={t`Permanently Destroy Records`}
|
||||
subtitle={t`Are you sure you want to destroy these records? They won't be recoverable anymore.`}
|
||||
onConfirmClick={handleDestroyClick}
|
||||
confirmButtonText={t`Destroy Records`}
|
||||
/>
|
||||
</CommandConfigContext.Provider>
|
||||
);
|
||||
};
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import { CommandMenuItemDisplay } from '@/command-menu-item/display/components/CommandMenuItemDisplay';
|
||||
import { CommandConfigContext } from '@/command-menu-item/contexts/CommandConfigContext';
|
||||
import { useCloseCommandMenu } from '@/command-menu-item/hooks/useCloseCommandMenu';
|
||||
import { computeProgressText } from '@/command-menu-item/utils/computeProgressText';
|
||||
import { getCommandMenuItemLabel } from '@/command-menu-item/utils/getCommandMenuItemLabel';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { useRecordIndexExportRecords } from '@/object-record/record-index/export/hooks/useRecordIndexExportRecords';
|
||||
import { getRecordIndexIdFromObjectNamePluralAndViewId } from '@/object-record/utils/getRecordIndexIdFromObjectNamePluralAndViewId';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
import { useContext } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const ExportMultipleRecordsCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const contextStoreCurrentViewId = useAtomComponentStateValue(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
);
|
||||
|
||||
if (!contextStoreCurrentViewId) {
|
||||
throw new Error('Current view ID is not defined');
|
||||
}
|
||||
|
||||
const { download, progress } = useRecordIndexExportRecords({
|
||||
delayMs: 100,
|
||||
objectMetadataItem,
|
||||
recordIndexId: getRecordIndexIdFromObjectNamePluralAndViewId(
|
||||
objectMetadataItem.namePlural,
|
||||
contextStoreCurrentViewId,
|
||||
),
|
||||
filename: `${objectMetadataItem.nameSingular}.csv`,
|
||||
});
|
||||
|
||||
const { closeCommandMenu } = useCloseCommandMenu({});
|
||||
|
||||
const exportProgress = isDefined(progress)
|
||||
? {
|
||||
processedRecordCount: progress.processedRecordCount,
|
||||
totalRecordCount: progress.totalRecordCount,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const actionConfig = useContext(CommandConfigContext);
|
||||
|
||||
if (!isDefined(actionConfig)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const originalLabel = getCommandMenuItemLabel(actionConfig.label);
|
||||
|
||||
const originalShortLabel = getCommandMenuItemLabel(
|
||||
actionConfig.shortLabel ?? '',
|
||||
);
|
||||
|
||||
const progressText = computeProgressText(exportProgress);
|
||||
|
||||
const actionConfigWithProgress = {
|
||||
...actionConfig,
|
||||
label: `${originalLabel}${progressText}`,
|
||||
shortLabel: `${originalShortLabel}${progressText}`,
|
||||
};
|
||||
|
||||
const handleClick = async () => {
|
||||
try {
|
||||
await download();
|
||||
closeCommandMenu();
|
||||
} catch (error) {
|
||||
closeCommandMenu();
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<CommandConfigContext.Provider value={actionConfigWithProgress}>
|
||||
<CommandMenuItemDisplay onClick={handleClick} />
|
||||
</CommandConfigContext.Provider>
|
||||
);
|
||||
};
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { CommandMenuItemDisplay } from '@/command-menu-item/display/components/CommandMenuItemDisplay';
|
||||
import { useSelectedRecordIds } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIds';
|
||||
import { useOpenMergeRecordsPageInSidePanel } from '@/side-panel/hooks/useOpenMergeRecordsPageInSidePanel';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
|
||||
export const MergeMultipleRecordsCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const contextStoreCurrentViewId = useAtomComponentStateValue(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
);
|
||||
|
||||
if (!contextStoreCurrentViewId) {
|
||||
throw new Error('Current view ID is not defined');
|
||||
}
|
||||
const selectedRecordIds = useSelectedRecordIds();
|
||||
|
||||
const { openMergeRecordsPageInSidePanel } =
|
||||
useOpenMergeRecordsPageInSidePanel({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
objectRecordIds: selectedRecordIds,
|
||||
});
|
||||
|
||||
const handleClick = () => {
|
||||
openMergeRecordsPageInSidePanel();
|
||||
};
|
||||
|
||||
return <CommandMenuItemDisplay onClick={handleClick} />;
|
||||
};
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
import { CommandModal } from '@/command-menu-item/display/components/CommandModal';
|
||||
import { contextStoreAnyFieldFilterValueComponentState } from '@/context-store/states/contextStoreAnyFieldFilterValueComponentState';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { contextStoreFilterGroupsComponentState } from '@/context-store/states/contextStoreFilterGroupsComponentState';
|
||||
import { contextStoreFiltersComponentState } from '@/context-store/states/contextStoreFiltersComponentState';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { computeContextStoreFilters } from '@/context-store/utils/computeContextStoreFilters';
|
||||
import { DEFAULT_QUERY_PAGE_SIZE } from '@/object-record/constants/DefaultQueryPageSize';
|
||||
import { useLazyFetchAllRecords } from '@/object-record/hooks/useLazyFetchAllRecords';
|
||||
import { useRestoreManyRecords } from '@/object-record/hooks/useRestoreManyRecords';
|
||||
import { useRemoveSelectedRecordsFromRecordBoard } from '@/object-record/record-board/hooks/useRemoveSelectedRecordsFromRecordBoard';
|
||||
import { useFilterValueDependencies } from '@/object-record/record-filter/hooks/useFilterValueDependencies';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { type RecordGqlOperationFilter } from 'twenty-shared/types';
|
||||
|
||||
export const RestoreMultipleRecordsCommand = () => {
|
||||
const { recordIndexId, objectMetadataItem } =
|
||||
useRecordIndexIdFromCurrentContextStore();
|
||||
|
||||
const contextStoreCurrentViewId = useAtomComponentStateValue(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
);
|
||||
|
||||
if (!contextStoreCurrentViewId) {
|
||||
throw new Error('Current view ID is not defined');
|
||||
}
|
||||
|
||||
const { resetTableRowSelection } = useResetTableRowSelection(recordIndexId);
|
||||
const { removeSelectedRecordsFromRecordBoard } =
|
||||
useRemoveSelectedRecordsFromRecordBoard(recordIndexId);
|
||||
|
||||
const { restoreManyRecords } = useRestoreManyRecords({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
});
|
||||
|
||||
const contextStoreTargetedRecordsRule = useAtomComponentStateValue(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
);
|
||||
|
||||
const contextStoreFilters = useAtomComponentStateValue(
|
||||
contextStoreFiltersComponentState,
|
||||
);
|
||||
|
||||
const contextStoreFilterGroups = useAtomComponentStateValue(
|
||||
contextStoreFilterGroupsComponentState,
|
||||
);
|
||||
|
||||
const contextStoreAnyFieldFilterValue = useAtomComponentStateValue(
|
||||
contextStoreAnyFieldFilterValueComponentState,
|
||||
);
|
||||
|
||||
const { filterValueDependencies } = useFilterValueDependencies();
|
||||
|
||||
const deletedAtFilter: RecordGqlOperationFilter = {
|
||||
deletedAt: { is: 'NOT_NULL' },
|
||||
};
|
||||
|
||||
const graphqlFilter = {
|
||||
...computeContextStoreFilters({
|
||||
contextStoreTargetedRecordsRule,
|
||||
contextStoreFilters,
|
||||
contextStoreFilterGroups,
|
||||
objectMetadataItem,
|
||||
filterValueDependencies,
|
||||
contextStoreAnyFieldFilterValue,
|
||||
}),
|
||||
...deletedAtFilter,
|
||||
};
|
||||
|
||||
const { fetchAllRecords: fetchAllRecordIds } = useLazyFetchAllRecords({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
filter: graphqlFilter,
|
||||
limit: DEFAULT_QUERY_PAGE_SIZE,
|
||||
recordGqlFields: { id: true },
|
||||
});
|
||||
|
||||
const handleRestoreClick = async () => {
|
||||
removeSelectedRecordsFromRecordBoard();
|
||||
const recordsToRestore = await fetchAllRecordIds();
|
||||
const recordIdsToRestore = recordsToRestore.map((record) => record.id);
|
||||
|
||||
resetTableRowSelection();
|
||||
|
||||
await restoreManyRecords({
|
||||
idsToRestore: recordIdsToRestore,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<CommandModal
|
||||
title={t`Restore Records`}
|
||||
subtitle={t`Are you sure you want to restore these records?`}
|
||||
onConfirmClick={handleRestoreClick}
|
||||
confirmButtonText={t`Restore Records`}
|
||||
confirmButtonAccent="default"
|
||||
/>
|
||||
);
|
||||
};
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { CommandMenuItemDisplay } from '@/command-menu-item/display/components/CommandMenuItemDisplay';
|
||||
import { useOpenUpdateMultipleRecordsPageInSidePanel } from '@/side-panel/hooks/useOpenUpdateMultipleRecordsPageInSidePanel';
|
||||
import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext';
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
|
||||
export const UpdateMultipleRecordsCommand = () => {
|
||||
const contextStoreInstanceId = useAvailableComponentInstanceIdOrThrow(
|
||||
ContextStoreComponentInstanceContext,
|
||||
);
|
||||
|
||||
const { openUpdateMultipleRecordsPageInSidePanel } =
|
||||
useOpenUpdateMultipleRecordsPageInSidePanel({
|
||||
contextStoreInstanceId,
|
||||
});
|
||||
|
||||
const handleClick = () => {
|
||||
openUpdateMultipleRecordsPageInSidePanel();
|
||||
};
|
||||
|
||||
return <CommandMenuItemDisplay onClick={handleClick} />;
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
export enum MultipleRecordsCommandKeys {
|
||||
UPDATE = 'update-multiple-records',
|
||||
DELETE = 'delete-multiple-records',
|
||||
EXPORT = 'export-multiple-records',
|
||||
MERGE = 'merge-multiple-records',
|
||||
DESTROY = 'destroy-multiple-records',
|
||||
RESTORE = 'restore-multiple-records',
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { useCreateNewIndexRecord } from '@/object-record/record-table/hooks/useCreateNewIndexRecord';
|
||||
|
||||
export const CreateNewIndexRecordNoSelectionRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const { createNewIndexRecord } = useCreateNewIndexRecord({
|
||||
objectMetadataItem,
|
||||
});
|
||||
|
||||
return (
|
||||
<Command
|
||||
onClick={() => createNewIndexRecord({ position: 'first' })}
|
||||
closeSidePanelOnCommandMenuListExecution={false}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { getRecordIndexIdFromObjectNamePluralAndViewId } from '@/object-record/utils/getRecordIndexIdFromObjectNamePluralAndViewId';
|
||||
import { useOpenDropdown } from '@/ui/layout/dropdown/hooks/useOpenDropdown';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
|
||||
import { VIEW_PICKER_DROPDOWN_ID } from '@/views/view-picker/constants/ViewPickerDropdownId';
|
||||
import { useViewPickerMode } from '@/views/view-picker/hooks/useViewPickerMode';
|
||||
import { viewPickerReferenceViewIdComponentState } from '@/views/view-picker/states/viewPickerReferenceViewIdComponentState';
|
||||
|
||||
export const CreateNewViewNoSelectionRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
const { openDropdown } = useOpenDropdown();
|
||||
|
||||
const contextStoreCurrentViewId = useAtomComponentStateValue(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
);
|
||||
|
||||
if (!contextStoreCurrentViewId) {
|
||||
throw new Error('Current view ID is not defined');
|
||||
}
|
||||
|
||||
const recordIndexId = getRecordIndexIdFromObjectNamePluralAndViewId(
|
||||
objectMetadataItem.namePlural,
|
||||
contextStoreCurrentViewId,
|
||||
);
|
||||
|
||||
const setViewPickerReferenceViewId = useSetAtomComponentState(
|
||||
viewPickerReferenceViewIdComponentState,
|
||||
recordIndexId,
|
||||
);
|
||||
|
||||
const { setViewPickerMode } = useViewPickerMode(recordIndexId);
|
||||
|
||||
const handleAddViewButtonClick = () => {
|
||||
setViewPickerReferenceViewId(contextStoreCurrentViewId);
|
||||
setViewPickerMode('create-empty');
|
||||
openDropdown({
|
||||
dropdownComponentInstanceIdFromProps: VIEW_PICKER_DROPDOWN_ID,
|
||||
});
|
||||
};
|
||||
|
||||
return <Command onClick={handleAddViewButtonClick} />;
|
||||
};
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { isNavigationMenuInEditModeState } from '@/navigation-menu-item/states/isNavigationMenuInEditModeState';
|
||||
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
|
||||
|
||||
export const EditNavigationSidebarNoSelectionRecordCommand = () => {
|
||||
const setIsNavigationMenuInEditMode = useSetAtomState(
|
||||
isNavigationMenuInEditModeState,
|
||||
);
|
||||
|
||||
return (
|
||||
<Command
|
||||
onClick={() => setIsNavigationMenuInEditMode(true)}
|
||||
closeSidePanelOnCommandMenuListExecution
|
||||
/>
|
||||
);
|
||||
};
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { useCheckIsSoftDeleteFilter } from '@/object-record/record-filter/hooks/useCheckIsSoftDeleteFilter';
|
||||
import { useRemoveRecordFilter } from '@/object-record/record-filter/hooks/useRemoveRecordFilter';
|
||||
import { currentRecordFiltersComponentState } from '@/object-record/record-filter/states/currentRecordFiltersComponentState';
|
||||
import { useHandleToggleTrashColumnFilter } from '@/object-record/record-index/hooks/useHandleToggleTrashColumnFilter';
|
||||
import { getRecordIndexIdFromObjectNamePluralAndViewId } from '@/object-record/utils/getRecordIndexIdFromObjectNamePluralAndViewId';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const HideDeletedRecordsNoSelectionRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const contextStoreCurrentViewId = useAtomComponentStateValue(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
);
|
||||
|
||||
if (!contextStoreCurrentViewId) {
|
||||
throw new Error('Current view ID is not defined');
|
||||
}
|
||||
|
||||
const recordIndexId = getRecordIndexIdFromObjectNamePluralAndViewId(
|
||||
objectMetadataItem.namePlural,
|
||||
contextStoreCurrentViewId,
|
||||
);
|
||||
|
||||
const { toggleSoftDeleteFilterState } = useHandleToggleTrashColumnFilter({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
viewBarId: recordIndexId,
|
||||
});
|
||||
|
||||
const { isRecordFilterAboutSoftDelete } = useCheckIsSoftDeleteFilter();
|
||||
|
||||
const currentRecordFilters = useAtomComponentStateValue(
|
||||
currentRecordFiltersComponentState,
|
||||
recordIndexId,
|
||||
);
|
||||
|
||||
const deletedFilter = currentRecordFilters.find(
|
||||
isRecordFilterAboutSoftDelete,
|
||||
);
|
||||
|
||||
const { removeRecordFilter } = useRemoveRecordFilter();
|
||||
|
||||
const handleClick = () => {
|
||||
if (!isDefined(deletedFilter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
removeRecordFilter({ recordFilterId: deletedFilter.id });
|
||||
toggleSoftDeleteFilterState(false);
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { useOpenObjectRecordsSpreadsheetImportDialog } from '@/object-record/spreadsheet-import/hooks/useOpenObjectRecordsSpreadsheetImportDialog';
|
||||
|
||||
export const ImportRecordsNoSelectionRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const { openObjectRecordsSpreadsheetImportDialog } =
|
||||
useOpenObjectRecordsSpreadsheetImportDialog(
|
||||
objectMetadataItem.nameSingular,
|
||||
);
|
||||
|
||||
return <Command onClick={openObjectRecordsSpreadsheetImportDialog} />;
|
||||
};
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { useHandleToggleTrashColumnFilter } from '@/object-record/record-index/hooks/useHandleToggleTrashColumnFilter';
|
||||
import { getRecordIndexIdFromObjectNamePluralAndViewId } from '@/object-record/utils/getRecordIndexIdFromObjectNamePluralAndViewId';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
|
||||
export const SeeDeletedRecordsNoSelectionRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const contextStoreCurrentViewId = useAtomComponentStateValue(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
);
|
||||
|
||||
if (!contextStoreCurrentViewId) {
|
||||
throw new Error('Current view ID is not defined');
|
||||
}
|
||||
|
||||
const recordIndexId = getRecordIndexIdFromObjectNamePluralAndViewId(
|
||||
objectMetadataItem.namePlural,
|
||||
contextStoreCurrentViewId,
|
||||
);
|
||||
|
||||
const { handleToggleTrashColumnFilter, toggleSoftDeleteFilterState } =
|
||||
useHandleToggleTrashColumnFilter({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
viewBarId: recordIndexId,
|
||||
});
|
||||
|
||||
return (
|
||||
<Command
|
||||
onClick={() => {
|
||||
handleToggleTrashColumnFilter();
|
||||
toggleSoftDeleteFilterState(true);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
export enum NoSelectionRecordCommandKeys {
|
||||
EXPORT_VIEW = 'export-view',
|
||||
CREATE_NEW_RECORD = 'create-new-record',
|
||||
SEE_DELETED_RECORDS = 'see-deleted-records',
|
||||
HIDE_DELETED_RECORDS = 'hide-deleted-records',
|
||||
IMPORT_RECORDS = 'import-records',
|
||||
GO_TO_WORKFLOWS = 'go-to-workflows',
|
||||
GO_TO_PEOPLE = 'go-to-people',
|
||||
GO_TO_COMPANIES = 'go-to-companies',
|
||||
GO_TO_DASHBOARDS = 'go-to-dashboards',
|
||||
GO_TO_OPPORTUNITIES = 'go-to-opportunities',
|
||||
GO_TO_SETTINGS = 'go-to-settings',
|
||||
GO_TO_TASKS = 'go-to-tasks',
|
||||
GO_TO_NOTES = 'go-to-notes',
|
||||
CREATE_NEW_VIEW = 'create-view',
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export enum NoSelectionWorkflowRecordCommandKeys {
|
||||
GO_TO_RUNS = 'go-to-runs',
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { useCreateFavorite } from '@/favorites/hooks/useCreateFavorite';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const AddToFavoritesSingleRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const { createFavorite } = useCreateFavorite();
|
||||
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
const handleClick = () => {
|
||||
if (!isDefined(recordStore)) {
|
||||
return;
|
||||
}
|
||||
|
||||
createFavorite(recordStore, objectMetadataItem.nameSingular);
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useOpenRecordInSidePanel } from '@/side-panel/hooks/useOpenRecordInSidePanel';
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { CoreObjectNameSingular } from 'twenty-shared/types';
|
||||
import { type FieldMetadataItemRelation } from '@/object-metadata/types/FieldMetadataItemRelation';
|
||||
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
||||
import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { getForeignKeyNameFromRelationFieldName } from '@/object-record/utils/getForeignKeyNameFromRelationFieldName';
|
||||
|
||||
interface CreateRelatedRecordCommandProps {
|
||||
targetFieldMetadataItemRelation: FieldMetadataItemRelation;
|
||||
}
|
||||
|
||||
export const CreateRelatedRecordCommand = ({
|
||||
targetFieldMetadataItemRelation,
|
||||
}: CreateRelatedRecordCommandProps) => {
|
||||
const sourceRecordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const { objectMetadataItem: targetObjectMetadataItem } =
|
||||
useObjectMetadataItem({
|
||||
objectNameSingular:
|
||||
targetFieldMetadataItemRelation.targetObjectMetadata.nameSingular,
|
||||
});
|
||||
|
||||
const { objectMetadataItem: taskObjectMetadataItem } = useObjectMetadataItem({
|
||||
objectNameSingular: CoreObjectNameSingular.Task,
|
||||
});
|
||||
|
||||
const { objectMetadataItem: noteObjectMetadataItem } = useObjectMetadataItem({
|
||||
objectNameSingular: CoreObjectNameSingular.Note,
|
||||
});
|
||||
|
||||
const { openRecordInSidePanel } = useOpenRecordInSidePanel();
|
||||
|
||||
const { createOneRecord: createOneTaskTarget } = useCreateOneRecord({
|
||||
objectNameSingular: CoreObjectNameSingular.TaskTarget,
|
||||
});
|
||||
|
||||
const { createOneRecord: createOneNoteTarget } = useCreateOneRecord({
|
||||
objectNameSingular: CoreObjectNameSingular.NoteTarget,
|
||||
});
|
||||
|
||||
const targetObject =
|
||||
targetObjectMetadataItem.nameSingular === CoreObjectNameSingular.TaskTarget
|
||||
? taskObjectMetadataItem
|
||||
: targetObjectMetadataItem.nameSingular ===
|
||||
CoreObjectNameSingular.NoteTarget
|
||||
? noteObjectMetadataItem
|
||||
: targetObjectMetadataItem;
|
||||
|
||||
const { createOneRecord } = useCreateOneRecord({
|
||||
objectNameSingular: targetObject.nameSingular,
|
||||
});
|
||||
|
||||
const handleCreateRelatedRecord = async () => {
|
||||
const foreignKeyFieldName =
|
||||
targetFieldMetadataItemRelation.targetFieldMetadata.name;
|
||||
const foreignKeyIdFieldName =
|
||||
getForeignKeyNameFromRelationFieldName(foreignKeyFieldName);
|
||||
|
||||
let createdRecord: ObjectRecord;
|
||||
|
||||
switch (targetObjectMetadataItem.nameSingular) {
|
||||
case CoreObjectNameSingular.TaskTarget: {
|
||||
createdRecord = await createOneRecord({});
|
||||
|
||||
await createOneTaskTarget({
|
||||
taskId: createdRecord.id,
|
||||
[foreignKeyIdFieldName]: sourceRecordId,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case CoreObjectNameSingular.NoteTarget: {
|
||||
createdRecord = await createOneRecord({});
|
||||
|
||||
await createOneNoteTarget({
|
||||
noteId: createdRecord.id,
|
||||
[foreignKeyIdFieldName]: sourceRecordId,
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
createdRecord = await createOneRecord({
|
||||
[foreignKeyIdFieldName]: sourceRecordId,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
openRecordInSidePanel({
|
||||
recordId: createdRecord.id,
|
||||
objectNameSingular: targetObject.nameSingular,
|
||||
isNewRecord: true,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Command
|
||||
onClick={handleCreateRelatedRecord}
|
||||
closeSidePanelOnCommandMenuListExecution={false}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useDeleteFavorite } from '@/favorites/hooks/useDeleteFavorite';
|
||||
import { useFavorites } from '@/favorites/hooks/useFavorites';
|
||||
import { usePrefetchedNavigationMenuItemsData } from '@/navigation-menu-item/hooks/usePrefetchedNavigationMenuItemsData';
|
||||
import { useRemoveNavigationMenuItemByTargetRecordId } from '@/navigation-menu-item/hooks/useRemoveNavigationMenuItemByTargetRecordId';
|
||||
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
|
||||
import { useRemoveSelectedRecordsFromRecordBoard } from '@/object-record/record-board/hooks/useRemoveSelectedRecordsFromRecordBoard';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const DeleteSingleRecordCommand = () => {
|
||||
const { recordIndexId, objectMetadataItem } =
|
||||
useRecordIndexIdFromCurrentContextStore();
|
||||
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const { resetTableRowSelection } = useResetTableRowSelection(recordIndexId);
|
||||
|
||||
const { removeSelectedRecordsFromRecordBoard } =
|
||||
useRemoveSelectedRecordsFromRecordBoard(recordIndexId);
|
||||
|
||||
const { deleteOneRecord } = useDeleteOneRecord({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
});
|
||||
|
||||
const { sortedFavorites: favorites } = useFavorites();
|
||||
const { deleteFavorite } = useDeleteFavorite();
|
||||
|
||||
const { navigationMenuItems, workspaceNavigationMenuItems } =
|
||||
usePrefetchedNavigationMenuItemsData();
|
||||
const { removeNavigationMenuItemsByTargetRecordIds } =
|
||||
useRemoveNavigationMenuItemByTargetRecordId();
|
||||
|
||||
const handleDeleteClick = async () => {
|
||||
removeSelectedRecordsFromRecordBoard();
|
||||
|
||||
resetTableRowSelection();
|
||||
|
||||
const foundFavorite = favorites?.find(
|
||||
(favorite) => favorite.recordId === recordId,
|
||||
);
|
||||
|
||||
if (isDefined(foundFavorite)) {
|
||||
deleteFavorite(foundFavorite.id);
|
||||
}
|
||||
|
||||
const foundNavigationMenuItem = [
|
||||
...navigationMenuItems,
|
||||
...workspaceNavigationMenuItems,
|
||||
].find((item) => item.targetRecordId === recordId);
|
||||
|
||||
if (isDefined(foundNavigationMenuItem)) {
|
||||
removeNavigationMenuItemsByTargetRecordIds([recordId]);
|
||||
}
|
||||
|
||||
await deleteOneRecord(recordId);
|
||||
};
|
||||
|
||||
return <Command onClick={handleDeleteClick} />;
|
||||
};
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
import { CommandModal } from '@/command-menu-item/display/components/CommandModal';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useDestroyOneRecord } from '@/object-record/hooks/useDestroyOneRecord';
|
||||
import { useRemoveSelectedRecordsFromRecordBoard } from '@/object-record/record-board/hooks/useRemoveSelectedRecordsFromRecordBoard';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { AppPath } from 'twenty-shared/types';
|
||||
import { useNavigateApp } from '~/hooks/useNavigateApp';
|
||||
|
||||
export const DestroySingleRecordCommand = () => {
|
||||
const { recordIndexId, objectMetadataItem } =
|
||||
useRecordIndexIdFromCurrentContextStore();
|
||||
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const navigateApp = useNavigateApp();
|
||||
|
||||
const { resetTableRowSelection } = useResetTableRowSelection(recordIndexId);
|
||||
|
||||
const { removeSelectedRecordsFromRecordBoard } =
|
||||
useRemoveSelectedRecordsFromRecordBoard(recordIndexId);
|
||||
|
||||
const { destroyOneRecord } = useDestroyOneRecord({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
});
|
||||
|
||||
const handleDeleteClick = async () => {
|
||||
removeSelectedRecordsFromRecordBoard();
|
||||
resetTableRowSelection();
|
||||
|
||||
await destroyOneRecord(recordId);
|
||||
navigateApp(AppPath.RecordIndexPage, {
|
||||
objectNamePlural: objectMetadataItem.namePlural,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<CommandModal
|
||||
title={t`Permanently Destroy Record`}
|
||||
subtitle={t`Are you sure you want to destroy this record? It cannot be recovered anymore.`}
|
||||
onConfirmClick={handleDeleteClick}
|
||||
confirmButtonText={t`Permanently Destroy Record`}
|
||||
closeSidePanelOnShowPageOptionsExecution={true}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const ExportNoteSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
const filename = `${(recordStore?.title || 'Untitled Note').replace(/[<>:"/\\|?*]/g, '-')}`;
|
||||
|
||||
const handleClick = async () => {
|
||||
if (!isDefined(recordStore)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const initialBody = recordStore.bodyV2?.blocknote;
|
||||
|
||||
let parsedBody = [];
|
||||
|
||||
// TODO: Remove this once we have removed the old rich text
|
||||
try {
|
||||
parsedBody = JSON.parse(initialBody);
|
||||
} catch {
|
||||
// oxlint-disable-next-line no-console
|
||||
console.warn(
|
||||
`Failed to parse body for record ${recordId}, for rich text version 'v2'`,
|
||||
);
|
||||
// oxlint-disable-next-line no-console
|
||||
console.warn(initialBody);
|
||||
}
|
||||
|
||||
const { exportBlockNoteEditorToPdf } = await import(
|
||||
'@/command-menu-item/record/single-record/utils/exportBlockNoteEditorToPdf'
|
||||
);
|
||||
|
||||
await exportBlockNoteEditorToPdf(parsedBody, filename);
|
||||
|
||||
// TODO later: implement DOCX export
|
||||
// const { exportBlockNoteEditorToDocx } = await import(
|
||||
// '@/command-menu-item/record/single-record/utils/exportBlockNoteEditorToDocx'
|
||||
// );
|
||||
// await exportBlockNoteEditorToDocx(editor, filename);
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
||||
import { useExportSingleRecord } from '@/object-record/record-show/hooks/useExportSingleRecord';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
|
||||
export const ExportSingleRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const contextStoreCurrentViewId = useAtomComponentStateValue(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
);
|
||||
|
||||
if (!contextStoreCurrentViewId) {
|
||||
throw new Error('Current view ID is not defined');
|
||||
}
|
||||
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const filename = `${objectMetadataItem.nameSingular}.csv`;
|
||||
const { download } = useExportSingleRecord({
|
||||
filename,
|
||||
objectMetadataItem,
|
||||
recordId,
|
||||
});
|
||||
|
||||
return <Command onClick={download} />;
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { useRecordShowPagePagination } from '@/object-record/record-show/hooks/useRecordShowPagePagination';
|
||||
|
||||
export const NavigateToNextRecordSingleRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const { navigateToNextRecord } = useRecordShowPagePagination(
|
||||
objectMetadataItem.nameSingular,
|
||||
recordId,
|
||||
);
|
||||
|
||||
return <Command onClick={navigateToNextRecord} />;
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { useRecordShowPagePagination } from '@/object-record/record-show/hooks/useRecordShowPagePagination';
|
||||
|
||||
export const NavigateToPreviousRecordSingleRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const { navigateToPreviousRecord } = useRecordShowPagePagination(
|
||||
objectMetadataItem.nameSingular,
|
||||
recordId,
|
||||
);
|
||||
|
||||
return <Command onClick={navigateToPreviousRecord} />;
|
||||
};
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { useDeleteFavorite } from '@/favorites/hooks/useDeleteFavorite';
|
||||
import { useFavorites } from '@/favorites/hooks/useFavorites';
|
||||
import { useDeleteNavigationMenuItem } from '@/navigation-menu-item/hooks/useDeleteNavigationMenuItem';
|
||||
import { usePrefetchedNavigationMenuItemsData } from '@/navigation-menu-item/hooks/usePrefetchedNavigationMenuItemsData';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const RemoveFromFavoritesSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const { sortedFavorites: favorites } = useFavorites();
|
||||
const { navigationMenuItems, workspaceNavigationMenuItems } =
|
||||
usePrefetchedNavigationMenuItemsData();
|
||||
|
||||
const { deleteFavorite } = useDeleteFavorite();
|
||||
const { deleteNavigationMenuItem } = useDeleteNavigationMenuItem();
|
||||
|
||||
const foundFavorite = favorites?.find(
|
||||
(favorite) => favorite.recordId === recordId,
|
||||
);
|
||||
|
||||
const foundNavigationMenuItem = [
|
||||
...navigationMenuItems,
|
||||
...workspaceNavigationMenuItems,
|
||||
].find(
|
||||
(item) =>
|
||||
item.targetRecordId === recordId &&
|
||||
item.targetObjectMetadataId === objectMetadataItem.id,
|
||||
);
|
||||
|
||||
const handleClick = () => {
|
||||
if (!isDefined(foundNavigationMenuItem) || !isDefined(foundFavorite)) {
|
||||
return;
|
||||
}
|
||||
|
||||
deleteNavigationMenuItem(foundNavigationMenuItem.id);
|
||||
deleteFavorite(foundFavorite.id);
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import { CommandModal } from '@/command-menu-item/display/components/CommandModal';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useRestoreManyRecords } from '@/object-record/hooks/useRestoreManyRecords';
|
||||
import { useRemoveSelectedRecordsFromRecordBoard } from '@/object-record/record-board/hooks/useRemoveSelectedRecordsFromRecordBoard';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection';
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
export const RestoreSingleRecordCommand = () => {
|
||||
const { recordIndexId, objectMetadataItem } =
|
||||
useRecordIndexIdFromCurrentContextStore();
|
||||
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const { resetTableRowSelection } = useResetTableRowSelection(recordIndexId);
|
||||
const { removeSelectedRecordsFromRecordBoard } =
|
||||
useRemoveSelectedRecordsFromRecordBoard(recordIndexId);
|
||||
|
||||
const { restoreManyRecords } = useRestoreManyRecords({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
});
|
||||
|
||||
const handleRestoreClick = async () => {
|
||||
removeSelectedRecordsFromRecordBoard();
|
||||
resetTableRowSelection();
|
||||
|
||||
await restoreManyRecords({
|
||||
idsToRestore: [recordId],
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<CommandModal
|
||||
title={t`Restore Record`}
|
||||
subtitle={t`Are you sure you want to restore this record?`}
|
||||
onConfirmClick={handleRestoreClick}
|
||||
confirmButtonText={t`Restore Record`}
|
||||
confirmButtonAccent="default"
|
||||
/>
|
||||
);
|
||||
};
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useResetDraftPageLayoutToPersistedPageLayout } from '@/page-layout/hooks/useResetDraftPageLayoutToPersistedPageLayout';
|
||||
import { useSetIsPageLayoutInEditMode } from '@/page-layout/hooks/useSetIsPageLayoutInEditMode';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
|
||||
export const CancelDashboardSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
const pageLayoutId = recordStore?.pageLayoutId;
|
||||
|
||||
const { closeSidePanelMenu } = useSidePanelMenu();
|
||||
|
||||
const { setIsPageLayoutInEditMode } =
|
||||
useSetIsPageLayoutInEditMode(pageLayoutId);
|
||||
|
||||
const { resetDraftPageLayoutToPersistedPageLayout } =
|
||||
useResetDraftPageLayoutToPersistedPageLayout(pageLayoutId);
|
||||
|
||||
const handleClick = () => {
|
||||
closeSidePanelMenu();
|
||||
|
||||
resetDraftPageLayoutToPersistedPageLayout();
|
||||
setIsPageLayoutInEditMode(false);
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useDuplicateDashboard } from '@/dashboards/hooks/useDuplicateDashboard';
|
||||
import { CoreObjectNameSingular, AppPath } from 'twenty-shared/types';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { useNavigateApp } from '~/hooks/useNavigateApp';
|
||||
|
||||
export const DuplicateDashboardSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const { duplicateDashboard } = useDuplicateDashboard();
|
||||
const navigate = useNavigateApp();
|
||||
const { enqueueSuccessSnackBar, enqueueErrorSnackBar } = useSnackBar();
|
||||
const { t } = useLingui();
|
||||
|
||||
const handleClick = async () => {
|
||||
const result = await duplicateDashboard(recordId);
|
||||
|
||||
if (isDefined(result) && isNonEmptyString(result.id)) {
|
||||
enqueueSuccessSnackBar({
|
||||
message: t`Dashboard duplicated successfully`,
|
||||
});
|
||||
navigate(AppPath.RecordShowPage, {
|
||||
objectNameSingular: CoreObjectNameSingular.Dashboard,
|
||||
objectRecordId: result.id,
|
||||
});
|
||||
} else {
|
||||
enqueueErrorSnackBar({
|
||||
message: t`Failed to duplicate dashboard`,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useSetIsPageLayoutInEditMode } from '@/page-layout/hooks/useSetIsPageLayoutInEditMode';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
import { useResetLocationHash } from 'twenty-ui/utilities';
|
||||
|
||||
export const EditDashboardSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
const pageLayoutId = recordStore?.pageLayoutId;
|
||||
|
||||
const { setIsPageLayoutInEditMode } =
|
||||
useSetIsPageLayoutInEditMode(pageLayoutId);
|
||||
|
||||
const { resetLocationHash } = useResetLocationHash();
|
||||
|
||||
const handleClick = () => {
|
||||
setIsPageLayoutInEditMode(true);
|
||||
resetLocationHash();
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useSavePageLayout } from '@/page-layout/hooks/useSavePageLayout';
|
||||
import { useSetIsPageLayoutInEditMode } from '@/page-layout/hooks/useSetIsPageLayoutInEditMode';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
|
||||
export const SaveDashboardSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
const pageLayoutId = recordStore?.pageLayoutId;
|
||||
|
||||
const { savePageLayout } = useSavePageLayout(pageLayoutId);
|
||||
|
||||
const { setIsPageLayoutInEditMode } =
|
||||
useSetIsPageLayoutInEditMode(pageLayoutId);
|
||||
|
||||
const { closeSidePanelMenu } = useSidePanelMenu();
|
||||
|
||||
const handleClick = async () => {
|
||||
const result = await savePageLayout();
|
||||
|
||||
if (result.status === 'successful') {
|
||||
closeSidePanelMenu();
|
||||
setIsPageLayoutInEditMode(false);
|
||||
}
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export enum DashboardSingleRecordCommandKeys {
|
||||
DUPLICATE_DASHBOARD = 'duplicate-dashboard-single-record',
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
|
||||
export const useSelectedRecordIdOrThrow = () => {
|
||||
const contextStoreTargetedRecordsRule = useAtomComponentStateValue(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
);
|
||||
|
||||
if (
|
||||
contextStoreTargetedRecordsRule.mode === 'exclusion' ||
|
||||
(contextStoreTargetedRecordsRule.mode === 'selection' &&
|
||||
contextStoreTargetedRecordsRule.selectedRecordIds.length === 0)
|
||||
) {
|
||||
throw new Error('Selected record ID is required');
|
||||
}
|
||||
|
||||
return contextStoreTargetedRecordsRule.selectedRecordIds[0];
|
||||
};
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
|
||||
export const useSelectedRecordIds = () => {
|
||||
const contextStoreTargetedRecordsRule = useAtomComponentStateValue(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
);
|
||||
|
||||
if (
|
||||
contextStoreTargetedRecordsRule.mode === 'exclusion' ||
|
||||
(contextStoreTargetedRecordsRule.mode === 'selection' &&
|
||||
contextStoreTargetedRecordsRule.selectedRecordIds.length === 0)
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return contextStoreTargetedRecordsRule.selectedRecordIds;
|
||||
};
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { useRecordPageLayoutIdFromRecordStoreOrThrow } from '@/page-layout/hooks/useRecordPageLayoutIdFromRecordStoreOrThrow';
|
||||
import { useResetDraftPageLayoutToPersistedPageLayout } from '@/page-layout/hooks/useResetDraftPageLayoutToPersistedPageLayout';
|
||||
import { useSetIsPageLayoutInEditMode } from '@/page-layout/hooks/useSetIsPageLayoutInEditMode';
|
||||
|
||||
export const CancelRecordPageLayoutSingleRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const { pageLayoutId } = useRecordPageLayoutIdFromRecordStoreOrThrow({
|
||||
targetObjectNameSingular: objectMetadataItem.nameSingular,
|
||||
});
|
||||
|
||||
const { closeSidePanelMenu } = useSidePanelMenu();
|
||||
|
||||
const { setIsPageLayoutInEditMode } =
|
||||
useSetIsPageLayoutInEditMode(pageLayoutId);
|
||||
|
||||
const { resetDraftPageLayoutToPersistedPageLayout } =
|
||||
useResetDraftPageLayoutToPersistedPageLayout(pageLayoutId);
|
||||
|
||||
const handleClick = () => {
|
||||
closeSidePanelMenu();
|
||||
|
||||
resetDraftPageLayoutToPersistedPageLayout();
|
||||
setIsPageLayoutInEditMode(false);
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { useRecordPageLayoutIdFromRecordStoreOrThrow } from '@/page-layout/hooks/useRecordPageLayoutIdFromRecordStoreOrThrow';
|
||||
import { useSetIsPageLayoutInEditMode } from '@/page-layout/hooks/useSetIsPageLayoutInEditMode';
|
||||
import { useResetLocationHash } from 'twenty-ui/utilities';
|
||||
|
||||
export const EditRecordPageLayoutSingleRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const { pageLayoutId } = useRecordPageLayoutIdFromRecordStoreOrThrow({
|
||||
targetObjectNameSingular: objectMetadataItem.nameSingular,
|
||||
});
|
||||
|
||||
const { setIsPageLayoutInEditMode } =
|
||||
useSetIsPageLayoutInEditMode(pageLayoutId);
|
||||
|
||||
const { resetLocationHash } = useResetLocationHash();
|
||||
|
||||
const handleClick = () => {
|
||||
setIsPageLayoutInEditMode(true);
|
||||
resetLocationHash();
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
|
||||
import { useContextStoreObjectMetadataItemOrThrow } from '@/context-store/hooks/useContextStoreObjectMetadataItemOrThrow';
|
||||
import { useRecordPageLayoutIdFromRecordStoreOrThrow } from '@/page-layout/hooks/useRecordPageLayoutIdFromRecordStoreOrThrow';
|
||||
import { useSaveFieldsWidgetGroups } from '@/page-layout/hooks/useSaveFieldsWidgetGroups';
|
||||
import { useSavePageLayout } from '@/page-layout/hooks/useSavePageLayout';
|
||||
import { useSetIsPageLayoutInEditMode } from '@/page-layout/hooks/useSetIsPageLayoutInEditMode';
|
||||
|
||||
export const SaveRecordPageLayoutSingleRecordCommand = () => {
|
||||
const { objectMetadataItem } = useContextStoreObjectMetadataItemOrThrow();
|
||||
|
||||
const { pageLayoutId } = useRecordPageLayoutIdFromRecordStoreOrThrow({
|
||||
targetObjectNameSingular: objectMetadataItem.nameSingular,
|
||||
});
|
||||
|
||||
const { savePageLayout } = useSavePageLayout(pageLayoutId);
|
||||
const { saveFieldsWidgetGroups } = useSaveFieldsWidgetGroups({
|
||||
pageLayoutId,
|
||||
});
|
||||
|
||||
const { setIsPageLayoutInEditMode } =
|
||||
useSetIsPageLayoutInEditMode(pageLayoutId);
|
||||
|
||||
const { closeSidePanelMenu } = useSidePanelMenu();
|
||||
|
||||
const handleClick = async () => {
|
||||
const result = await savePageLayout();
|
||||
|
||||
if (result.status === 'successful') {
|
||||
await saveFieldsWidgetGroups();
|
||||
|
||||
closeSidePanelMenu();
|
||||
setIsPageLayoutInEditMode(false);
|
||||
}
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export enum RecordPageLayoutSingleRecordCommandKeys {
|
||||
EDIT_RECORD_PAGE_LAYOUT = 'edit-record-page-layout-single-record',
|
||||
SAVE_RECORD_PAGE_LAYOUT = 'save-record-page-layout-single-record',
|
||||
CANCEL_RECORD_PAGE_LAYOUT_EDITION = 'cancel-record-page-layout-edition-single-record',
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
export enum SingleRecordCommandKeys {
|
||||
DELETE = 'delete-single-record',
|
||||
DESTROY = 'destroy-single-record',
|
||||
ADD_TO_FAVORITES = 'add-to-favorites-single-record',
|
||||
REMOVE_FROM_FAVORITES = 'remove-from-favorites-single-record',
|
||||
NAVIGATE_TO_NEXT_RECORD = 'navigate-to-next-record-single-record',
|
||||
NAVIGATE_TO_PREVIOUS_RECORD = 'navigate-to-previous-record-single-record',
|
||||
EXPORT_NOTE_TO_PDF = 'export-note-to-pdf-single-record',
|
||||
EXPORT_FROM_RECORD_INDEX = 'export-from-record-index-single-record',
|
||||
EXPORT_FROM_RECORD_SHOW = 'export-from-record-show-single-record',
|
||||
RESTORE = 'restore-single-record',
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { type BlockNoteEditor } from '@blocknote/core';
|
||||
import {
|
||||
docxDefaultSchemaMappings,
|
||||
DOCXExporter,
|
||||
} from '@blocknote/xl-docx-exporter';
|
||||
import { saveAs } from 'file-saver';
|
||||
|
||||
export const exportBlockNoteEditorToDocx = async (
|
||||
editor: BlockNoteEditor,
|
||||
filename: string,
|
||||
) => {
|
||||
const exporter = new DOCXExporter(editor.schema, docxDefaultSchemaMappings);
|
||||
|
||||
const blob = await exporter.toBlob(editor.document);
|
||||
saveAs(blob, `${filename}.docx`);
|
||||
};
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
import { BlockNoteEditor, type PartialBlock } from '@blocknote/core';
|
||||
import {
|
||||
PDFExporter,
|
||||
pdfDefaultSchemaMappings,
|
||||
} from '@blocknote/xl-pdf-exporter';
|
||||
import { Font, pdf } from '@react-pdf/renderer';
|
||||
import { saveAs } from 'file-saver';
|
||||
|
||||
const registerInterFonts = (() => {
|
||||
let registrationPromise: Promise<void> | null = null;
|
||||
|
||||
return () => {
|
||||
if (!registrationPromise) {
|
||||
registrationPromise = Promise.resolve().then(() => {
|
||||
Font.register({
|
||||
family: 'Inter',
|
||||
fonts: [
|
||||
{
|
||||
src: 'https://fonts.gstatic.com/s/inter/v19/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfMZg.ttf',
|
||||
fontWeight: 400,
|
||||
},
|
||||
{
|
||||
src: 'https://fonts.gstatic.com/s/inter/v19/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuI6fMZg.ttf',
|
||||
fontWeight: 500,
|
||||
},
|
||||
{
|
||||
src: 'https://fonts.gstatic.com/s/inter/v19/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuGKYMZg.ttf',
|
||||
fontWeight: 600,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
}
|
||||
return registrationPromise;
|
||||
};
|
||||
})();
|
||||
|
||||
export const exportBlockNoteEditorToPdf = async (
|
||||
parsedBody: PartialBlock[],
|
||||
filename: string,
|
||||
) => {
|
||||
await registerInterFonts();
|
||||
|
||||
const editor = BlockNoteEditor.create({
|
||||
initialContent: parsedBody,
|
||||
});
|
||||
|
||||
const exporter = new PDFExporter(editor.schema, pdfDefaultSchemaMappings, {
|
||||
resolveFileUrl: async (url: string) => {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
mode: 'cors',
|
||||
credentials: 'omit',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch asset at ${url}: ${response.status} ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
return await response.blob();
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
error.message.includes('Failed to fetch asset')
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
throw new Error(
|
||||
`Failed to fetch asset at ${url}: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const pdfDocument = await exporter.toReactPDFDocument(editor.document);
|
||||
|
||||
const blob = await pdf(pdfDocument).toBlob();
|
||||
saveAs(blob, `${filename}.pdf`);
|
||||
};
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNameSingular, AppPath } from 'twenty-shared/types';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const SeeVersionWorkflowRunSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
if (!isDefined(recordStore) || !isDefined(recordStore?.workflowVersion?.id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<CommandLink
|
||||
to={AppPath.RecordShowPage}
|
||||
params={{
|
||||
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
|
||||
objectRecordId: recordStore.workflowVersion.id,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNameSingular, AppPath } from 'twenty-shared/types';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const SeeWorkflowWorkflowRunSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
if (!isDefined(recordStore) || !isDefined(recordStore?.workflow?.id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<CommandLink
|
||||
to={AppPath.RecordShowPage}
|
||||
params={{
|
||||
objectNameSingular: CoreObjectNameSingular.Workflow,
|
||||
objectRecordId: recordStore.workflow.id,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { contextStoreAnyFieldFilterValueComponentState } from '@/context-store/states/contextStoreAnyFieldFilterValueComponentState';
|
||||
import { contextStoreFilterGroupsComponentState } from '@/context-store/states/contextStoreFilterGroupsComponentState';
|
||||
import { contextStoreFiltersComponentState } from '@/context-store/states/contextStoreFiltersComponentState';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { computeContextStoreFilters } from '@/context-store/utils/computeContextStoreFilters';
|
||||
import { CoreObjectNameSingular } from 'twenty-shared/types';
|
||||
import { DEFAULT_QUERY_PAGE_SIZE } from '@/object-record/constants/DefaultQueryPageSize';
|
||||
import { useLazyFetchAllRecords } from '@/object-record/hooks/useLazyFetchAllRecords';
|
||||
import { useFilterValueDependencies } from '@/object-record/record-filter/hooks/useFilterValueDependencies';
|
||||
import { useRecordIndexIdFromCurrentContextStore } from '@/object-record/record-index/hooks/useRecordIndexIdFromCurrentContextStore';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
import { useStopWorkflowRun } from '@/workflow/hooks/useStopWorkflowRun';
|
||||
|
||||
export const StopWorkflowRunSingleRecordCommand = () => {
|
||||
const { objectMetadataItem } = useRecordIndexIdFromCurrentContextStore();
|
||||
|
||||
const contextStoreTargetedRecordsRule = useAtomComponentStateValue(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
);
|
||||
|
||||
const contextStoreFilters = useAtomComponentStateValue(
|
||||
contextStoreFiltersComponentState,
|
||||
);
|
||||
|
||||
const contextStoreFilterGroups = useAtomComponentStateValue(
|
||||
contextStoreFilterGroupsComponentState,
|
||||
);
|
||||
|
||||
const contextStoreAnyFieldFilterValue = useAtomComponentStateValue(
|
||||
contextStoreAnyFieldFilterValueComponentState,
|
||||
);
|
||||
|
||||
const { filterValueDependencies } = useFilterValueDependencies();
|
||||
|
||||
const graphqlFilter = computeContextStoreFilters({
|
||||
contextStoreTargetedRecordsRule,
|
||||
contextStoreFilters,
|
||||
contextStoreFilterGroups,
|
||||
objectMetadataItem,
|
||||
filterValueDependencies,
|
||||
contextStoreAnyFieldFilterValue,
|
||||
});
|
||||
|
||||
const { fetchAllRecords: fetchAllRecordIds } = useLazyFetchAllRecords({
|
||||
objectNameSingular: CoreObjectNameSingular.WorkflowRun,
|
||||
filter: graphqlFilter,
|
||||
limit: DEFAULT_QUERY_PAGE_SIZE,
|
||||
recordGqlFields: { id: true },
|
||||
});
|
||||
|
||||
const { stopWorkflowRun } = useStopWorkflowRun();
|
||||
|
||||
const handleClick = async () => {
|
||||
if (contextStoreTargetedRecordsRule.mode === 'selection') {
|
||||
for (const selectedRecordId of contextStoreTargetedRecordsRule.selectedRecordIds) {
|
||||
await stopWorkflowRun(selectedRecordId);
|
||||
}
|
||||
} else {
|
||||
const records = await fetchAllRecordIds();
|
||||
|
||||
for (const record of records) {
|
||||
await stopWorkflowRun(record.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return <Command onClick={handleClick} />;
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export enum WorkflowRunSingleRecordCommandKeys {
|
||||
STOP = 'stop-workflow-run-single-record',
|
||||
SEE_WORKFLOW = 'see-workflow-workflow-run-single-record',
|
||||
SEE_VERSION = 'see-version-workflow-run-single-record',
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { AppPath, ViewFilterOperand } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
const SeeRunsWorkflowVersionSingleRecordCommandContent = ({
|
||||
workflowId,
|
||||
recordId,
|
||||
}: {
|
||||
workflowId: string;
|
||||
recordId: string;
|
||||
}) => {
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(workflowId);
|
||||
|
||||
return (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.WorkflowRun }}
|
||||
queryParams={{
|
||||
filter: {
|
||||
workflow: {
|
||||
[ViewFilterOperand.IS]: {
|
||||
selectedRecordIds: [workflowWithCurrentVersion?.id],
|
||||
},
|
||||
},
|
||||
recordStore: {
|
||||
[ViewFilterOperand.IS]: {
|
||||
selectedRecordIds: [recordId],
|
||||
},
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const SeeRunsWorkflowVersionSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
const workflowId = recordStore?.workflow?.id;
|
||||
|
||||
if (!isDefined(workflowId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<SeeRunsWorkflowVersionSingleRecordCommandContent
|
||||
workflowId={workflowId}
|
||||
recordId={recordId}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
import { AppPath, ViewFilterOperand } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
const SeeVersionsWorkflowVersionSingleRecordCommandContent = ({
|
||||
workflowId,
|
||||
}: {
|
||||
workflowId: string;
|
||||
}) => {
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(workflowId);
|
||||
|
||||
return (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.WorkflowVersion }}
|
||||
queryParams={{
|
||||
filter: {
|
||||
workflow: {
|
||||
[ViewFilterOperand.IS]: {
|
||||
selectedRecordIds: [workflowWithCurrentVersion?.id],
|
||||
},
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const SeeVersionsWorkflowVersionSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
if (!isDefined(recordStore) || !isDefined(recordStore.workflowId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<SeeVersionsWorkflowVersionSingleRecordCommandContent
|
||||
workflowId={recordStore.workflowId}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNameSingular, AppPath } from 'twenty-shared/types';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
||||
|
||||
export const SeeWorkflowWorkflowVersionSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId);
|
||||
|
||||
return (
|
||||
<CommandLink
|
||||
to={AppPath.RecordShowPage}
|
||||
params={{
|
||||
objectNameSingular: CoreObjectNameSingular.Workflow,
|
||||
objectRecordId: recordStore?.workflow?.id,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNameSingular, AppPath } from 'twenty-shared/types';
|
||||
import { useModal } from '@/ui/layout/modal/hooks/useModal';
|
||||
import { OverrideWorkflowDraftConfirmationModal } from '@/workflow/components/OverrideWorkflowDraftConfirmationModal';
|
||||
import { OVERRIDE_WORKFLOW_DRAFT_CONFIRMATION_MODAL_ID } from '@/workflow/constants/OverrideWorkflowDraftConfirmationModalId';
|
||||
import { useCreateDraftFromWorkflowVersion } from '@/workflow/hooks/useCreateDraftFromWorkflowVersion';
|
||||
import { useWorkflowVersion } from '@/workflow/hooks/useWorkflowVersion';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { useState } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { useNavigateApp } from '~/hooks/useNavigateApp';
|
||||
|
||||
const UseAsDraftWorkflowVersionSingleRecordCommandContent = ({
|
||||
workflowId,
|
||||
workflowVersionId,
|
||||
}: {
|
||||
workflowId: string;
|
||||
workflowVersionId: string;
|
||||
}) => {
|
||||
const { openModal } = useModal();
|
||||
const workflow = useWorkflowWithCurrentVersion(workflowId);
|
||||
const { createDraftFromWorkflowVersion } =
|
||||
useCreateDraftFromWorkflowVersion();
|
||||
const navigate = useNavigateApp();
|
||||
const [hasNavigated, setHasNavigated] = useState(false);
|
||||
|
||||
const hasAlreadyDraftVersion =
|
||||
workflow?.versions.some((version) => version.status === 'DRAFT') || false;
|
||||
|
||||
const handleClick = () => {
|
||||
if (!isDefined(workflow) || hasNavigated) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasAlreadyDraftVersion) {
|
||||
openModal(OVERRIDE_WORKFLOW_DRAFT_CONFIRMATION_MODAL_ID);
|
||||
} else {
|
||||
const executeCommandWithoutWaiting = async () => {
|
||||
await createDraftFromWorkflowVersion({
|
||||
workflowId,
|
||||
workflowVersionIdToCopy: workflowVersionId,
|
||||
});
|
||||
|
||||
navigate(AppPath.RecordShowPage, {
|
||||
objectNameSingular: CoreObjectNameSingular.Workflow,
|
||||
objectRecordId: workflowId,
|
||||
});
|
||||
|
||||
setHasNavigated(true);
|
||||
};
|
||||
|
||||
executeCommandWithoutWaiting();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Command onClick={handleClick} />
|
||||
<OverrideWorkflowDraftConfirmationModal
|
||||
workflowId={workflowId}
|
||||
workflowVersionIdToCopy={workflowVersionId}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const UseAsDraftWorkflowVersionSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const workflowVersion = useWorkflowVersion(recordId);
|
||||
|
||||
if (!isDefined(workflowVersion?.workflow?.id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<UseAsDraftWorkflowVersionSingleRecordCommandContent
|
||||
workflowId={workflowVersion.workflow.id}
|
||||
workflowVersionId={workflowVersion.id}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
export enum WorkflowVersionSingleRecordCommandKeys {
|
||||
SEE_RUNS = 'see-runs-workflow-version-single-record',
|
||||
SEE_VERSIONS = 'see-versions-workflow-version-single-record',
|
||||
USE_AS_DRAFT = 'use-as-draft-workflow-version-single-record',
|
||||
SEE_WORKFLOW = 'see-workflow-workflow-version-single-record',
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useActivateWorkflowVersion } from '@/workflow/hooks/useActivateWorkflowVersion';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const ActivateWorkflowSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const { activateWorkflowVersion } = useActivateWorkflowVersion();
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(recordId);
|
||||
|
||||
const onClick = () => {
|
||||
if (!isDefined(workflowWithCurrentVersion)) {
|
||||
return;
|
||||
}
|
||||
|
||||
activateWorkflowVersion({
|
||||
workflowVersionId: workflowWithCurrentVersion.currentVersion.id,
|
||||
workflowId: workflowWithCurrentVersion.id,
|
||||
});
|
||||
};
|
||||
|
||||
return <Command onClick={onClick} />;
|
||||
};
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useSidePanelWorkflowNavigation } from '@/side-panel/pages/workflow/hooks/useSidePanelWorkflowNavigation';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const AddNodeWorkflowSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(recordId);
|
||||
const { openWorkflowCreateStepInSidePanel } =
|
||||
useSidePanelWorkflowNavigation();
|
||||
|
||||
const onClick = () => {
|
||||
if (!isDefined(workflowWithCurrentVersion)) {
|
||||
return;
|
||||
}
|
||||
|
||||
openWorkflowCreateStepInSidePanel(workflowWithCurrentVersion.id);
|
||||
};
|
||||
|
||||
return <Command onClick={onClick} />;
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useDeactivateWorkflowVersion } from '@/workflow/hooks/useDeactivateWorkflowVersion';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const DeactivateWorkflowSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const { deactivateWorkflowVersion } = useDeactivateWorkflowVersion();
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(recordId);
|
||||
|
||||
const onClick = () => {
|
||||
if (!isDefined(workflowWithCurrentVersion)) {
|
||||
return;
|
||||
}
|
||||
|
||||
deactivateWorkflowVersion({
|
||||
workflowVersionId: workflowWithCurrentVersion.currentVersion.id,
|
||||
});
|
||||
};
|
||||
|
||||
return <Command onClick={onClick} />;
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useDeleteOneWorkflowVersion } from '@/workflow/hooks/useDeleteOneWorkflowVersion';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const DiscardDraftWorkflowSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const { deleteOneWorkflowVersion } = useDeleteOneWorkflowVersion();
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(recordId);
|
||||
|
||||
const onClick = () => {
|
||||
if (!isDefined(workflowWithCurrentVersion)) {
|
||||
return;
|
||||
}
|
||||
|
||||
deleteOneWorkflowVersion({
|
||||
workflowVersionId: workflowWithCurrentVersion.currentVersion.id,
|
||||
});
|
||||
};
|
||||
|
||||
return <Command onClick={onClick} />;
|
||||
};
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNameSingular, AppPath } from 'twenty-shared/types';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useDuplicateWorkflow } from '@/workflow/hooks/useDuplicateWorkflow';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { useNavigateApp } from '~/hooks/useNavigateApp';
|
||||
|
||||
export const DuplicateWorkflowSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const workflow = useWorkflowWithCurrentVersion(recordId);
|
||||
const { duplicateWorkflow } = useDuplicateWorkflow();
|
||||
const navigate = useNavigateApp();
|
||||
const { enqueueSuccessSnackBar, enqueueErrorSnackBar } = useSnackBar();
|
||||
const { t } = useLingui();
|
||||
|
||||
const handleClick = async () => {
|
||||
if (!isDefined(workflow) || !isDefined(workflow.currentVersion)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await duplicateWorkflow({
|
||||
workflowIdToDuplicate: workflow.id,
|
||||
workflowVersionIdToCopy: workflow.currentVersion.id,
|
||||
});
|
||||
|
||||
if (isDefined(result) && isNonEmptyString(result.workflowId)) {
|
||||
enqueueSuccessSnackBar({
|
||||
message: t`Workflow duplicated successfully`,
|
||||
});
|
||||
navigate(AppPath.RecordShowPage, {
|
||||
objectNameSingular: CoreObjectNameSingular.Workflow,
|
||||
objectRecordId: result.workflowId,
|
||||
});
|
||||
} else {
|
||||
enqueueErrorSnackBar({
|
||||
message: t`Failed to duplicate workflow`,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return isDefined(workflow) ? <Command onClick={handleClick} /> : null;
|
||||
};
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { CommandMenuItemDisplay } from '@/command-menu-item/display/components/CommandMenuItemDisplay';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNameSingular, AppPath } from 'twenty-shared/types';
|
||||
import { useActiveWorkflowVersion } from '@/workflow/hooks/useActiveWorkflowVersion';
|
||||
|
||||
export const SeeActiveVersionWorkflowSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
|
||||
const { workflowVersion, loading } = useActiveWorkflowVersion({
|
||||
workflowId: recordId,
|
||||
});
|
||||
|
||||
if (loading) {
|
||||
return <CommandMenuItemDisplay />;
|
||||
}
|
||||
|
||||
return (
|
||||
<CommandLink
|
||||
to={AppPath.RecordShowPage}
|
||||
params={{
|
||||
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
|
||||
objectRecordId: workflowVersion.id,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { AppPath, ViewFilterOperand } from 'twenty-shared/types';
|
||||
|
||||
export const SeeRunsWorkflowSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(recordId);
|
||||
|
||||
return (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.WorkflowRun }}
|
||||
queryParams={{
|
||||
filter: {
|
||||
workflow: {
|
||||
[ViewFilterOperand.IS]: {
|
||||
selectedRecordIds: [workflowWithCurrentVersion?.id],
|
||||
},
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import { CommandLink } from '@/command-menu-item/display/components/CommandLink';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { AppPath, ViewFilterOperand } from 'twenty-shared/types';
|
||||
|
||||
export const SeeVersionsWorkflowSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(recordId);
|
||||
|
||||
return (
|
||||
<CommandLink
|
||||
to={AppPath.RecordIndexPage}
|
||||
params={{ objectNamePlural: CoreObjectNamePlural.WorkflowVersion }}
|
||||
queryParams={{
|
||||
filter: {
|
||||
workflow: {
|
||||
[ViewFilterOperand.IS]: {
|
||||
selectedRecordIds: [workflowWithCurrentVersion?.id],
|
||||
},
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useRunWorkflowVersion } from '@/workflow/hooks/useRunWorkflowVersion';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const TestWorkflowSingleRecordCommand = () => {
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const { runWorkflowVersion } = useRunWorkflowVersion();
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(recordId);
|
||||
|
||||
const onClick = () => {
|
||||
if (!isDefined(workflowWithCurrentVersion)) {
|
||||
return;
|
||||
}
|
||||
|
||||
runWorkflowVersion({
|
||||
workflowVersionId: workflowWithCurrentVersion.currentVersion.id,
|
||||
workflowId: workflowWithCurrentVersion.id,
|
||||
});
|
||||
};
|
||||
|
||||
return <Command onClick={onClick} />;
|
||||
};
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { useSelectedRecordIdOrThrow } from '@/command-menu-item/record/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useGetUpdatableWorkflowVersionOrThrow } from '@/workflow/hooks/useGetUpdatableWorkflowVersionOrThrow';
|
||||
import { getWorkflowVisualizerComponentInstanceId } from '@/workflow/utils/getWorkflowVisualizerComponentInstanceId';
|
||||
import { workflowDiagramComponentState } from '@/workflow/workflow-diagram/states/workflowDiagramComponentState';
|
||||
import { useTidyUpWorkflowVersion } from '@/workflow/workflow-version/hooks/useTidyUpWorkflowVersion';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { useStore } from 'jotai';
|
||||
|
||||
export const TidyUpWorkflowSingleRecordCommand = () => {
|
||||
const store = useStore();
|
||||
const recordId = useSelectedRecordIdOrThrow();
|
||||
const { tidyUpWorkflowVersion } = useTidyUpWorkflowVersion();
|
||||
const instanceId = getWorkflowVisualizerComponentInstanceId({
|
||||
recordId,
|
||||
});
|
||||
const { getUpdatableWorkflowVersion } =
|
||||
useGetUpdatableWorkflowVersionOrThrow(instanceId);
|
||||
|
||||
const onClick = async () => {
|
||||
const workflowDiagramAtom = workflowDiagramComponentState.atomFamily({
|
||||
instanceId,
|
||||
});
|
||||
const workflowDiagram = store.get(workflowDiagramAtom);
|
||||
|
||||
if (!isDefined(workflowDiagram)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const workflowVersionId = await getUpdatableWorkflowVersion();
|
||||
|
||||
await tidyUpWorkflowVersion(workflowVersionId, workflowDiagram);
|
||||
};
|
||||
|
||||
return <Command onClick={onClick} />;
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
export enum WorkflowSingleRecordCommandKeys {
|
||||
ACTIVATE = 'activate-workflow-single-record',
|
||||
DEACTIVATE = 'deactivate-workflow-single-record',
|
||||
DISCARD_DRAFT = 'discard-draft-workflow-single-record',
|
||||
DUPLICATE_WORKFLOW = 'duplicate-workflow-single-record',
|
||||
SEE_ACTIVE_VERSION = 'see-active-version-workflow-single-record',
|
||||
SEE_RUNS = 'see-runs-workflow-single-record',
|
||||
SEE_VERSIONS = 'see-versions-workflow-single-record',
|
||||
TEST = 'test-workflow-single-record',
|
||||
ADD_NODE = 'add-node-workflow-single-record',
|
||||
TIDY_UP = 'tidy-up-workflow-single-record',
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { type MultipleRecordsCommandKeys } from '@/command-menu-item/record/multiple-records/types/MultipleRecordsCommandKeys';
|
||||
import { type NoSelectionRecordCommandKeys } from '@/command-menu-item/record/no-selection/types/NoSelectionRecordCommandKeys';
|
||||
import { type SingleRecordCommandKeys } from '@/command-menu-item/record/single-record/types/SingleRecordCommandKeys';
|
||||
|
||||
export type DefaultRecordCommandKeys =
|
||||
| NoSelectionRecordCommandKeys
|
||||
| SingleRecordCommandKeys
|
||||
| MultipleRecordsCommandKeys;
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
import { DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG } from '@/command-menu-item/record/constants/DefaultRecordCommandMenuItemsConfig';
|
||||
import { NoSelectionRecordCommandKeys } from '@/command-menu-item/record/no-selection/types/NoSelectionRecordCommandKeys';
|
||||
import { SingleRecordCommandKeys } from '@/command-menu-item/record/single-record/types/SingleRecordCommandKeys';
|
||||
import { type CommandMenuItemConfig } from '@/command-menu-item/types/CommandMenuItemConfig';
|
||||
import { CommandMenuItemScope } from '@/command-menu-item/types/CommandMenuItemScope';
|
||||
import { CommandMenuItemType } from '@/command-menu-item/types/CommandMenuItemType';
|
||||
import { type DefaultRecordCommandKeys } from '@/command-menu-item/record/types/DefaultRecordCommandKeys';
|
||||
import { IconHeart, IconPlus } from 'twenty-ui/display';
|
||||
import { inheritCommandMenuItemsFromDefaultConfig } from '@/command-menu-item/record/utils/inheritCommandMenuItemsFromDefaultConfig';
|
||||
|
||||
const MockComponent = <div>Mock Component</div>;
|
||||
|
||||
describe('inheritCommandMenuItemsFromDefaultConfig', () => {
|
||||
it('should return empty object when no action keys are provided', () => {
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {},
|
||||
commandKeys: [],
|
||||
propertiesToOverwrite: {},
|
||||
});
|
||||
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it('should return only provided config when no default action keys are specified', () => {
|
||||
const customConfig: Record<string, CommandMenuItemConfig> = {
|
||||
'custom-action': {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: 'custom-action',
|
||||
label: 'Custom Action',
|
||||
position: 100,
|
||||
Icon: IconPlus,
|
||||
shouldBeRegistered: () => true,
|
||||
component: MockComponent,
|
||||
},
|
||||
};
|
||||
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: customConfig,
|
||||
commandKeys: [],
|
||||
propertiesToOverwrite: {},
|
||||
});
|
||||
|
||||
expect(result).toEqual(customConfig);
|
||||
});
|
||||
|
||||
it('should inherit actions from default config', () => {
|
||||
const commandKeys: DefaultRecordCommandKeys[] = [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
];
|
||||
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {},
|
||||
commandKeys,
|
||||
propertiesToOverwrite: {},
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]:
|
||||
DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD
|
||||
],
|
||||
[SingleRecordCommandKeys.ADD_TO_FAVORITES]:
|
||||
DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('should overwrite specific properties of inherited actions', () => {
|
||||
const commandKeys: DefaultRecordCommandKeys[] = [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
];
|
||||
|
||||
const propertiesToOverwrite = {
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: {
|
||||
label: 'Custom Create Label',
|
||||
position: 999,
|
||||
isPinned: false,
|
||||
},
|
||||
};
|
||||
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {},
|
||||
commandKeys,
|
||||
propertiesToOverwrite,
|
||||
});
|
||||
|
||||
const expectedCommandMenuItem = {
|
||||
...DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD
|
||||
],
|
||||
label: 'Custom Create Label',
|
||||
position: 999,
|
||||
isPinned: false,
|
||||
};
|
||||
|
||||
expect(result).toEqual({
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: expectedCommandMenuItem,
|
||||
});
|
||||
});
|
||||
|
||||
it('should overwrite properties for multiple actions', () => {
|
||||
const commandKeys: DefaultRecordCommandKeys[] = [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
];
|
||||
|
||||
const propertiesToOverwrite = {
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: {
|
||||
position: 10,
|
||||
},
|
||||
[SingleRecordCommandKeys.ADD_TO_FAVORITES]: {
|
||||
label: 'Custom Favorite Label',
|
||||
Icon: IconHeart,
|
||||
},
|
||||
};
|
||||
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {},
|
||||
commandKeys,
|
||||
propertiesToOverwrite,
|
||||
});
|
||||
|
||||
expect(result[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]).toEqual({
|
||||
...DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD
|
||||
],
|
||||
position: 10,
|
||||
});
|
||||
|
||||
expect(result[SingleRecordCommandKeys.ADD_TO_FAVORITES]).toEqual({
|
||||
...DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES
|
||||
],
|
||||
label: 'Custom Favorite Label',
|
||||
Icon: IconHeart,
|
||||
});
|
||||
});
|
||||
|
||||
it('should only overwrite properties for specified actions', () => {
|
||||
const commandKeys: DefaultRecordCommandKeys[] = [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
];
|
||||
|
||||
const propertiesToOverwrite = {
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: {
|
||||
position: 10,
|
||||
},
|
||||
};
|
||||
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {},
|
||||
commandKeys,
|
||||
propertiesToOverwrite,
|
||||
});
|
||||
|
||||
expect(result[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]).toEqual({
|
||||
...DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD
|
||||
],
|
||||
position: 10,
|
||||
});
|
||||
|
||||
expect(result[SingleRecordCommandKeys.ADD_TO_FAVORITES]).toEqual(
|
||||
DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
it('should merge inherited actions with provided config', () => {
|
||||
const customConfig: Record<string, CommandMenuItemConfig> = {
|
||||
'custom-action': {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: 'custom-action',
|
||||
label: 'Custom Action',
|
||||
position: 100,
|
||||
Icon: IconPlus,
|
||||
shouldBeRegistered: () => true,
|
||||
component: MockComponent,
|
||||
},
|
||||
};
|
||||
|
||||
const commandKeys: DefaultRecordCommandKeys[] = [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
];
|
||||
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: customConfig,
|
||||
commandKeys,
|
||||
propertiesToOverwrite: {},
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]:
|
||||
DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD
|
||||
],
|
||||
'custom-action': customConfig['custom-action'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should prioritize provided config over inherited actions when keys conflict', () => {
|
||||
const customConfig: Record<string, CommandMenuItemConfig> = {
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
label: 'Overridden Create Action',
|
||||
position: 999,
|
||||
Icon: IconHeart,
|
||||
shouldBeRegistered: () => false,
|
||||
component: MockComponent,
|
||||
},
|
||||
};
|
||||
|
||||
const commandKeys: DefaultRecordCommandKeys[] = [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
];
|
||||
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: customConfig,
|
||||
commandKeys,
|
||||
propertiesToOverwrite: {},
|
||||
});
|
||||
|
||||
expect(result[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]).toEqual(
|
||||
customConfig[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD],
|
||||
);
|
||||
expect(result[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD].label).toBe(
|
||||
'Overridden Create Action',
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle complex scenario with inheritance, overrides, and custom config', () => {
|
||||
const customConfig: Record<string, CommandMenuItemConfig> = {
|
||||
'custom-action-1': {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.Object,
|
||||
key: 'custom-action-1',
|
||||
label: 'Custom Action 1',
|
||||
position: 50,
|
||||
Icon: IconPlus,
|
||||
shouldBeRegistered: () => true,
|
||||
component: MockComponent,
|
||||
},
|
||||
[SingleRecordCommandKeys.ADD_TO_FAVORITES]: {
|
||||
type: CommandMenuItemType.Standard,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
key: SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
label: 'Completely Custom Favorites',
|
||||
position: 1000,
|
||||
Icon: IconHeart,
|
||||
shouldBeRegistered: () => false,
|
||||
component: MockComponent,
|
||||
},
|
||||
};
|
||||
|
||||
const commandKeys: DefaultRecordCommandKeys[] = [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
SingleRecordCommandKeys.ADD_TO_FAVORITES,
|
||||
SingleRecordCommandKeys.REMOVE_FROM_FAVORITES,
|
||||
];
|
||||
|
||||
const propertiesToOverwrite = {
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: {
|
||||
label: 'Modified Create Label',
|
||||
position: 5,
|
||||
},
|
||||
[SingleRecordCommandKeys.REMOVE_FROM_FAVORITES]: {
|
||||
isPinned: false,
|
||||
},
|
||||
};
|
||||
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: customConfig,
|
||||
commandKeys,
|
||||
propertiesToOverwrite,
|
||||
});
|
||||
|
||||
expect(Object.keys(result)).toHaveLength(4);
|
||||
|
||||
expect(result['custom-action-1']).toEqual(customConfig['custom-action-1']);
|
||||
|
||||
expect(result[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]).toEqual({
|
||||
...DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD
|
||||
],
|
||||
label: 'Modified Create Label',
|
||||
position: 5,
|
||||
});
|
||||
|
||||
expect(result[SingleRecordCommandKeys.ADD_TO_FAVORITES]).toEqual(
|
||||
customConfig[SingleRecordCommandKeys.ADD_TO_FAVORITES],
|
||||
);
|
||||
|
||||
expect(result[SingleRecordCommandKeys.REMOVE_FROM_FAVORITES]).toEqual({
|
||||
...DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
SingleRecordCommandKeys.REMOVE_FROM_FAVORITES
|
||||
],
|
||||
isPinned: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty overrides gracefully', () => {
|
||||
const commandKeys: DefaultRecordCommandKeys[] = [
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD,
|
||||
];
|
||||
|
||||
const propertiesToOverwrite = {
|
||||
[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]: {},
|
||||
};
|
||||
|
||||
const result = inheritCommandMenuItemsFromDefaultConfig({
|
||||
config: {},
|
||||
commandKeys,
|
||||
propertiesToOverwrite,
|
||||
});
|
||||
|
||||
expect(result[NoSelectionRecordCommandKeys.CREATE_NEW_RECORD]).toEqual(
|
||||
DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[
|
||||
NoSelectionRecordCommandKeys.CREATE_NEW_RECORD
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG } from '@/command-menu-item/record/constants/DefaultRecordCommandMenuItemsConfig';
|
||||
import { type CommandMenuItemConfig } from '@/command-menu-item/types/CommandMenuItemConfig';
|
||||
import { type DefaultRecordCommandKeys } from '@/command-menu-item/record/types/DefaultRecordCommandKeys';
|
||||
|
||||
export const inheritCommandMenuItemsFromDefaultConfig = ({
|
||||
config,
|
||||
commandKeys,
|
||||
propertiesToOverwrite,
|
||||
}: {
|
||||
config: Record<string, CommandMenuItemConfig>;
|
||||
commandKeys: DefaultRecordCommandKeys[];
|
||||
propertiesToOverwrite: Partial<
|
||||
Record<DefaultRecordCommandKeys, Partial<CommandMenuItemConfig>>
|
||||
>;
|
||||
}): Record<string, CommandMenuItemConfig> => {
|
||||
const commandMenuItemsFromDefaultConfig = commandKeys.reduce(
|
||||
(acc, key) => ({
|
||||
...acc,
|
||||
[key]: {
|
||||
...DEFAULT_RECORD_COMMAND_MENU_ITEMS_CONFIG[key],
|
||||
...propertiesToOverwrite[key],
|
||||
},
|
||||
}),
|
||||
{} as Record<string, CommandMenuItemConfig>,
|
||||
);
|
||||
|
||||
return {
|
||||
...commandMenuItemsFromDefaultConfig,
|
||||
...config,
|
||||
};
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { type WorkflowTrigger } from '@/workflow/types/Workflow';
|
||||
|
||||
export const isBulkRecordsManualTrigger = (trigger: WorkflowTrigger) => {
|
||||
return (
|
||||
trigger.type === 'MANUAL' &&
|
||||
trigger?.settings?.availability?.type === 'BULK_RECORDS'
|
||||
);
|
||||
};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import { type WorkflowTrigger } from '@/workflow/types/Workflow';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const isGlobalManualTrigger = (trigger: WorkflowTrigger) => {
|
||||
if (trigger.type !== 'MANUAL') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Legacy support for manual triggers without availability
|
||||
if (!isDefined(trigger.settings?.availability)) {
|
||||
return !isDefined(trigger.settings?.objectType);
|
||||
}
|
||||
|
||||
return trigger.settings.availability.type === 'GLOBAL';
|
||||
};
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
import { Command } from '@/command-menu-item/display/components/Command';
|
||||
import { isBulkRecordsManualTrigger } from '@/command-menu-item/record/utils/isBulkRecordsManualTrigger';
|
||||
import { CommandMenuItemScope } from '@/command-menu-item/types/CommandMenuItemScope';
|
||||
import { CommandMenuItemType } from '@/command-menu-item/types/CommandMenuItemType';
|
||||
import { contextStoreIsPageInEditModeComponentState } from '@/context-store/states/contextStoreIsPageInEditModeComponentState';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
||||
import { useActiveWorkflowVersionsWithManualTrigger } from '@/workflow/hooks/useActiveWorkflowVersionsWithManualTrigger';
|
||||
import { useRunWorkflowVersion } from '@/workflow/hooks/useRunWorkflowVersion';
|
||||
|
||||
import { type WorkflowVersion } from '@/workflow/types/Workflow';
|
||||
import { COMMAND_MENU_DEFAULT_ICON } from '@/workflow/workflow-trigger/constants/CommandMenuDefaultIcon';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { useCallback } from 'react';
|
||||
import { QUERY_MAX_RECORDS } from 'twenty-shared/constants';
|
||||
import { capitalize, isDefined } from 'twenty-shared/utils';
|
||||
import { useIcons } from 'twenty-ui/display';
|
||||
import { useStore } from 'jotai';
|
||||
|
||||
export const useRunWorkflowRecordCommands = ({
|
||||
objectMetadataItem,
|
||||
skip,
|
||||
}: {
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
skip?: boolean;
|
||||
}) => {
|
||||
const store = useStore();
|
||||
const { getIcon } = useIcons();
|
||||
const { enqueueWarningSnackBar } = useSnackBar();
|
||||
|
||||
const contextStoreTargetedRecordsRule = useAtomComponentStateValue(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
);
|
||||
|
||||
const contextStoreIsPageInEditMode = useAtomComponentStateValue(
|
||||
contextStoreIsPageInEditModeComponentState,
|
||||
);
|
||||
|
||||
const selectedRecordIds =
|
||||
contextStoreTargetedRecordsRule.mode === 'selection'
|
||||
? contextStoreTargetedRecordsRule.selectedRecordIds
|
||||
: undefined;
|
||||
|
||||
const { records: activeWorkflowVersions } =
|
||||
useActiveWorkflowVersionsWithManualTrigger({
|
||||
objectMetadataItem,
|
||||
skip,
|
||||
});
|
||||
|
||||
const { runWorkflowVersion } = useRunWorkflowVersion();
|
||||
|
||||
const runWorkflowVersionOnSelectedRecords = useCallback(
|
||||
async (
|
||||
selectedRecordIds: string[],
|
||||
activeWorkflowVersion: Pick<
|
||||
WorkflowVersion,
|
||||
'id' | 'workflowId' | 'trigger'
|
||||
>,
|
||||
) => {
|
||||
if (selectedRecordIds.length > QUERY_MAX_RECORDS) {
|
||||
const selectedCountFormatted =
|
||||
selectedRecordIds.length.toLocaleString();
|
||||
const limitFormatted = QUERY_MAX_RECORDS.toLocaleString();
|
||||
|
||||
enqueueWarningSnackBar({
|
||||
message: t`You selected ${selectedCountFormatted} records but manual triggers can run on at most ${limitFormatted} records at once. Only the first ${limitFormatted} records will be processed.`,
|
||||
options: {
|
||||
dedupeKey: 'workflow-manual-trigger-selection-limit',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const limitedSelectedRecordIds = selectedRecordIds.slice(
|
||||
0,
|
||||
QUERY_MAX_RECORDS,
|
||||
);
|
||||
|
||||
if (
|
||||
isDefined(activeWorkflowVersion?.trigger) &&
|
||||
isBulkRecordsManualTrigger(activeWorkflowVersion.trigger)
|
||||
) {
|
||||
const objectNamePlural = objectMetadataItem.namePlural;
|
||||
const selectedRecords = limitedSelectedRecordIds
|
||||
.map((recordId) =>
|
||||
store.get(recordStoreFamilyState.atomFamily(recordId)),
|
||||
)
|
||||
.filter(isDefined);
|
||||
|
||||
await runWorkflowVersion({
|
||||
workflowId: activeWorkflowVersion.workflowId,
|
||||
workflowVersionId: activeWorkflowVersion.id,
|
||||
payload: {
|
||||
[objectNamePlural]: selectedRecords,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
for (const selectedRecordId of limitedSelectedRecordIds) {
|
||||
const selectedRecord = store.get(
|
||||
recordStoreFamilyState.atomFamily(selectedRecordId),
|
||||
);
|
||||
|
||||
if (!isDefined(selectedRecord)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await runWorkflowVersion({
|
||||
workflowId: activeWorkflowVersion.workflowId,
|
||||
workflowVersionId: activeWorkflowVersion.id,
|
||||
payload: selectedRecord,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
[runWorkflowVersion, objectMetadataItem, enqueueWarningSnackBar, store],
|
||||
);
|
||||
|
||||
return activeWorkflowVersions
|
||||
.filter((activeWorkflowVersion) =>
|
||||
isDefined(activeWorkflowVersion.workflow),
|
||||
)
|
||||
.map((activeWorkflowVersion, index) => {
|
||||
const name = capitalize(activeWorkflowVersion.workflow.name);
|
||||
|
||||
const Icon = getIcon(
|
||||
activeWorkflowVersion.trigger?.settings.icon,
|
||||
COMMAND_MENU_DEFAULT_ICON,
|
||||
);
|
||||
|
||||
return {
|
||||
type: CommandMenuItemType.WorkflowRun,
|
||||
key: `workflow-run-${activeWorkflowVersion.id}`,
|
||||
scope: CommandMenuItemScope.RecordSelection,
|
||||
label: name,
|
||||
shortLabel: name,
|
||||
position: index,
|
||||
Icon,
|
||||
isPinned:
|
||||
!contextStoreIsPageInEditMode &&
|
||||
activeWorkflowVersion.trigger?.settings?.isPinned,
|
||||
shouldBeRegistered: () => true,
|
||||
component: (
|
||||
<Command
|
||||
onClick={async () => {
|
||||
if (!isDefined(selectedRecordIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await runWorkflowVersionOnSelectedRecords(
|
||||
selectedRecordIds,
|
||||
activeWorkflowVersion,
|
||||
);
|
||||
}}
|
||||
closeSidePanelOnCommandMenuListExecution={false}
|
||||
/>
|
||||
),
|
||||
};
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user