mirror of
https://github.com/docmost/docmost.git
synced 2026-08-28 17:27:06 +08:00
feat(base): subscribe to formula WS events on client
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
import { atom } from "jotai";
|
||||||
|
|
||||||
|
export const formulaRecomputeAtom = atom<Record<string, string[]>>({});
|
||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
IBaseView,
|
IBaseView,
|
||||||
} from "@/features/base/types/base.types";
|
} from "@/features/base/types/base.types";
|
||||||
import { selectedRowIdsAtom } from "@/features/base/atoms/base-atoms";
|
import { selectedRowIdsAtom } from "@/features/base/atoms/base-atoms";
|
||||||
|
import { formulaRecomputeAtom } from "@/features/base/atoms/formula-recompute-atom";
|
||||||
import { IPagination } from "@/lib/types";
|
import { IPagination } from "@/lib/types";
|
||||||
|
|
||||||
type BaseRowCreated = {
|
type BaseRowCreated = {
|
||||||
@@ -69,12 +70,39 @@ type BaseViewEvent = {
|
|||||||
viewId?: string;
|
viewId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type BaseRowsUpdated = {
|
||||||
|
operation: "base:rows:updated";
|
||||||
|
baseId: string;
|
||||||
|
rowIds: string[];
|
||||||
|
propertyIds: string[];
|
||||||
|
requestId?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type BaseFormulaRecomputeStarted = {
|
||||||
|
operation: "base:formula:recompute:started";
|
||||||
|
baseId: string;
|
||||||
|
propertyIds: string[];
|
||||||
|
jobId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type BaseFormulaRecomputeCompleted = {
|
||||||
|
operation: "base:formula:recompute:completed";
|
||||||
|
baseId: string;
|
||||||
|
propertyIds: string[];
|
||||||
|
jobId: string;
|
||||||
|
processed: number;
|
||||||
|
errored: number;
|
||||||
|
};
|
||||||
|
|
||||||
type BaseInboundEvent =
|
type BaseInboundEvent =
|
||||||
| BaseRowCreated
|
| BaseRowCreated
|
||||||
| BaseRowUpdated
|
| BaseRowUpdated
|
||||||
| BaseRowDeleted
|
| BaseRowDeleted
|
||||||
| BaseRowsDeleted
|
| BaseRowsDeleted
|
||||||
| BaseRowReordered
|
| BaseRowReordered
|
||||||
|
| BaseRowsUpdated
|
||||||
|
| BaseFormulaRecomputeStarted
|
||||||
|
| BaseFormulaRecomputeCompleted
|
||||||
| BasePropertyEvent
|
| BasePropertyEvent
|
||||||
| BaseViewEvent
|
| BaseViewEvent
|
||||||
| { operation: string; baseId: string };
|
| { operation: string; baseId: string };
|
||||||
@@ -240,6 +268,32 @@ export function useBaseSocket(baseId: string | undefined): void {
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "base:rows:updated": {
|
||||||
|
// Formula recompute wrote new cell values on the server. The event
|
||||||
|
// only carries row IDs, so invalidate the rows query to refetch.
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["base-rows", baseId] });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "base:formula:recompute:started": {
|
||||||
|
const e = event as BaseFormulaRecomputeStarted;
|
||||||
|
const store = getDefaultStore();
|
||||||
|
store.set(formulaRecomputeAtom, {
|
||||||
|
...store.get(formulaRecomputeAtom),
|
||||||
|
[e.jobId]: e.propertyIds,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "base:formula:recompute:completed": {
|
||||||
|
const e = event as BaseFormulaRecomputeCompleted;
|
||||||
|
const store = getDefaultStore();
|
||||||
|
const current = store.get(formulaRecomputeAtom);
|
||||||
|
if (e.jobId in current) {
|
||||||
|
const next = { ...current };
|
||||||
|
delete next[e.jobId];
|
||||||
|
store.set(formulaRecomputeAtom, next);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "base:property:created":
|
case "base:property:created":
|
||||||
case "base:property:updated":
|
case "base:property:updated":
|
||||||
case "base:property:deleted":
|
case "base:property:deleted":
|
||||||
|
|||||||
Reference in New Issue
Block a user