Improve Performances of FE by reducing first print queries (#2623)
This commit is contained in:
@ -3,18 +3,18 @@ import { useRecoilCallback } from 'recoil';
|
||||
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { ViewField } from '@/views/types/ViewField';
|
||||
import { getViewScopedStatesFromSnapshot } from '@/views/utils/getViewScopedStatesFromSnapshot';
|
||||
import { getViewScopedStateValuesFromSnapshot } from '@/views/utils/getViewScopedStateValuesFromSnapshot';
|
||||
|
||||
export const useViewFields = (viewScopeId: string) => {
|
||||
const { updateOneMutation, createOneMutation, findManyQuery } =
|
||||
useObjectMetadataItem({
|
||||
objectNameSingular: 'viewField',
|
||||
});
|
||||
const { updateOneMutation, createOneMutation } = useObjectMetadataItem({
|
||||
objectNameSingular: 'viewField',
|
||||
});
|
||||
|
||||
const apolloClient = useApolloClient();
|
||||
|
||||
const persistViewFields = useRecoilCallback(
|
||||
({ snapshot }) =>
|
||||
({ snapshot, set }) =>
|
||||
async (viewFieldsToPersist: ViewField[], viewId?: string) => {
|
||||
const { viewObjectMetadataId, currentViewId, savedViewFieldsByKey } =
|
||||
getViewScopedStateValuesFromSnapshot({
|
||||
@ -23,6 +23,12 @@ export const useViewFields = (viewScopeId: string) => {
|
||||
viewId,
|
||||
});
|
||||
|
||||
const { isPersistingViewState } = getViewScopedStatesFromSnapshot({
|
||||
snapshot,
|
||||
viewScopeId,
|
||||
viewId,
|
||||
});
|
||||
|
||||
const viewIdToPersist = viewId ?? currentViewId;
|
||||
|
||||
if (!currentViewId || !savedViewFieldsByKey || !viewObjectMetadataId) {
|
||||
@ -47,7 +53,6 @@ export const useViewFields = (viewScopeId: string) => {
|
||||
position: viewField.position,
|
||||
},
|
||||
},
|
||||
refetchQueries: [findManyQuery],
|
||||
}),
|
||||
),
|
||||
);
|
||||
@ -90,17 +95,13 @@ export const useViewFields = (viewScopeId: string) => {
|
||||
.isVisible !== viewFieldToPersit.isVisible),
|
||||
);
|
||||
|
||||
set(isPersistingViewState, true);
|
||||
await _createViewFields(viewFieldsToCreate);
|
||||
|
||||
await _updateViewFields(viewFieldsToUpdate);
|
||||
set(isPersistingViewState, false);
|
||||
},
|
||||
[
|
||||
apolloClient,
|
||||
createOneMutation,
|
||||
findManyQuery,
|
||||
updateOneMutation,
|
||||
viewScopeId,
|
||||
],
|
||||
[apolloClient, createOneMutation, updateOneMutation, viewScopeId],
|
||||
);
|
||||
|
||||
return { persistViewFields };
|
||||
|
||||
@ -11,14 +11,10 @@ import { getViewScopedStateValuesFromSnapshot } from '@/views/utils/getViewScope
|
||||
import { useViewScopedStates } from './useViewScopedStates';
|
||||
|
||||
export const useViewFilters = (viewScopeId: string) => {
|
||||
const {
|
||||
updateOneMutation,
|
||||
createOneMutation,
|
||||
deleteOneMutation,
|
||||
findManyQuery,
|
||||
} = useObjectMetadataItem({
|
||||
objectNameSingular: 'viewFilter',
|
||||
});
|
||||
const { updateOneMutation, createOneMutation, deleteOneMutation } =
|
||||
useObjectMetadataItem({
|
||||
objectNameSingular: 'viewFilter',
|
||||
});
|
||||
const apolloClient = useApolloClient();
|
||||
|
||||
const { currentViewFiltersState } = useViewScopedStates({
|
||||
@ -60,7 +56,6 @@ export const useViewFilters = (viewScopeId: string) => {
|
||||
operand: viewFilter.operand,
|
||||
},
|
||||
},
|
||||
refetchQueries: [findManyQuery],
|
||||
}),
|
||||
),
|
||||
);
|
||||
@ -139,7 +134,6 @@ export const useViewFilters = (viewScopeId: string) => {
|
||||
apolloClient,
|
||||
createOneMutation,
|
||||
deleteOneMutation,
|
||||
findManyQuery,
|
||||
updateOneMutation,
|
||||
viewScopeId,
|
||||
],
|
||||
|
||||
@ -36,6 +36,7 @@ export const useViewScopedStates = (args?: { customViewScopeId?: string }) => {
|
||||
currentViewSortsState,
|
||||
entityCountInCurrentViewState,
|
||||
isViewBarExpandedState,
|
||||
isPersistingViewState,
|
||||
onViewFieldsChangeState,
|
||||
onViewFiltersChangeState,
|
||||
onViewSortsChangeState,
|
||||
@ -67,6 +68,7 @@ export const useViewScopedStates = (args?: { customViewScopeId?: string }) => {
|
||||
currentViewSortsState,
|
||||
entityCountInCurrentViewState,
|
||||
isViewBarExpandedState,
|
||||
isPersistingViewState,
|
||||
onViewFieldsChangeState,
|
||||
onViewFiltersChangeState,
|
||||
onViewSortsChangeState,
|
||||
|
||||
@ -11,14 +11,10 @@ import { getViewScopedStateValuesFromSnapshot } from '@/views/utils/getViewScope
|
||||
import { useViewScopedStates } from './useViewScopedStates';
|
||||
|
||||
export const useViewSorts = (viewScopeId: string) => {
|
||||
const {
|
||||
updateOneMutation,
|
||||
createOneMutation,
|
||||
deleteOneMutation,
|
||||
findManyQuery,
|
||||
} = useObjectMetadataItem({
|
||||
objectNameSingular: 'viewSort',
|
||||
});
|
||||
const { updateOneMutation, createOneMutation, deleteOneMutation } =
|
||||
useObjectMetadataItem({
|
||||
objectNameSingular: 'viewSort',
|
||||
});
|
||||
const apolloClient = useApolloClient();
|
||||
|
||||
const { currentViewSortsState } = useViewScopedStates({
|
||||
@ -59,7 +55,6 @@ export const useViewSorts = (viewScopeId: string) => {
|
||||
direction: viewSort.direction,
|
||||
},
|
||||
},
|
||||
refetchQueries: [findManyQuery],
|
||||
}),
|
||||
),
|
||||
);
|
||||
@ -132,7 +127,6 @@ export const useViewSorts = (viewScopeId: string) => {
|
||||
apolloClient,
|
||||
createOneMutation,
|
||||
deleteOneMutation,
|
||||
findManyQuery,
|
||||
updateOneMutation,
|
||||
viewScopeId,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user