mirror of
https://github.com/docmost/docmost.git
synced 2026-08-29 10:05:03 +08:00
fix formula
This commit is contained in:
@@ -234,7 +234,15 @@ export function CreatePropertyPopover({ baseId, properties, onPropertyCreated }:
|
|||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
{panel === "configure" && selectedType === "formula" && (
|
{panel === "configure" && selectedType === "formula" && (
|
||||||
<Stack gap={0} p="sm">
|
<Stack gap="xs" p="sm">
|
||||||
|
<TextInput
|
||||||
|
ref={nameInputRef}
|
||||||
|
size="xs"
|
||||||
|
label={t("Name")}
|
||||||
|
placeholder={selectedTypeLabel}
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.currentTarget.value)}
|
||||||
|
/>
|
||||||
<FormulaEditor
|
<FormulaEditor
|
||||||
properties={properties ?? []}
|
properties={properties ?? []}
|
||||||
editingPropertyId={null}
|
editingPropertyId={null}
|
||||||
|
|||||||
@@ -269,9 +269,31 @@ export function useBaseSocket(baseId: string | undefined): void {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "base:rows:updated": {
|
case "base:rows:updated": {
|
||||||
// Formula recompute wrote new cell values on the server. The event
|
const e = event as BaseRowsUpdated;
|
||||||
// only carries row IDs, so invalidate the rows query to refetch.
|
// Only refetch if the batch touches rows currently in cache.
|
||||||
queryClient.invalidateQueries({ queryKey: ["base-rows", baseId] });
|
// Uncached pages will fetch fresh when the user scrolls to them,
|
||||||
|
// so invalidating on batches the user can't see is wasted work —
|
||||||
|
// formula backfills on a large base emit one batch event per 500
|
||||||
|
// rows, so this also drops ~Nrows/500 redundant refetches.
|
||||||
|
const updatedIds = new Set(e.rowIds);
|
||||||
|
const caches = queryClient.getQueriesData<
|
||||||
|
InfiniteData<IPagination<IBaseRow>>
|
||||||
|
>({ queryKey: ["base-rows", baseId] });
|
||||||
|
let touchesCache = false;
|
||||||
|
outer: for (const [, data] of caches) {
|
||||||
|
if (!data) continue;
|
||||||
|
for (const page of data.pages) {
|
||||||
|
for (const row of page.items) {
|
||||||
|
if (updatedIds.has(row.id)) {
|
||||||
|
touchesCache = true;
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (touchesCache) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["base-rows", baseId] });
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "base:formula:recompute:started": {
|
case "base:formula:recompute:started": {
|
||||||
|
|||||||
@@ -64,7 +64,14 @@ export function useViewDraft(args: UseViewDraftArgs): ViewDraftState {
|
|||||||
(next: FilterGroup | undefined) => {
|
(next: FilterGroup | undefined) => {
|
||||||
if (!ready) return;
|
if (!ready) return;
|
||||||
const current = storedDraft ?? null;
|
const current = storedDraft ?? null;
|
||||||
const mergedFilter = next;
|
// If the baseline has a filter, clearing to `undefined` would fall
|
||||||
|
// back to the baseline in effectiveFilter. Persist an empty AND-group
|
||||||
|
// instead so the draft explicitly overrides the baseline with no
|
||||||
|
// predicates.
|
||||||
|
const mergedFilter =
|
||||||
|
next === undefined && baselineFilter !== undefined
|
||||||
|
? ({ op: "and", children: [] } as FilterGroup)
|
||||||
|
: next;
|
||||||
const mergedSorts = current?.sorts;
|
const mergedSorts = current?.sorts;
|
||||||
if (mergedFilter === undefined && (mergedSorts === undefined || mergedSorts === null)) {
|
if (mergedFilter === undefined && (mergedSorts === undefined || mergedSorts === null)) {
|
||||||
setDraft(RESET);
|
setDraft(RESET);
|
||||||
@@ -76,7 +83,7 @@ export function useViewDraft(args: UseViewDraftArgs): ViewDraftState {
|
|||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[ready, storedDraft, setDraft],
|
[ready, storedDraft, setDraft, baselineFilter],
|
||||||
);
|
);
|
||||||
|
|
||||||
const setSorts = useCallback(
|
const setSorts = useCallback(
|
||||||
|
|||||||
Reference in New Issue
Block a user