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