mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-30 23:23:47 +03:00
Fix sort delete (#2312)
This commit is contained in:
parent
1c5c71bc48
commit
8080353075
@ -14,10 +14,14 @@ import { ViewSort } from '@/views/types/ViewSort';
|
|||||||
import { useViewSetStates } from '../useViewSetStates';
|
import { useViewSetStates } from '../useViewSetStates';
|
||||||
|
|
||||||
export const useViewSorts = (viewScopeId: string) => {
|
export const useViewSorts = (viewScopeId: string) => {
|
||||||
const { updateOneMutation, createOneMutation, findManyQuery } =
|
const {
|
||||||
useFindOneObjectMetadataItem({
|
updateOneMutation,
|
||||||
objectNameSingular: 'viewSortV2',
|
createOneMutation,
|
||||||
});
|
deleteOneMutation,
|
||||||
|
findManyQuery,
|
||||||
|
} = useFindOneObjectMetadataItem({
|
||||||
|
objectNameSingular: 'viewSortV2',
|
||||||
|
});
|
||||||
const apolloClient = useApolloClient();
|
const apolloClient = useApolloClient();
|
||||||
const { setCurrentViewSorts } = useViewSetStates(viewScopeId);
|
const { setCurrentViewSorts } = useViewSetStates(viewScopeId);
|
||||||
|
|
||||||
@ -72,7 +76,16 @@ export const useViewSorts = (viewScopeId: string) => {
|
|||||||
const deleteViewSorts = (viewSortIdsToDelete: string[]) => {
|
const deleteViewSorts = (viewSortIdsToDelete: string[]) => {
|
||||||
if (!viewSortIdsToDelete.length) return;
|
if (!viewSortIdsToDelete.length) return;
|
||||||
|
|
||||||
// Todo
|
return Promise.all(
|
||||||
|
viewSortIdsToDelete.map((viewFilterId) =>
|
||||||
|
apolloClient.mutate({
|
||||||
|
mutation: deleteOneMutation,
|
||||||
|
variables: {
|
||||||
|
idToDelete: viewFilterId,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentViewSorts = snapshot
|
const currentViewSorts = snapshot
|
||||||
@ -117,7 +130,10 @@ export const useViewSorts = (viewScopeId: string) => {
|
|||||||
const sortKeysToDelete = Object.keys(savedViewSortsByKey).filter(
|
const sortKeysToDelete = Object.keys(savedViewSortsByKey).filter(
|
||||||
(previousSortKey) => !sortKeys.includes(previousSortKey),
|
(previousSortKey) => !sortKeys.includes(previousSortKey),
|
||||||
);
|
);
|
||||||
await deleteViewSorts(sortKeysToDelete);
|
const sortIdsToDelete = sortKeysToDelete.map(
|
||||||
|
(sortKeyToDelete) => savedViewSortsByKey[sortKeyToDelete].id ?? '',
|
||||||
|
);
|
||||||
|
await deleteViewSorts(sortIdsToDelete);
|
||||||
set(
|
set(
|
||||||
savedViewSortsScopedFamilyState({
|
savedViewSortsScopedFamilyState({
|
||||||
scopeId: viewScopeId,
|
scopeId: viewScopeId,
|
||||||
@ -129,6 +145,7 @@ export const useViewSorts = (viewScopeId: string) => {
|
|||||||
[
|
[
|
||||||
apolloClient,
|
apolloClient,
|
||||||
createOneMutation,
|
createOneMutation,
|
||||||
|
deleteOneMutation,
|
||||||
findManyQuery,
|
findManyQuery,
|
||||||
updateOneMutation,
|
updateOneMutation,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
|
Loading…
Reference in New Issue
Block a user