Add coreView state in FE (#14034)
Co-authored-by: bosiraphael <raphael.bosi@gmail.com> Co-authored-by: Raphaël Bosi <71827178+bosiraphael@users.noreply.github.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import { usePersistViewFilterGroupRecords } from '@/views/hooks/internal/usePers
|
||||
import { usePersistViewFilterRecords } from '@/views/hooks/internal/usePersistViewFilterRecords';
|
||||
import { usePersistViewGroupRecords } from '@/views/hooks/internal/usePersistViewGroupRecords';
|
||||
import { usePersistViewSortRecords } from '@/views/hooks/internal/usePersistViewSortRecords';
|
||||
import { coreViewsState } from '@/views/states/coreViewState';
|
||||
import { isPersistingViewFieldsState } from '@/views/states/isPersistingViewFieldsState';
|
||||
import { type GraphQLView } from '@/views/types/GraphQLView';
|
||||
import { type View } from '@/views/types/View';
|
||||
@@ -32,7 +33,12 @@ import { useFeatureFlagsMap } from '@/workspace/hooks/useFeatureFlagsMap';
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { v4 } from 'uuid';
|
||||
import { FeatureFlagKey, useCreateCoreViewMutation } from '~/generated/graphql';
|
||||
import {
|
||||
FeatureFlagKey,
|
||||
useCreateCoreViewMutation,
|
||||
useFindManyCoreViewsLazyQuery,
|
||||
} from '~/generated/graphql';
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
|
||||
export const useCreateViewFromCurrentView = (viewBarComponentId?: string) => {
|
||||
@@ -64,6 +70,8 @@ export const useCreateViewFromCurrentView = (viewBarComponentId?: string) => {
|
||||
|
||||
const { objectMetadataItem } = useRecordIndexContextOrThrow();
|
||||
|
||||
const [findManyCoreViewsLazy] = useFindManyCoreViewsLazyQuery();
|
||||
|
||||
const { findManyRecordsLazy } = useLazyFindManyRecords({
|
||||
objectNameSingular: CoreObjectNameSingular.View,
|
||||
fetchPolicy: 'network-only',
|
||||
@@ -249,7 +257,28 @@ export const useCreateViewFromCurrentView = (viewBarComponentId?: string) => {
|
||||
await createViewSortRecords(viewSortsToCreate, { id: newViewId });
|
||||
}
|
||||
|
||||
await findManyRecordsLazy();
|
||||
if (isCoreViewEnabled) {
|
||||
const result = await findManyCoreViewsLazy({
|
||||
variables: {
|
||||
objectMetadataId: objectMetadataItem.id,
|
||||
},
|
||||
fetchPolicy: 'network-only',
|
||||
});
|
||||
|
||||
const existingCoreViews = snapshot
|
||||
.getLoadable(coreViewsState)
|
||||
.getValue();
|
||||
|
||||
if (
|
||||
isDefined(result.data?.getCoreViews) &&
|
||||
!isDeeplyEqual(existingCoreViews, result.data.getCoreViews)
|
||||
) {
|
||||
set(coreViewsState, result.data.getCoreViews);
|
||||
}
|
||||
} else {
|
||||
await findManyRecordsLazy();
|
||||
}
|
||||
|
||||
set(isPersistingViewFieldsState, false);
|
||||
return newViewId;
|
||||
},
|
||||
@@ -269,6 +298,8 @@ export const useCreateViewFromCurrentView = (viewBarComponentId?: string) => {
|
||||
currentRecordFilterGroups,
|
||||
isCoreViewEnabled,
|
||||
createCoreViewMutation,
|
||||
findManyCoreViewsLazy,
|
||||
objectMetadataItem.id,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user