refactor(base): prune deleted property cells locally instead of invalidating rows

This commit is contained in:
Philipinho
2026-04-18 13:18:51 +01:00
parent 89638fb11d
commit 5ae49cab49
@@ -1,4 +1,4 @@
import { useMutation } from "@tanstack/react-query"; import { InfiniteData, useMutation } from "@tanstack/react-query";
import { import {
createProperty, createProperty,
updateProperty, updateProperty,
@@ -8,6 +8,7 @@ import {
import { import {
IBase, IBase,
IBaseProperty, IBaseProperty,
IBaseRow,
CreatePropertyInput, CreatePropertyInput,
UpdatePropertyInput, UpdatePropertyInput,
DeletePropertyInput, DeletePropertyInput,
@@ -17,6 +18,7 @@ import {
import { notifications } from "@mantine/notifications"; import { notifications } from "@mantine/notifications";
import { queryClient } from "@/main"; import { queryClient } from "@/main";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { IPagination } from "@/lib/types";
export function useCreatePropertyMutation() { export function useCreatePropertyMutation() {
const { t } = useTranslation(); const { t } = useTranslation();
@@ -100,9 +102,23 @@ export function useDeletePropertyMutation() {
}, },
); );
queryClient.invalidateQueries({ queryClient.setQueriesData<InfiniteData<IPagination<IBaseRow>>>(
queryKey: ["base-rows", variables.baseId], { queryKey: ["base-rows", variables.baseId] },
}); (old) => {
if (!old) return old;
return {
...old,
pages: old.pages.map((page) => ({
...page,
items: page.items.map((row) => {
if (!(variables.propertyId in row.cells)) return row;
const { [variables.propertyId]: _, ...rest } = row.cells;
return { ...row, cells: rest };
}),
})),
};
},
);
}, },
onError: () => { onError: () => {
notifications.show({ notifications.show({