From 5a1a678dc56b4db432571fa06902eabde0bff78d Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Wed, 25 Sep 2024 18:04:00 +0200 Subject: [PATCH 1/6] Add opened section for non-displayed objects --- .../components/WorkspaceFavorites.tsx | 25 +------ .../components/MainNavigationDrawerItems.tsx | 3 + ...ObjectMetadataItemsInWorkspaceFavorites.ts | 32 ++++++++ .../NavigationDrawerOpenedSection.tsx | 74 +++++++++++++++++++ .../data-seed-dev-workspace.command.ts | 14 +++- ...ject-metadata-ids-for-favorites-prefill.ts | 8 ++ .../demo-objects-prefill-data.ts | 5 +- .../standard-objects-prefill-data.ts | 12 ++- .../standard-objects-prefill-data/view.ts | 10 ++- .../views/workflow-runs-all.view.ts | 56 ++++++++++++++ .../views/workflow-versions.view.ts | 56 ++++++++++++++ .../constants/standard-field-ids.ts | 3 + .../workflow-run.workspace-entity.ts | 29 +++++++- .../workflow-version.workspace-entity.ts | 19 ++++- .../workflow.workspace-entity.ts | 1 + 15 files changed, 315 insertions(+), 32 deletions(-) create mode 100644 packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts create mode 100644 packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx create mode 100644 packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill.ts create mode 100644 packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view.ts create mode 100644 packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts diff --git a/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx b/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx index b89290526c98..0876a7713412 100644 --- a/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx +++ b/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx @@ -1,7 +1,6 @@ -import { useFavorites } from '@/favorites/hooks/useFavorites'; +import { useObjectMetadataItemsInWorkspaceFavorites } from '@/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites'; import { NavigationDrawerSectionForObjectMetadataItems } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItems'; import { NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader'; -import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems'; import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading'; import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData'; import { PrefetchKey } from '@/prefetch/types/PrefetchKey'; @@ -9,27 +8,11 @@ import { View } from '@/views/types/View'; export const WorkspaceFavorites = () => { const { records: views } = usePrefetchedData(PrefetchKey.AllViews); - const loading = useIsPrefetchLoading(); - - const { workspaceFavorites } = useFavorites(); - - const workspaceFavoriteIds = new Set( - workspaceFavorites.map((favorite) => favorite.recordId), - ); - const favoriteViewObjectMetadataIds = views.reduce((acc, view) => { - if (workspaceFavoriteIds.has(view.id)) { - acc.push(view.objectMetadataId); - } - return acc; - }, []); - - const { objectMetadataItems } = useFilteredObjectMetadataItems(); - - const objectMetadataItemsToDisplay = objectMetadataItems.filter((item) => - favoriteViewObjectMetadataIds.includes(item.id), - ); + const { objectMetadataItems: objectMetadataItemsToDisplay } = + useObjectMetadataItemsInWorkspaceFavorites(); + const loading = useIsPrefetchLoading(); if (loading) { return ; } diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerItems.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerItems.tsx index 88f18e97e66b..867b5b49f558 100644 --- a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerItems.tsx +++ b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerItems.tsx @@ -5,6 +5,7 @@ import { IconSearch, IconSettings } from 'twenty-ui'; import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; import { CurrentWorkspaceMemberFavorites } from '@/favorites/components/CurrentWorkspaceMemberFavorites'; import { WorkspaceFavorites } from '@/favorites/components/WorkspaceFavorites'; +import { NavigationDrawerOpenedSection } from '@/object-metadata/components/NavigationDrawerOpenedSection'; import { NavigationDrawerSectionForObjectMetadataItemsWrapper } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItemsWrapper'; import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem'; import { NavigationDrawerSection } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSection'; @@ -44,6 +45,8 @@ export const MainNavigationDrawerItems = () => { )} + {isWorkspaceFavoriteEnabled && } + {isWorkspaceFavoriteEnabled ? ( diff --git a/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts b/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts new file mode 100644 index 000000000000..55c70dc04237 --- /dev/null +++ b/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts @@ -0,0 +1,32 @@ +import { useFavorites } from '@/favorites/hooks/useFavorites'; +import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems'; +import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData'; +import { PrefetchKey } from '@/prefetch/types/PrefetchKey'; +import { View } from '@/views/types/View'; + +export const useObjectMetadataItemsInWorkspaceFavorites = () => { + const { records: views } = usePrefetchedData(PrefetchKey.AllViews); + + const { workspaceFavorites } = useFavorites(); + + const workspaceFavoriteIds = new Set( + workspaceFavorites.map((favorite) => favorite.recordId), + ); + + const favoriteViewObjectMetadataIds = views.reduce((acc, view) => { + if (workspaceFavoriteIds.has(view.id)) { + acc.push(view.objectMetadataId); + } + return acc; + }, []); + + const { objectMetadataItems } = useFilteredObjectMetadataItems(); + + const objectMetadataItemsInWorkspaceFavorites = objectMetadataItems.filter( + (item) => favoriteViewObjectMetadataIds.includes(item.id), + ); + + return { + objectMetadataItems: objectMetadataItemsInWorkspaceFavorites, + }; +}; diff --git a/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx b/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx new file mode 100644 index 000000000000..4420edb31eb0 --- /dev/null +++ b/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx @@ -0,0 +1,74 @@ +import { useLocation } from 'react-router-dom'; +import { useRecoilValue } from 'recoil'; +import { isDefined } from 'twenty-ui'; + +import { currentUserState } from '@/auth/states/currentUserState'; +import { useObjectMetadataItemsInWorkspaceFavorites } from '@/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites'; +import { NavigationDrawerSectionForObjectMetadataItems } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItems'; +import { NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader'; +import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems'; +import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading'; +import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData'; +import { PrefetchKey } from '@/prefetch/types/PrefetchKey'; +import { View } from '@/views/types/View'; + +export const NavigationDrawerOpenedSection = () => { + const currentUser = useRecoilValue(currentUserState); + + const { activeObjectMetadataItems } = useFilteredObjectMetadataItems(); + const filteredActiveObjectMetadataItems = activeObjectMetadataItems.filter( + (item) => !item.isRemote, + ); + + const { records: views } = usePrefetchedData(PrefetchKey.AllViews); + const loading = useIsPrefetchLoading(); + + const currentPath = useLocation().pathname; + const currentObjectNamePlural = extractObjectFromCurrentPath(currentPath); + + const { objectMetadataItems: objectMetadataItemsCurrentlyDisplayed } = + useObjectMetadataItemsInWorkspaceFavorites(); + + if (!currentObjectNamePlural) { + return; + } + + const objectMetadataItem = filteredActiveObjectMetadataItems.find( + (item) => item.namePlural === currentObjectNamePlural, + ); + + if (!objectMetadataItem) { + return; + } + + const shouldDisplayObjectInOpenedSection = + !objectMetadataItemsCurrentlyDisplayed + .map((item) => item.id) + .includes(objectMetadataItem.id); + + if (loading && isDefined(currentUser)) { + return ; + } + + return ( + shouldDisplayObjectInOpenedSection && ( + + ) + ); +}; + +const extractObjectFromCurrentPath = (url: string): string | null => { + const regex = /^\/objects\/([^/?]+)/; + const match = url.match(regex); + + if (isDefined(match) && match.length > 1) { + return match[1]; + } + + return null; +}; diff --git a/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts b/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts index 50113a1c95b4..74b30f479a82 100644 --- a/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts +++ b/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts @@ -40,6 +40,7 @@ import { DataSourceService } from 'src/engine/metadata-modules/data-source/data- import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service'; +import { getExcludedObjectMetadataIdsForFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill'; import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service'; import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; @@ -217,9 +218,20 @@ export class DataSeedWorkspaceCommand extends CommandRunner { isWorkflowEnabled, ); + const excludedObjectMetadataIdsForFavoritesPrefill = + getExcludedObjectMetadataIdsForFavoritesPrefill( + objectMetadataMap, + ); + await seedWorkspaceFavorites( viewDefinitionsWithId - .filter((view) => view.key === 'INDEX') + .filter( + (view) => + view.key === 'INDEX' && + !excludedObjectMetadataIdsForFavoritesPrefill.includes( + view.objectMetadataId, + ), + ) .map((view) => view.id), entityManager, dataSourceMetadata.schema, diff --git a/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill.ts b/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill.ts new file mode 100644 index 000000000000..59744906704b --- /dev/null +++ b/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill.ts @@ -0,0 +1,8 @@ +import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; + +export const getExcludedObjectMetadataIdsForFavoritesPrefill = ( + objectMetadataMap, +) => [ + objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].id, + objectMetadataMap[STANDARD_OBJECT_IDS.workflowRun].id, +]; diff --git a/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts b/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts index 226e5557c82b..a7ee8e760172 100644 --- a/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts +++ b/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts @@ -2,6 +2,7 @@ import { DataSource, EntityManager } from 'typeorm'; import { seedWorkspaceFavorites } from 'src/database/typeorm-seeds/workspace/favorites'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; +import { getExcludedObjectMetadataIdsForFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill'; import { companyPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/company'; import { opportunityPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/opportunity'; import { personPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/person'; @@ -40,9 +41,11 @@ export const demoObjectsPrefillData = async ( isWorkflowEnabled, ); + const excludedObjectMetadataIdsForFavoritesPrefill = getExcludedObjectMetadataIdsForFavoritesPrefill(objectMetadataMap); + await seedWorkspaceFavorites( viewDefinitionsWithId - .filter((view) => view.key === 'INDEX') + .filter((view) => view.key === 'INDEX' && !excludedObjectMetadataIdsForFavoritesPrefill.includes(view.objectMetadataId)) .map((view) => view.id), entityManager, schemaName, diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts index 7198fe4ef1e6..c3b5f745562b 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts @@ -2,6 +2,7 @@ import { DataSource, EntityManager } from 'typeorm'; import { seedWorkspaceFavorites } from 'src/database/typeorm-seeds/workspace/favorites'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; +import { getExcludedObjectMetadataIdsForFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill'; import { companyPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/company'; import { personPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/person'; import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view'; @@ -43,9 +44,18 @@ export const standardObjectsPrefillData = async ( isWorkflowEnabled, ); + const excludedObjectMetadataIdsForFavoritesPrefill = + getExcludedObjectMetadataIdsForFavoritesPrefill(objectMetadataMap); + await seedWorkspaceFavorites( viewDefinitionsWithId - .filter((view) => view.key === 'INDEX') + .filter( + (view) => + view.key === 'INDEX' && + !excludedObjectMetadataIdsForFavoritesPrefill.includes( + view.objectMetadataId, + ), + ) .map((view) => view.id), entityManager, schemaName, diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts index a4f230eaca32..f3b1e33c256d 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts @@ -9,6 +9,8 @@ import { opportunitiesByStageView } from 'src/engine/workspace-manager/standard- import { peopleAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/people-all.view'; import { tasksAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-all.view'; import { tasksByStatusView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-by-status.view'; +import { workflowRunsAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view'; +import { workflowVersionsAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view'; import { workflowsAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/workflows-all.view'; export const viewPrefillData = async ( @@ -25,7 +27,13 @@ export const viewPrefillData = async ( await notesAllView(objectMetadataMap), await tasksAllView(objectMetadataMap), await tasksByStatusView(objectMetadataMap), - ...(isWorkflowEnabled ? [await workflowsAllView(objectMetadataMap)] : []), + ...(isWorkflowEnabled + ? [ + await workflowsAllView(objectMetadataMap), + await workflowVersionsAllView(objectMetadataMap), + await workflowRunsAllView(objectMetadataMap), + ] + : []), ]; const viewDefinitionsWithId = viewDefinitions.map((viewDefinition) => ({ diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view.ts new file mode 100644 index 000000000000..52a2578a49da --- /dev/null +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view.ts @@ -0,0 +1,56 @@ +import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; +import { WORKFLOW_RUN_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; +import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; + +export const workflowRunsAllView = async ( + objectMetadataMap: Record, +) => { + return { + name: 'All Workflow Runs', + objectMetadataId: objectMetadataMap[STANDARD_OBJECT_IDS.workflowRun].id, + type: 'table', + key: 'INDEX', + position: 0, + icon: 'IconHistory', + kanbanFieldMetadataId: '', + filters: [], + fields: [ + { + fieldMetadataId: + objectMetadataMap[STANDARD_OBJECT_IDS.workflowRun].fields[ + WORKFLOW_RUN_STANDARD_FIELD_IDS.name + ], + position: 0, + isVisible: true, + size: 210, + }, + { + fieldMetadataId: + objectMetadataMap[STANDARD_OBJECT_IDS.workflowRun].fields[ + WORKFLOW_RUN_STANDARD_FIELD_IDS.status + ], + position: 1, + isVisible: true, + size: 150, + }, + { + fieldMetadataId: + objectMetadataMap[STANDARD_OBJECT_IDS.workflowRun].fields[ + WORKFLOW_RUN_STANDARD_FIELD_IDS.startedAt + ], + position: 2, + isVisible: true, + size: 150, + }, + { + fieldMetadataId: + objectMetadataMap[STANDARD_OBJECT_IDS.workflowRun].fields[ + WORKFLOW_RUN_STANDARD_FIELD_IDS.endedAt + ], + position: 3, + isVisible: true, + size: 150, + }, + ], + }; +}; diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts new file mode 100644 index 000000000000..d91b93bd0401 --- /dev/null +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts @@ -0,0 +1,56 @@ +import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; +import { WORKFLOW_VERSION_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; +import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; + +export const workflowVersionsAllView = async ( + objectMetadataMap: Record, +) => { + return { + name: 'All Workflow Versions', + objectMetadataId: objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].id, + type: 'table', + key: 'INDEX', + position: 0, + icon: 'IconVersions', + kanbanFieldMetadataId: '', + filters: [], + fields: [ + { + fieldMetadataId: + objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].fields[ + WORKFLOW_VERSION_STANDARD_FIELD_IDS.name + ], + position: 0, + isVisible: true, + size: 210, + }, + { + fieldMetadataId: + objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].fields[ + WORKFLOW_VERSION_STANDARD_FIELD_IDS.status + ], + position: 1, + isVisible: true, + size: 150, + }, + { + fieldMetadataId: + objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].fields[ + WORKFLOW_VERSION_STANDARD_FIELD_IDS.trigger + ], + position: 2, + isVisible: true, + size: 150, + }, + { + fieldMetadataId: + objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].fields[ + WORKFLOW_VERSION_STANDARD_FIELD_IDS.steps + ], + position: 3, + isVisible: true, + size: 150, + }, + ], + }; +}; diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids.ts index d9359e6eb595..6243016b8f73 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids.ts @@ -412,11 +412,13 @@ export const WORKFLOW_STANDARD_FIELD_IDS = { }; export const WORKFLOW_RUN_STANDARD_FIELD_IDS = { + name: '20202020-b840-4253-aef9-4e5013694587', workflowVersion: '20202020-2f52-4ba8-8dc4-d0d6adb9578d', workflow: '20202020-8c57-4e7f-84f5-f373f68e1b82', startedAt: '20202020-a234-4e2d-bd15-85bcea6bb183', endedAt: '20202020-e1c1-4b6b-bbbd-b2beaf2e159e', status: '20202020-6b3e-4f9c-8c2b-2e5b8e6d6f3b', + position: '20202020-7802-4c40-ae89-1f506fe3365c', createdBy: '20202020-6007-401a-8aa5-e6f38581a6f3', output: '20202020-7be4-4db2-8ac6-3ff0d740843d', }; @@ -426,6 +428,7 @@ export const WORKFLOW_VERSION_STANDARD_FIELD_IDS = { workflow: '20202020-afa3-46c3-91b0-0631ca6aa1c8', trigger: '20202020-4eae-43e7-86e0-212b41a30b48', status: '20202020-5a34-440e-8a25-39d8c3d1d4cf', + position: '20202020-791d-4950-ab28-0e704767ae1c', runs: '20202020-1d08-46df-901a-85045f18099a', steps: '20202020-5988-4a64-b94a-1f9b7b989039', }; diff --git a/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-run.workspace-entity.ts b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-run.workspace-entity.ts index 388d5f1293c9..347536f57a82 100644 --- a/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-run.workspace-entity.ts +++ b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-run.workspace-entity.ts @@ -41,15 +41,25 @@ export type WorkflowRunOutput = { @WorkspaceEntity({ standardId: STANDARD_OBJECT_IDS.workflowRun, namePlural: 'workflowRuns', - labelSingular: 'workflowRun', - labelPlural: 'WorkflowRuns', + labelSingular: 'Workflow Run', + labelPlural: 'Workflow Runs', description: 'A workflow run', + labelIdentifierStandardId: WORKFLOW_RUN_STANDARD_FIELD_IDS.name, + icon: 'IconHistory', }) @WorkspaceGate({ featureFlag: FeatureFlagKey.IsWorkflowEnabled, }) -@WorkspaceIsSystem() export class WorkflowRunWorkspaceEntity extends BaseWorkspaceEntity { + @WorkspaceField({ + standardId: WORKFLOW_RUN_STANDARD_FIELD_IDS.name, + type: FieldMetadataType.TEXT, + label: 'Name', + description: 'Name of the workflow run', + icon: 'IconText', + }) + name: string; + @WorkspaceField({ standardId: WORKFLOW_RUN_STANDARD_FIELD_IDS.startedAt, type: FieldMetadataType.DATE_TIME, @@ -75,7 +85,7 @@ export class WorkflowRunWorkspaceEntity extends BaseWorkspaceEntity { type: FieldMetadataType.SELECT, label: 'Workflow run status', description: 'Workflow run status', - icon: 'IconHistory', + icon: 'IconStatusChange', options: [ { value: WorkflowRunStatus.NOT_STARTED, @@ -128,6 +138,17 @@ export class WorkflowRunWorkspaceEntity extends BaseWorkspaceEntity { @WorkspaceIsNullable() output: WorkflowRunOutput | null; + @WorkspaceField({ + standardId: WORKFLOW_RUN_STANDARD_FIELD_IDS.position, + type: FieldMetadataType.POSITION, + label: 'Position', + description: 'Workflow run position', + icon: 'IconHierarchy2', + }) + @WorkspaceIsSystem() + @WorkspaceIsNullable() + position: number | null; + // Relations @WorkspaceRelation({ standardId: WORKFLOW_RUN_STANDARD_FIELD_IDS.workflowVersion, diff --git a/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-version.workspace-entity.ts b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-version.workspace-entity.ts index 80545fe7897d..5ec2b4ade7da 100644 --- a/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-version.workspace-entity.ts +++ b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-version.workspace-entity.ts @@ -61,8 +61,8 @@ const WorkflowVersionStatusOptions = [ @WorkspaceEntity({ standardId: STANDARD_OBJECT_IDS.workflowVersion, namePlural: 'workflowVersions', - labelSingular: 'WorkflowVersion', - labelPlural: 'WorkflowVersions', + labelSingular: 'Workflow Version', + labelPlural: 'Workflow Versions', description: 'A workflow version', icon: 'IconVersions', labelIdentifierStandardId: WORKFLOW_VERSION_STANDARD_FIELD_IDS.name, @@ -70,7 +70,6 @@ const WorkflowVersionStatusOptions = [ @WorkspaceGate({ featureFlag: FeatureFlagKey.IsWorkflowEnabled, }) -@WorkspaceIsSystem() export class WorkflowVersionWorkspaceEntity extends BaseWorkspaceEntity { @WorkspaceField({ standardId: WORKFLOW_VERSION_STANDARD_FIELD_IDS.name, @@ -86,6 +85,7 @@ export class WorkflowVersionWorkspaceEntity extends BaseWorkspaceEntity { type: FieldMetadataType.RAW_JSON, label: 'Version trigger', description: 'Json object to provide trigger', + icon: 'IconSettingsAutomation', }) @WorkspaceIsNullable() trigger: WorkflowTrigger | null; @@ -95,6 +95,7 @@ export class WorkflowVersionWorkspaceEntity extends BaseWorkspaceEntity { type: FieldMetadataType.RAW_JSON, label: 'Version steps', description: 'Json object to provide steps', + icon: 'IconSettingsAutomation', }) @WorkspaceIsNullable() steps: WorkflowStep[] | null; @@ -104,11 +105,23 @@ export class WorkflowVersionWorkspaceEntity extends BaseWorkspaceEntity { type: FieldMetadataType.SELECT, label: 'Version status', description: 'The workflow version status', + icon: 'IconStatusChange', options: WorkflowVersionStatusOptions, defaultValue: "'DRAFT'", }) status: WorkflowVersionStatus; + @WorkspaceField({ + standardId: WORKFLOW_VERSION_STANDARD_FIELD_IDS.position, + type: FieldMetadataType.POSITION, + label: 'Position', + description: 'Workflow version position', + icon: 'IconHierarchy2', + }) + @WorkspaceIsSystem() + @WorkspaceIsNullable() + position: number | null; + // Relations @WorkspaceRelation({ standardId: WORKFLOW_VERSION_STANDARD_FIELD_IDS.workflow, diff --git a/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow.workspace-entity.ts b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow.workspace-entity.ts index 98dd40417e35..167f449740ff 100644 --- a/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow.workspace-entity.ts +++ b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow.workspace-entity.ts @@ -84,6 +84,7 @@ export class WorkflowWorkspaceEntity extends BaseWorkspaceEntity { type: FieldMetadataType.MULTI_SELECT, label: 'Statuses', description: 'The current statuses of the workflow versions', + icon: 'IconStatusChange', options: WorkflowStatusOptions, }) @WorkspaceIsNullable() From d9181e0a6fac9a04fc8be35935aba9db812f5d71 Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Thu, 26 Sep 2024 11:41:59 +0200 Subject: [PATCH 2/6] Rename section --- .../src/modules/favorites/components/WorkspaceFavorites.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx b/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx index 0876a7713412..376ba660e63a 100644 --- a/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx +++ b/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx @@ -19,7 +19,7 @@ export const WorkspaceFavorites = () => { return ( Date: Thu, 26 Sep 2024 11:53:37 +0200 Subject: [PATCH 3/6] Rename util --- .../database/commands/data-seed-dev-workspace.command.ts | 8 ++++---- ...xcluded-object-metadata-ids-from-favorites-prefill.ts} | 2 +- .../demo-objects-prefill-data.ts | 6 +++--- .../standard-objects-prefill-data.ts | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) rename packages/twenty-server/src/engine/utils/{get-excluded-object-metadata-ids-for-favorites-prefill.ts => get-excluded-object-metadata-ids-from-favorites-prefill.ts} (80%) diff --git a/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts b/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts index 74b30f479a82..71c48ed4dff2 100644 --- a/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts +++ b/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts @@ -40,7 +40,7 @@ import { DataSourceService } from 'src/engine/metadata-modules/data-source/data- import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service'; -import { getExcludedObjectMetadataIdsForFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill'; +import { getExcludedObjectMetadataIdsFromFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill'; import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service'; import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; @@ -218,8 +218,8 @@ export class DataSeedWorkspaceCommand extends CommandRunner { isWorkflowEnabled, ); - const excludedObjectMetadataIdsForFavoritesPrefill = - getExcludedObjectMetadataIdsForFavoritesPrefill( + const excludedObjectMetadataIdsFromFavoritesPrefill = + getExcludedObjectMetadataIdsFromFavoritesPrefill( objectMetadataMap, ); @@ -228,7 +228,7 @@ export class DataSeedWorkspaceCommand extends CommandRunner { .filter( (view) => view.key === 'INDEX' && - !excludedObjectMetadataIdsForFavoritesPrefill.includes( + !excludedObjectMetadataIdsFromFavoritesPrefill.includes( view.objectMetadataId, ), ) diff --git a/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill.ts b/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill.ts similarity index 80% rename from packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill.ts rename to packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill.ts index 59744906704b..d5a7b50e7c34 100644 --- a/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill.ts +++ b/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill.ts @@ -1,6 +1,6 @@ import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const getExcludedObjectMetadataIdsForFavoritesPrefill = ( +export const getExcludedObjectMetadataIdsFromFavoritesPrefill = ( objectMetadataMap, ) => [ objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].id, diff --git a/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts b/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts index a7ee8e760172..a513f3826bb7 100644 --- a/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts +++ b/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts @@ -2,7 +2,7 @@ import { DataSource, EntityManager } from 'typeorm'; import { seedWorkspaceFavorites } from 'src/database/typeorm-seeds/workspace/favorites'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; -import { getExcludedObjectMetadataIdsForFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill'; +import { getExcludedObjectMetadataIdsFromFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill'; import { companyPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/company'; import { opportunityPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/opportunity'; import { personPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/person'; @@ -41,11 +41,11 @@ export const demoObjectsPrefillData = async ( isWorkflowEnabled, ); - const excludedObjectMetadataIdsForFavoritesPrefill = getExcludedObjectMetadataIdsForFavoritesPrefill(objectMetadataMap); + const excludedObjectMetadataIdsFromFavoritesPrefill = getExcludedObjectMetadataIdsFromFavoritesPrefill(objectMetadataMap); await seedWorkspaceFavorites( viewDefinitionsWithId - .filter((view) => view.key === 'INDEX' && !excludedObjectMetadataIdsForFavoritesPrefill.includes(view.objectMetadataId)) + .filter((view) => view.key === 'INDEX' && !excludedObjectMetadataIdsFromFavoritesPrefill.includes(view.objectMetadataId)) .map((view) => view.id), entityManager, schemaName, diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts index c3b5f745562b..3fa2620156c8 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts @@ -2,7 +2,7 @@ import { DataSource, EntityManager } from 'typeorm'; import { seedWorkspaceFavorites } from 'src/database/typeorm-seeds/workspace/favorites'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; -import { getExcludedObjectMetadataIdsForFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-for-favorites-prefill'; +import { getExcludedObjectMetadataIdsFromFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill'; import { companyPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/company'; import { personPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/person'; import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view'; @@ -44,15 +44,15 @@ export const standardObjectsPrefillData = async ( isWorkflowEnabled, ); - const excludedObjectMetadataIdsForFavoritesPrefill = - getExcludedObjectMetadataIdsForFavoritesPrefill(objectMetadataMap); + const excludedObjectMetadataIdsFromFavoritesPrefill = + getExcludedObjectMetadataIdsFromFavoritesPrefill(objectMetadataMap); await seedWorkspaceFavorites( viewDefinitionsWithId .filter( (view) => view.key === 'INDEX' && - !excludedObjectMetadataIdsForFavoritesPrefill.includes( + !excludedObjectMetadataIdsFromFavoritesPrefill.includes( view.objectMetadataId, ), ) From f485574dcf8bef2cd9636333bae8afe9ddc8a235 Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Thu, 26 Sep 2024 15:40:36 +0200 Subject: [PATCH 4/6] Remove unused async --- ...ObjectMetadataItemsInWorkspaceFavorites.ts | 16 ++++++++------- .../standard-objects-prefill-data/view.ts | 20 +++++++++---------- .../views/companies-all.view.ts | 2 +- .../views/notes-all.view.ts | 2 +- .../views/opportunities-all.view.ts | 2 +- .../views/opportunity-by-stage.view.ts | 2 +- .../views/people-all.view.ts | 2 +- .../views/tasks-all.view.ts | 2 +- .../views/tasks-by-status.view.ts | 2 +- .../views/workflow-runs-all.view.ts | 2 +- .../views/workflow-versions.view.ts | 2 +- .../views/workflows-all.view.ts | 2 +- 12 files changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts b/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts index 55c70dc04237..2ca35b974167 100644 --- a/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts +++ b/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts @@ -13,17 +13,19 @@ export const useObjectMetadataItemsInWorkspaceFavorites = () => { workspaceFavorites.map((favorite) => favorite.recordId), ); - const favoriteViewObjectMetadataIds = views.reduce((acc, view) => { - if (workspaceFavoriteIds.has(view.id)) { - acc.push(view.objectMetadataId); - } - return acc; - }, []); + const favoriteViewObjectMetadataIds = new Set( + views.reduce((acc, view) => { + if (workspaceFavoriteIds.has(view.id)) { + acc.push(view.objectMetadataId); + } + return acc; + }, []), + ); const { objectMetadataItems } = useFilteredObjectMetadataItems(); const objectMetadataItemsInWorkspaceFavorites = objectMetadataItems.filter( - (item) => favoriteViewObjectMetadataIds.includes(item.id), + (item) => favoriteViewObjectMetadataIds.has(item.id), ); return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts index f3b1e33c256d..6802d20a9559 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts @@ -20,18 +20,18 @@ export const viewPrefillData = async ( isWorkflowEnabled: boolean, ) => { const viewDefinitions = [ - await companiesAllView(objectMetadataMap), - await peopleAllView(objectMetadataMap), - await opportunitiesAllView(objectMetadataMap), - await opportunitiesByStageView(objectMetadataMap), - await notesAllView(objectMetadataMap), - await tasksAllView(objectMetadataMap), - await tasksByStatusView(objectMetadataMap), + companiesAllView(objectMetadataMap), + peopleAllView(objectMetadataMap), + opportunitiesAllView(objectMetadataMap), + opportunitiesByStageView(objectMetadataMap), + notesAllView(objectMetadataMap), + tasksAllView(objectMetadataMap), + tasksByStatusView(objectMetadataMap), ...(isWorkflowEnabled ? [ - await workflowsAllView(objectMetadataMap), - await workflowVersionsAllView(objectMetadataMap), - await workflowRunsAllView(objectMetadataMap), + workflowsAllView(objectMetadataMap), + workflowVersionsAllView(objectMetadataMap), + workflowRunsAllView(objectMetadataMap), ] : []), ]; diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/companies-all.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/companies-all.view.ts index ff26eab35631..73aad80dbba6 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/companies-all.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/companies-all.view.ts @@ -5,7 +5,7 @@ import { } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const companiesAllView = async ( +export const companiesAllView = ( objectMetadataMap: Record, ) => { return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/notes-all.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/notes-all.view.ts index 97354aa1f2ff..fec9f63b0ed0 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/notes-all.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/notes-all.view.ts @@ -5,7 +5,7 @@ import { } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const notesAllView = async ( +export const notesAllView = ( objectMetadataMap: Record, ) => { return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/opportunities-all.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/opportunities-all.view.ts index 4dfad89ad4a7..b3a57bf4de61 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/opportunities-all.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/opportunities-all.view.ts @@ -2,7 +2,7 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat import { OPPORTUNITY_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const opportunitiesAllView = async ( +export const opportunitiesAllView = ( objectMetadataMap: Record, ) => { return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/opportunity-by-stage.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/opportunity-by-stage.view.ts index c67a5945b814..82d3b479122c 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/opportunity-by-stage.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/opportunity-by-stage.view.ts @@ -2,7 +2,7 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat import { OPPORTUNITY_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const opportunitiesByStageView = async ( +export const opportunitiesByStageView = ( objectMetadataMap: Record, ) => { return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/people-all.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/people-all.view.ts index 9fbddef9109b..53492e7b9dda 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/people-all.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/people-all.view.ts @@ -5,7 +5,7 @@ import { } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const peopleAllView = async ( +export const peopleAllView = ( objectMetadataMap: Record, ) => { return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-all.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-all.view.ts index 3d9a0ffadf71..29ed1ce476f8 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-all.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-all.view.ts @@ -5,7 +5,7 @@ import { } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const tasksAllView = async ( +export const tasksAllView = ( objectMetadataMap: Record, ) => { return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-by-status.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-by-status.view.ts index fe392c181305..304b3ed0112e 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-by-status.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-by-status.view.ts @@ -5,7 +5,7 @@ import { } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const tasksByStatusView = async ( +export const tasksByStatusView = ( objectMetadataMap: Record, ) => { return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view.ts index 52a2578a49da..d7bc3775d9c3 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view.ts @@ -2,7 +2,7 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat import { WORKFLOW_RUN_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const workflowRunsAllView = async ( +export const workflowRunsAllView = ( objectMetadataMap: Record, ) => { return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts index d91b93bd0401..fff64745d579 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts @@ -2,7 +2,7 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat import { WORKFLOW_VERSION_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const workflowVersionsAllView = async ( +export const workflowVersionsAllView = ( objectMetadataMap: Record, ) => { return { diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflows-all.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflows-all.view.ts index 8eba4bdc4442..330d68523529 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflows-all.view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflows-all.view.ts @@ -2,7 +2,7 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat import { WORKFLOW_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; -export const workflowsAllView = async ( +export const workflowsAllView = ( objectMetadataMap: Record, ) => { return { From ba14b9c3cee0fb921ea2685732f01155fa184884 Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Tue, 1 Oct 2024 15:33:42 +0200 Subject: [PATCH 5/6] Use active objectmetadataItems --- .../favorites/components/WorkspaceFavorites.tsx | 2 +- .../useObjectMetadataItemsInWorkspaceFavorites.ts | 11 ++++++----- .../components/NavigationDrawerOpenedSection.tsx | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx b/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx index 376ba660e63a..931eae9f03f4 100644 --- a/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx +++ b/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx @@ -9,7 +9,7 @@ import { View } from '@/views/types/View'; export const WorkspaceFavorites = () => { const { records: views } = usePrefetchedData(PrefetchKey.AllViews); - const { objectMetadataItems: objectMetadataItemsToDisplay } = + const { activeObjectMetadataItems: objectMetadataItemsToDisplay } = useObjectMetadataItemsInWorkspaceFavorites(); const loading = useIsPrefetchLoading(); diff --git a/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts b/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts index 2ca35b974167..4e9576e58139 100644 --- a/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts +++ b/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts @@ -22,13 +22,14 @@ export const useObjectMetadataItemsInWorkspaceFavorites = () => { }, []), ); - const { objectMetadataItems } = useFilteredObjectMetadataItems(); + const { activeObjectMetadataItems } = useFilteredObjectMetadataItems(); - const objectMetadataItemsInWorkspaceFavorites = objectMetadataItems.filter( - (item) => favoriteViewObjectMetadataIds.has(item.id), - ); + const activeObjectMetadataItemsInWorkspaceFavorites = + activeObjectMetadataItems.filter((item) => + favoriteViewObjectMetadataIds.has(item.id), + ); return { - objectMetadataItems: objectMetadataItemsInWorkspaceFavorites, + activeObjectMetadataItems: activeObjectMetadataItemsInWorkspaceFavorites, }; }; diff --git a/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx b/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx index 4420edb31eb0..bed9adaefe82 100644 --- a/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx +++ b/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx @@ -26,7 +26,7 @@ export const NavigationDrawerOpenedSection = () => { const currentPath = useLocation().pathname; const currentObjectNamePlural = extractObjectFromCurrentPath(currentPath); - const { objectMetadataItems: objectMetadataItemsCurrentlyDisplayed } = + const { activeObjectMetadataItems: objectMetadataItemsCurrentlyDisplayed } = useObjectMetadataItemsInWorkspaceFavorites(); if (!currentObjectNamePlural) { From d1651141c6fcf2323452382e6af090e0ebb657ac Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Mon, 7 Oct 2024 11:46:06 +0200 Subject: [PATCH 6/6] Fix comments --- .../components/WorkspaceFavorites.tsx | 4 +- ...ObjectMetadataItemsInWorkspaceFavorites.ts | 2 +- .../NavigationDrawerOpenedSection.tsx | 31 ++++---------- .../useIsMenuNavbarDisplayed.test.tsx | 40 ------------------- .../layout/hooks/useIsMenuNavbarDisplayed.ts | 6 --- .../data-seed-dev-workspace.command.ts | 10 ++--- ...ect-metadata-ids-from-favorites-prefill.ts | 8 ---- .../utils/should-seed-workspace-favorite.ts | 9 +++++ .../demo-objects-prefill-data.ts | 6 +-- .../standard-objects-prefill-data.ts | 8 ++-- .../standard-objects-prefill-data/view.ts | 2 +- ....view.ts => workflow-versions-all.view.ts} | 0 12 files changed, 28 insertions(+), 98 deletions(-) delete mode 100644 packages/twenty-front/src/modules/ui/layout/hooks/__tests__/useIsMenuNavbarDisplayed.test.tsx delete mode 100644 packages/twenty-front/src/modules/ui/layout/hooks/useIsMenuNavbarDisplayed.ts delete mode 100644 packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill.ts create mode 100644 packages/twenty-server/src/engine/utils/should-seed-workspace-favorite.ts rename packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/{workflow-versions.view.ts => workflow-versions-all.view.ts} (100%) diff --git a/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx b/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx index 931eae9f03f4..cf106211405b 100644 --- a/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx +++ b/packages/twenty-front/src/modules/favorites/components/WorkspaceFavorites.tsx @@ -1,4 +1,4 @@ -import { useObjectMetadataItemsInWorkspaceFavorites } from '@/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites'; +import { useFilteredObjectMetadataItemsForWorkspaceFavorites } from '@/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites'; import { NavigationDrawerSectionForObjectMetadataItems } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItems'; import { NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader'; import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading'; @@ -10,7 +10,7 @@ export const WorkspaceFavorites = () => { const { records: views } = usePrefetchedData(PrefetchKey.AllViews); const { activeObjectMetadataItems: objectMetadataItemsToDisplay } = - useObjectMetadataItemsInWorkspaceFavorites(); + useFilteredObjectMetadataItemsForWorkspaceFavorites(); const loading = useIsPrefetchLoading(); if (loading) { diff --git a/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts b/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts index 4e9576e58139..1c8abefe350e 100644 --- a/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts +++ b/packages/twenty-front/src/modules/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites.ts @@ -4,7 +4,7 @@ import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData'; import { PrefetchKey } from '@/prefetch/types/PrefetchKey'; import { View } from '@/views/types/View'; -export const useObjectMetadataItemsInWorkspaceFavorites = () => { +export const useFilteredObjectMetadataItemsForWorkspaceFavorites = () => { const { records: views } = usePrefetchedData(PrefetchKey.AllViews); const { workspaceFavorites } = useFavorites(); diff --git a/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx b/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx index bed9adaefe82..fb17b643078f 100644 --- a/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx +++ b/packages/twenty-front/src/modules/object-metadata/components/NavigationDrawerOpenedSection.tsx @@ -1,9 +1,6 @@ -import { useLocation } from 'react-router-dom'; -import { useRecoilValue } from 'recoil'; -import { isDefined } from 'twenty-ui'; +import { useParams } from 'react-router-dom'; -import { currentUserState } from '@/auth/states/currentUserState'; -import { useObjectMetadataItemsInWorkspaceFavorites } from '@/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites'; +import { useFilteredObjectMetadataItemsForWorkspaceFavorites } from '@/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites'; import { NavigationDrawerSectionForObjectMetadataItems } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItems'; import { NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader'; import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems'; @@ -13,8 +10,6 @@ import { PrefetchKey } from '@/prefetch/types/PrefetchKey'; import { View } from '@/views/types/View'; export const NavigationDrawerOpenedSection = () => { - const currentUser = useRecoilValue(currentUserState); - const { activeObjectMetadataItems } = useFilteredObjectMetadataItems(); const filteredActiveObjectMetadataItems = activeObjectMetadataItems.filter( (item) => !item.isRemote, @@ -23,11 +18,10 @@ export const NavigationDrawerOpenedSection = () => { const { records: views } = usePrefetchedData(PrefetchKey.AllViews); const loading = useIsPrefetchLoading(); - const currentPath = useLocation().pathname; - const currentObjectNamePlural = extractObjectFromCurrentPath(currentPath); + const currentObjectNamePlural = useParams().objectNamePlural; - const { activeObjectMetadataItems: objectMetadataItemsCurrentlyDisplayed } = - useObjectMetadataItemsInWorkspaceFavorites(); + const { activeObjectMetadataItems: workspaceFavoritesObjectMetadataItems } = + useFilteredObjectMetadataItemsForWorkspaceFavorites(); if (!currentObjectNamePlural) { return; @@ -42,11 +36,11 @@ export const NavigationDrawerOpenedSection = () => { } const shouldDisplayObjectInOpenedSection = - !objectMetadataItemsCurrentlyDisplayed + !workspaceFavoritesObjectMetadataItems .map((item) => item.id) .includes(objectMetadataItem.id); - if (loading && isDefined(currentUser)) { + if (loading) { return ; } @@ -61,14 +55,3 @@ export const NavigationDrawerOpenedSection = () => { ) ); }; - -const extractObjectFromCurrentPath = (url: string): string | null => { - const regex = /^\/objects\/([^/?]+)/; - const match = url.match(regex); - - if (isDefined(match) && match.length > 1) { - return match[1]; - } - - return null; -}; diff --git a/packages/twenty-front/src/modules/ui/layout/hooks/__tests__/useIsMenuNavbarDisplayed.test.tsx b/packages/twenty-front/src/modules/ui/layout/hooks/__tests__/useIsMenuNavbarDisplayed.test.tsx deleted file mode 100644 index 990ff743bbf6..000000000000 --- a/packages/twenty-front/src/modules/ui/layout/hooks/__tests__/useIsMenuNavbarDisplayed.test.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import * as reactRouterDom from 'react-router-dom'; - -import { useIsMenuNavbarDisplayed } from '../useIsMenuNavbarDisplayed'; - -jest.mock('react-router-dom', () => ({ - useLocation: jest.fn(), -})); - -const setupMockLocation = (pathname: string) => { - jest.spyOn(reactRouterDom, 'useLocation').mockReturnValueOnce({ - pathname, - state: undefined, - key: '', - search: '', - hash: '', - }); -}; - -describe('useIsMenuNavbarDisplayed', () => { - it('Should return true for paths starting with "/companies"', () => { - setupMockLocation('/companies'); - - const result = useIsMenuNavbarDisplayed(); - expect(result).toBeTruthy(); - }); - - it('Should return true for paths starting with "/companies/"', () => { - setupMockLocation('/companies/test-some-subpath'); - - const result = useIsMenuNavbarDisplayed(); - expect(result).toBeTruthy(); - }); - - it('Should return false for paths not starting with "/companies"', () => { - setupMockLocation('/test-path'); - - const result = useIsMenuNavbarDisplayed(); - expect(result).toBeFalsy(); - }); -}); diff --git a/packages/twenty-front/src/modules/ui/layout/hooks/useIsMenuNavbarDisplayed.ts b/packages/twenty-front/src/modules/ui/layout/hooks/useIsMenuNavbarDisplayed.ts deleted file mode 100644 index 08f6103f310d..000000000000 --- a/packages/twenty-front/src/modules/ui/layout/hooks/useIsMenuNavbarDisplayed.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { useLocation } from 'react-router-dom'; - -export const useIsMenuNavbarDisplayed = () => { - const currentPath = useLocation().pathname; - return currentPath.match(/^\/companies(\/.*)?$/) !== null; -}; diff --git a/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts b/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts index 71c48ed4dff2..5f212a025a1d 100644 --- a/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts +++ b/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts @@ -40,7 +40,7 @@ import { DataSourceService } from 'src/engine/metadata-modules/data-source/data- import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service'; -import { getExcludedObjectMetadataIdsFromFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill'; +import { shouldSeedWorkspaceFavorite } from 'src/engine/utils/should-seed-workspace-favorite'; import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service'; import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; @@ -218,18 +218,14 @@ export class DataSeedWorkspaceCommand extends CommandRunner { isWorkflowEnabled, ); - const excludedObjectMetadataIdsFromFavoritesPrefill = - getExcludedObjectMetadataIdsFromFavoritesPrefill( - objectMetadataMap, - ); - await seedWorkspaceFavorites( viewDefinitionsWithId .filter( (view) => view.key === 'INDEX' && - !excludedObjectMetadataIdsFromFavoritesPrefill.includes( + shouldSeedWorkspaceFavorite( view.objectMetadataId, + objectMetadataMap, ), ) .map((view) => view.id), diff --git a/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill.ts b/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill.ts deleted file mode 100644 index d5a7b50e7c34..000000000000 --- a/packages/twenty-server/src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; - -export const getExcludedObjectMetadataIdsFromFavoritesPrefill = ( - objectMetadataMap, -) => [ - objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].id, - objectMetadataMap[STANDARD_OBJECT_IDS.workflowRun].id, -]; diff --git a/packages/twenty-server/src/engine/utils/should-seed-workspace-favorite.ts b/packages/twenty-server/src/engine/utils/should-seed-workspace-favorite.ts new file mode 100644 index 000000000000..ae7d9b6ff9f3 --- /dev/null +++ b/packages/twenty-server/src/engine/utils/should-seed-workspace-favorite.ts @@ -0,0 +1,9 @@ +import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; + +export const shouldSeedWorkspaceFavorite = ( + objectMetadataId, + objectMetadataMap, +): boolean => + objectMetadataId !== + objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].id && + objectMetadataId !== objectMetadataMap[STANDARD_OBJECT_IDS.workflowRun].id; diff --git a/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts b/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts index a513f3826bb7..73b36137db03 100644 --- a/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts +++ b/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data.ts @@ -2,7 +2,7 @@ import { DataSource, EntityManager } from 'typeorm'; import { seedWorkspaceFavorites } from 'src/database/typeorm-seeds/workspace/favorites'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; -import { getExcludedObjectMetadataIdsFromFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill'; +import { shouldSeedWorkspaceFavorite } from 'src/engine/utils/should-seed-workspace-favorite'; import { companyPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/company'; import { opportunityPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/opportunity'; import { personPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/person'; @@ -41,11 +41,9 @@ export const demoObjectsPrefillData = async ( isWorkflowEnabled, ); - const excludedObjectMetadataIdsFromFavoritesPrefill = getExcludedObjectMetadataIdsFromFavoritesPrefill(objectMetadataMap); - await seedWorkspaceFavorites( viewDefinitionsWithId - .filter((view) => view.key === 'INDEX' && !excludedObjectMetadataIdsFromFavoritesPrefill.includes(view.objectMetadataId)) + .filter((view) => view.key === 'INDEX' && shouldSeedWorkspaceFavorite(view.objectMetadataId, objectMetadataMap)) .map((view) => view.id), entityManager, schemaName, diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts index 3fa2620156c8..9584474f4377 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data.ts @@ -2,7 +2,7 @@ import { DataSource, EntityManager } from 'typeorm'; import { seedWorkspaceFavorites } from 'src/database/typeorm-seeds/workspace/favorites'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; -import { getExcludedObjectMetadataIdsFromFavoritesPrefill } from 'src/engine/utils/get-excluded-object-metadata-ids-from-favorites-prefill'; +import { shouldSeedWorkspaceFavorite } from 'src/engine/utils/should-seed-workspace-favorite'; import { companyPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/company'; import { personPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/person'; import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view'; @@ -44,16 +44,14 @@ export const standardObjectsPrefillData = async ( isWorkflowEnabled, ); - const excludedObjectMetadataIdsFromFavoritesPrefill = - getExcludedObjectMetadataIdsFromFavoritesPrefill(objectMetadataMap); - await seedWorkspaceFavorites( viewDefinitionsWithId .filter( (view) => view.key === 'INDEX' && - !excludedObjectMetadataIdsFromFavoritesPrefill.includes( + shouldSeedWorkspaceFavorite( view.objectMetadataId, + objectMetadataMap, ), ) .map((view) => view.id), diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts index 6802d20a9559..3b7e47b80d90 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view.ts @@ -10,7 +10,7 @@ import { peopleAllView } from 'src/engine/workspace-manager/standard-objects-pre import { tasksAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-all.view'; import { tasksByStatusView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-by-status.view'; import { workflowRunsAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-runs-all.view'; -import { workflowVersionsAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view'; +import { workflowVersionsAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions-all.view'; import { workflowsAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/workflows-all.view'; export const viewPrefillData = async ( diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions-all.view.ts similarity index 100% rename from packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions.view.ts rename to packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/views/workflow-versions-all.view.ts