mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
refactor(base): prune deleted property cells locally instead of invalidating rows
This commit is contained in:
@@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user