Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opened section #7265

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import { useFavorites } from '@/favorites/hooks/useFavorites';
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';
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 WorkspaceFavorites = () => {
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
const loading = useIsPrefetchLoading();

const { workspaceFavorites } = useFavorites();

const workspaceFavoriteIds = new Set(
workspaceFavorites.map((favorite) => favorite.recordId),
);

const favoriteViewObjectMetadataIds = views.reduce<string[]>((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 { activeObjectMetadataItems: objectMetadataItemsToDisplay } =
useFilteredObjectMetadataItemsForWorkspaceFavorites();

const loading = useIsPrefetchLoading();
if (loading) {
return <NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader />;
}

return (
<NavigationDrawerSectionForObjectMetadataItems
sectionTitle={'Workspace Favorites'}
sectionTitle={'Workspace'}
objectMetadataItems={objectMetadataItemsToDisplay}
views={views}
isRemote={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,6 +45,8 @@ export const MainNavigationDrawerItems = () => {
</NavigationDrawerSection>
)}

{isWorkspaceFavoriteEnabled && <NavigationDrawerOpenedSection />}

<CurrentWorkspaceMemberFavorites />

{isWorkspaceFavoriteEnabled ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 useFilteredObjectMetadataItemsForWorkspaceFavorites = () => {
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);

const { workspaceFavorites } = useFavorites();

const workspaceFavoriteIds = new Set(
workspaceFavorites.map((favorite) => favorite.recordId),
);

const favoriteViewObjectMetadataIds = new Set(
views.reduce<string[]>((acc, view) => {
if (workspaceFavoriteIds.has(view.id)) {
acc.push(view.objectMetadataId);
}
return acc;
}, []),
);

const { activeObjectMetadataItems } = useFilteredObjectMetadataItems();

const activeObjectMetadataItemsInWorkspaceFavorites =
activeObjectMetadataItems.filter((item) =>
favoriteViewObjectMetadataIds.has(item.id),
);

return {
activeObjectMetadataItems: activeObjectMetadataItemsInWorkspaceFavorites,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useParams } from 'react-router-dom';

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';
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 = () => {
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
const { activeObjectMetadataItems } = useFilteredObjectMetadataItems();
const filteredActiveObjectMetadataItems = activeObjectMetadataItems.filter(
(item) => !item.isRemote,
);
thomtrp marked this conversation as resolved.
Show resolved Hide resolved

const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
const loading = useIsPrefetchLoading();

const currentObjectNamePlural = useParams().objectNamePlural;

const { activeObjectMetadataItems: workspaceFavoritesObjectMetadataItems } =
useFilteredObjectMetadataItemsForWorkspaceFavorites();

if (!currentObjectNamePlural) {
return;
}

const objectMetadataItem = filteredActiveObjectMetadataItems.find(
(item) => item.namePlural === currentObjectNamePlural,
);

if (!objectMetadataItem) {
return;
}

const shouldDisplayObjectInOpenedSection =
!workspaceFavoritesObjectMetadataItems
.map((item) => item.id)
.includes(objectMetadataItem.id);

if (loading) {
return <NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader />;
}

return (
shouldDisplayObjectInOpenedSection && (
<NavigationDrawerSectionForObjectMetadataItems
sectionTitle={'Opened'}
objectMetadataItems={[objectMetadataItem]}
views={views}
isRemote={false}
/>
)
);
};

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 { 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 @@ -219,7 +220,14 @@ export class DataSeedWorkspaceCommand extends CommandRunner {

await seedWorkspaceFavorites(
viewDefinitionsWithId
.filter((view) => view.key === 'INDEX')
.filter(
(view) =>
view.key === 'INDEX' &&
shouldSeedWorkspaceFavorite(
view.objectMetadataId,
objectMetadataMap,
),
)
.map((view) => view.id),
entityManager,
dataSourceMetadata.schema,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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 { 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 @@ -42,7 +43,7 @@ export const demoObjectsPrefillData = async (

await seedWorkspaceFavorites(
viewDefinitionsWithId
.filter((view) => view.key === 'INDEX')
.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,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 { 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 @@ -45,7 +46,14 @@ export const standardObjectsPrefillData = async (

await seedWorkspaceFavorites(
viewDefinitionsWithId
.filter((view) => view.key === 'INDEX')
.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 @@ -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-all.view';
import { workflowsAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/workflows-all.view';

export const viewPrefillData = async (
Expand All @@ -18,14 +20,20 @@ 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),
...(isWorkflowEnabled ? [await workflowsAllView(objectMetadataMap)] : []),
companiesAllView(objectMetadataMap),
peopleAllView(objectMetadataMap),
opportunitiesAllView(objectMetadataMap),
opportunitiesByStageView(objectMetadataMap),
notesAllView(objectMetadataMap),
tasksAllView(objectMetadataMap),
tasksByStatusView(objectMetadataMap),
...(isWorkflowEnabled
? [
workflowsAllView(objectMetadataMap),
workflowVersionsAllView(objectMetadataMap),
workflowRunsAllView(objectMetadataMap),
]
: []),
];

const viewDefinitionsWithId = viewDefinitions.map((viewDefinition) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ObjectMetadataEntity>,
) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ObjectMetadataEntity>,
) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ObjectMetadataEntity>,
) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ObjectMetadataEntity>,
) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ObjectMetadataEntity>,
) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ObjectMetadataEntity>,
) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ObjectMetadataEntity>,
) => {
return {
Expand Down
Loading
Loading