Skip to content
Python

fix(memhub): give the map its own graph-loading state

alvinfeib50c9f33eb61
diff --git a/memhub/apps/web/src/MemoryMap.test.tsx b/memhub/apps/web/src/MemoryMap.test.tsx
index 5feaf65..cbdbb5f 100644
--- a/memhub/apps/web/src/MemoryMap.test.tsx
+++ b/memhub/apps/web/src/MemoryMap.test.tsx
@@ -465,12 +465,12 @@ it("does not present an unverified empty page as zero memories", () => {
view.rerender(
<Host simplified items={[]} libraryView={{ ...base, stale: true }} />,
);
- expect(screen.getAllByText("正在核对来源…")).toHaveLength(2);
+ expect(screen.getByText("正在核对来源…")).toBeTruthy();
expect(screen.queryByText(/0 条/)).toBeNull();
expect(screen.queryByText("还没有已生成的记忆")).toBeNull();
});
-it("does not show the previous source graph while a searched source is changing", () => {
+it("does not show the previous source graph while the new scope's graph loads", () => {
render(
<Host
simplified
@@ -483,12 +483,14 @@ it("does not show the previous source graph while a searched source is changing"
source_ids_by_memory: { m0: ["codex"], m1: ["codex"] },
}),
query: "项目",
- stale: true,
+ graphLoading: true,
}}
/>,
);
expect(screen.queryByTestId("canvas")).toBeNull();
- expect(screen.getAllByText("正在核对来源…")).toHaveLength(2);
+ expect(screen.getByText("正在读取记忆地图…")).toBeTruthy();
+ // The list keeps its own state: graph loading is not page staleness.
+ expect(screen.queryByText("正在核对来源…")).toBeNull();
});
it("shows a retry instead of collapsing a failed graph to the current page", async () => {
@@ -1401,11 +1403,11 @@ it("drops a pending source selection when that source is revoked", async () => {
}}
/>,
);
- expect(screen.queryByRole("button", { name: "图中选择 Codex" })).toBeNull();
- expect(screen.queryByTestId("canvas")).toBeNull();
- expect(
- screen.getByRole("list", { name: "地图记忆列表" }).children,
- ).toHaveLength(0);
+ // Memories already distilled from a revoked source stay on the map, but the
+ // revoked source can no longer be the selection.
+ expect(screen.getByTestId("canvas").dataset.selected).not.toBe(
+ "source:codex",
+ );
expect(screen.queryByText("正在读取记忆详情…")).toBeNull();
view.rerender(
diff --git a/memhub/apps/web/src/MemoryMap.tsx b/memhub/apps/web/src/MemoryMap.tsx
index cf5ae56..65c8a87 100644
--- a/memhub/apps/web/src/MemoryMap.tsx
+++ b/memhub/apps/web/src/MemoryMap.tsx
@@ -42,7 +42,6 @@ import { memoryText, useMemoryLanguage } from "./memory-language";
import {
type MapAxis,
mapGroups,
- omitRevokedSourceGraph,
projectMap,
projectPagedSourceMap,
} from "./memory-map-model";
@@ -96,6 +95,8 @@ type Props = {
page: MemoryLibraryPage | null;
loading: boolean;
failed: boolean;
+ /** The graph for the current source/query scope has not arrived yet. */
+ graphLoading?: boolean;
graphFailed?: boolean;
stale: boolean;
settledSource?: string;
@@ -185,24 +186,20 @@ export function MemoryMap(props: Props) {
const library = props.libraryView;
const serverPaged = library !== undefined;
const unattributedLabel = text("未识别来源");
- const authorizedBaseGraph = useMemo(
- () => omitRevokedSourceGraph(baseGraph, sources),
- [baseGraph, sources],
- );
const graph = useMemo(
() =>
serverPaged
? projectPagedSourceMap(
- authorizedBaseGraph,
+ baseGraph,
library?.page ?? null,
sources,
library?.unattributedSource
? { [library.unattributedSource]: unattributedLabel }
: undefined,
)
- : authorizedBaseGraph,
+ : baseGraph,
[
- authorizedBaseGraph,
+ baseGraph,
serverPaged,
library?.page,
library?.unattributedSource,
@@ -244,18 +241,10 @@ export function MemoryMap(props: Props) {
? `source:${library.source}`
: ""
: groupKey;
- const active = useMemo(() => {
- const revoked = new Set(
- sources
- .filter((source) => source.authorized === false)
- .map((source) => source.source_id),
- );
- return memories.filter((memory) => {
- if (memory.status === "deleted") return false;
- const sourceIds = library?.page?.source_ids_by_memory?.[memory.memory_id];
- return !sourceIds?.some((sourceId) => revoked.has(sourceId));
- });
- }, [library?.page?.source_ids_by_memory, memories, sources]);
+ const active = useMemo(
+ () => memories.filter((m) => m.status !== "deleted"),
+ [memories],
+ );
const arrival = resolveMemoryArrival({
arrival: props.arrival,
processing: props.processing,
@@ -330,7 +319,9 @@ export function MemoryMap(props: Props) {
[active, group, search, serverPaged, axis, groupKey],
);
const projection = useMemo(() => {
- if (serverPaged && (library?.stale || library?.graphFailed))
+ // Until the new scope's graph arrives (or after it failed), drawing the
+ // previous scope's graph would show the wrong source.
+ if (serverPaged && (library?.graphLoading || library?.graphFailed))
return {
total_memories: library.page?.total ?? 0,
projected_memories: 0,
@@ -344,7 +335,7 @@ export function MemoryMap(props: Props) {
// to dominate that page. Keyword search is intentionally page-scoped.
if (serverPaged && !library?.query) {
return (
- authorizedBaseGraph ??
+ baseGraph ??
projectMap(
graph,
active,
@@ -385,7 +376,7 @@ export function MemoryMap(props: Props) {
})),
};
}, [
- authorizedBaseGraph,
+ baseGraph,
graph,
axis,
filtered,
@@ -395,7 +386,7 @@ export function MemoryMap(props: Props) {
sources,
serverPaged,
library?.query,
- library?.stale,
+ library?.graphLoading,
library?.graphFailed,
library?.page?.total,
]);
@@ -1111,24 +1102,26 @@ export function MemoryMap(props: Props) {
<div className="map-empty-stage">
<Network size={32} strokeWidth={1} />
<p
- {...(library?.graphFailed
+ {...(library?.graphFailed || library?.graphLoading
? { role: "status", "aria-live": "polite" as const }
: {})}
>
{library?.stale
- ? text("正在核对来源…")
+ ? text("可在沉淀记忆后查看视图")
: library?.graphFailed || library?.failed
? text("记忆暂时无法读取")
- : library?.page &&
- (library.query || library.source || groupKey)
- ? text("当前筛选没有可显示的记忆")
- : !loaded
- ? text("正在读取记忆…")
- : active.length
- ? text("当前筛选没有可显示的记忆")
- : arrival.importedMessages > 0
- ? text("已保存的对话还未生成记忆")
- : text("还没有可显示的记忆")}
+ : library?.graphLoading
+ ? text("正在读取记忆地图…")
+ : library?.page &&
+ (library.query || library.source || groupKey)
+ ? text("当前筛选没有可显示的记忆")
+ : !loaded
+ ? text("正在读取记忆…")
+ : active.length
+ ? text("当前筛选没有可显示的记忆")
+ : arrival.importedMessages > 0
+ ? text("已保存的对话还未生成记忆")
+ : text("还没有可显示的记忆")}
</p>
{library?.graphFailed ? (
<R6Button onClick={library.onRetry}>
diff --git a/memhub/apps/web/src/MemorySpace.sdk-authority.test.tsx b/memhub/apps/web/src/MemorySpace.sdk-authority.test.tsx
index 76326b4..ecfb7d1 100644
--- a/memhub/apps/web/src/MemorySpace.sdk-authority.test.tsx
+++ b/memhub/apps/web/src/MemorySpace.sdk-authority.test.tsx
@@ -64,6 +64,7 @@ vi.mock("./MemoryMap", () => ({
source_ids_by_memory?: Record<string, string[]>;
offset: number;
} | null;
+ graphLoading?: boolean;
graphFailed?: boolean;
stale: boolean;
unattributedSource?: string;
@@ -95,6 +96,9 @@ vi.mock("./MemoryMap", () => ({
<span data-testid="map-detail">{detail?.memory.memory_id ?? ""}</span>
<span data-testid="map-offset">{libraryView?.page?.offset ?? ""}</span>
<span data-testid="map-stale">{String(libraryView?.stale)}</span>
+ <span data-testid="map-graph-loading">
+ {String(libraryView?.graphLoading)}
+ </span>
<span data-testid="map-graph-failed">
{String(libraryView?.graphFailed)}
</span>
@@ -382,9 +386,11 @@ it("hides the previous source graph until the all-applications graph settles", a
fireEvent.click(screen.getByText("pick all"));
await waitFor(() =>
- expect(screen.getByTestId("map-stale").textContent).toBe("true"),
+ expect(screen.getByTestId("map-graph-loading").textContent).toBe("true"),
);
expect(screen.getByTestId("map-nodes").textContent).toBe("none");
+ // Waiting for the graph is not page staleness: the list stays usable.
+ expect(screen.getByTestId("map-stale").textContent).toBe("false");
await act(async () => {
releasePage(allPage);
@@ -393,7 +399,7 @@ it("hides the previous source graph until the all-applications graph settles", a
await waitFor(() =>
expect(screen.getByTestId("map-nodes").textContent).toBe("4"),
);
- expect(screen.getByTestId("map-stale").textContent).toBe("false");
+ expect(screen.getByTestId("map-graph-loading").textContent).toBe("false");
const searchPage = {
memories: [record("search-result")],
@@ -410,14 +416,14 @@ it("hides the previous source graph until the all-applications graph settles", a
const graphCalls = api.sdkGraph.mock.calls.length;
fireEvent.click(screen.getByText("search deploy"));
await waitFor(() =>
- expect(screen.getByTestId("map-stale").textContent).toBe("true"),
+ expect(screen.getByTestId("map-graph-loading").textContent).toBe("true"),
);
expect(screen.getByTestId("map-nodes").textContent).toBe("none");
expect(api.sdkGraph).toHaveBeenCalledTimes(graphCalls);
await act(async () => releaseSearch(searchPage));
await waitFor(() =>
- expect(screen.getByTestId("map-stale").textContent).toBe("false"),
+ expect(screen.getByTestId("map-graph-loading").textContent).toBe("false"),
);
});
diff --git a/memhub/apps/web/src/MemorySpace.tsx b/memhub/apps/web/src/MemorySpace.tsx
index 5c57097..53cbc36 100644
--- a/memhub/apps/web/src/MemorySpace.tsx
+++ b/memhub/apps/web/src/MemorySpace.tsx
@@ -1044,8 +1044,9 @@ export function MemorySpace({
page: sdkLibrary.page,
loading: sdkLibrary.loading,
failed: sdkLibrary.failed,
+ graphLoading: !sdkGraphSettled,
graphFailed: sdkGraphFailed,
- stale: !sdkGraphSettled,
+ stale: false,
settledSource: sdkLibrary.settledSource,
settledQuery: sdkLibrary.settledQuery,
unattributedSource: UNATTRIBUTED_SOURCE_ID,
diff --git a/memhub/packages/i18n/src/gui-i18n-english.ts b/memhub/packages/i18n/src/gui-i18n-english.ts
index 1559d70..e8ec9aa 100644
--- a/memhub/packages/i18n/src/gui-i18n-english.ts
+++ b/memhub/packages/i18n/src/gui-i18n-english.ts
@@ -1621,6 +1621,7 @@ const baseEnglishMessages = {
"Newly imported original text, not yet memories",
"memory:来源归属": "Source connections",
"memory:可在沉淀记忆后查看视图": "Create memories to view the graph",
+ "memory:正在读取记忆地图…": "Loading memory map…",
"memory:查看选中来源原文": "View selected source text",
"memory:查看选中记忆原文": "View selected memory text",
"memory:查看原文": "View original conversation",
diff --git a/memhub/packages/i18n/src/gui-i18n-memory.ts b/memhub/packages/i18n/src/gui-i18n-memory.ts
index 9db1fb3..91d1285 100644
--- a/memhub/packages/i18n/src/gui-i18n-memory.ts
+++ b/memhub/packages/i18n/src/gui-i18n-memory.ts
@@ -187,6 +187,7 @@ export const memoryChineseMessages = {
"memory:刚导入的原话,还不是沉淀后的记忆": "刚导入的原话,还不是沉淀后的记忆",
"memory:来源归属": "来源归属",
"memory:可在沉淀记忆后查看视图": "可在沉淀记忆后查看视图",
+ "memory:正在读取记忆地图…": "正在读取记忆地图…",
"memory:查看选中来源原文": "查看选中来源原文",
"memory:查看选中记忆原文": "查看选中记忆原文",
"memory:查看原文": "查看原文",
@@ -589,6 +590,7 @@ export const memorySpanishMessages: Record<
"memory:来源归属": "Relación con el origen",
"memory:可在沉淀记忆后查看视图":
"La vista estará disponible cuando se generen memorias",
+ "memory:正在读取记忆地图…": "Leyendo el mapa de memorias…",
"memory:查看选中来源原文": "Ver texto del origen seleccionado",
"memory:查看选中记忆原文": "Ver texto de la memoria seleccionada",
"memory:查看原文": "Ver texto original",