Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Oct 7, 2024
1 parent ba14b9c commit a92f84e
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,7 +10,7 @@ export const WorkspaceFavorites = () => {
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);

const { activeObjectMetadataItems: objectMetadataItemsToDisplay } =
useObjectMetadataItemsInWorkspaceFavorites();
useFilteredObjectMetadataItemsForWorkspaceFavorites();

const loading = useIsPrefetchLoading();
if (loading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<View>(PrefetchKey.AllViews);

const { workspaceFavorites } = useFavorites();
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -23,11 +18,10 @@ export const NavigationDrawerOpenedSection = () => {
const { records: views } = usePrefetchedData<View>(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;
Expand All @@ -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 <NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader />;
}

Expand All @@ -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;
};

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';

export const shouldSeedWorkspaceFavorite = (
objectMetadataId,
objectMetadataMap,
) => [
objectMetadataId !==
objectMetadataMap[STANDARD_OBJECT_IDS.workflowVersion].id &&
objectMetadataId !== objectMetadataMap[STANDARD_OBJECT_IDS.workflowRun].id,
];
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit a92f84e

Please sign in to comment.