Plug filter delete to backend (#2303)
* plug-filter-delete-to-backend * delete console
This commit is contained in:
@ -14,10 +14,14 @@ import { ViewFilter } from '@/views/types/ViewFilter';
|
||||
import { useViewSetStates } from '../useViewSetStates';
|
||||
|
||||
export const useViewFilters = (viewScopeId: string) => {
|
||||
const { updateOneMutation, createOneMutation, findManyQuery } =
|
||||
useFindOneObjectMetadataItem({
|
||||
objectNameSingular: 'viewFilterV2',
|
||||
});
|
||||
const {
|
||||
updateOneMutation,
|
||||
createOneMutation,
|
||||
deleteOneMutation,
|
||||
findManyQuery,
|
||||
} = useFindOneObjectMetadataItem({
|
||||
objectNameSingular: 'viewFilterV2',
|
||||
});
|
||||
const apolloClient = useApolloClient();
|
||||
const { setCurrentViewFilters } = useViewSetStates(viewScopeId);
|
||||
|
||||
@ -76,7 +80,16 @@ export const useViewFilters = (viewScopeId: string) => {
|
||||
const deleteViewFilters = (viewFilterIdsToDelete: string[]) => {
|
||||
if (!viewFilterIdsToDelete.length) return;
|
||||
|
||||
// Todo
|
||||
return Promise.all(
|
||||
viewFilterIdsToDelete.map((viewFilterId) =>
|
||||
apolloClient.mutate({
|
||||
mutation: deleteOneMutation,
|
||||
variables: {
|
||||
idToDelete: viewFilterId,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const currentViewFilters = snapshot
|
||||
@ -121,7 +134,11 @@ export const useViewFilters = (viewScopeId: string) => {
|
||||
const filterKeysToDelete = Object.keys(savedViewFiltersByKey).filter(
|
||||
(previousFilterKey) => !filterKeys.includes(previousFilterKey),
|
||||
);
|
||||
await deleteViewFilters(filterKeysToDelete);
|
||||
const filterIdsToDelete = filterKeysToDelete.map(
|
||||
(filterKeyToDelete) =>
|
||||
savedViewFiltersByKey[filterKeyToDelete].id ?? '',
|
||||
);
|
||||
await deleteViewFilters(filterIdsToDelete);
|
||||
set(
|
||||
savedViewFiltersScopedFamilyState({
|
||||
scopeId: viewScopeId,
|
||||
@ -133,6 +150,7 @@ export const useViewFilters = (viewScopeId: string) => {
|
||||
[
|
||||
apolloClient,
|
||||
createOneMutation,
|
||||
deleteOneMutation,
|
||||
findManyQuery,
|
||||
updateOneMutation,
|
||||
viewScopeId,
|
||||
|
||||
Reference in New Issue
Block a user