Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8591: refactor(views): one shared rule for client filter dependencies (#9926)

Jiayuan Zhangdd42d0331f89
diff --git a/packages/core/issues/surface/filter-dependency.test.ts b/packages/core/issues/surface/filter-dependency.test.ts
new file mode 100644
index 0000000000..64f82f4818
--- /dev/null
+++ b/packages/core/issues/surface/filter-dependency.test.ts
@@ -0,0 +1,93 @@
+// @vitest-environment node
+import { describe, expect, it, vi } from "vitest";
+import { buildIssueStatusCatalog } from "../../issue-statuses/queries";
+import {
+ combineFilterDependencies,
+ filterDependencyState,
+ statusCatalogSource,
+ type FilterDependencySource,
+} from "./filter-dependency";
+
+function source(overrides: Partial<FilterDependencySource> = {}): FilterDependencySource {
+ return { data: undefined, isError: false, refetch: vi.fn(), ...overrides };
+}
+
+const loaded = () => source({ data: [] });
+const pending = () => source();
+const failed = () => source({ isError: true });
+
+describe("filterDependencyState", () => {
+ it("is resolved when the filter is off, whatever its sources say", () => {
+ expect(filterDependencyState(false, [pending(), failed()])).toMatchObject({
+ pending: false,
+ error: false,
+ unresolved: false,
+ });
+ });
+
+ it("waits while a source has no data", () => {
+ expect(filterDependencyState(true, [loaded(), pending()])).toMatchObject({
+ pending: true,
+ error: false,
+ unresolved: true,
+ });
+ });
+
+ it("treats an empty answer as resolved, not as missing", () => {
+ expect(filterDependencyState(true, [source({ data: [] })]).unresolved).toBe(false);
+ });
+
+ it("reports an error once any source fails, even while another is pending", () => {
+ expect(filterDependencyState(true, [pending(), failed()])).toMatchObject({
+ pending: false,
+ error: true,
+ unresolved: true,
+ });
+ });
+
+ it("keeps answering from data kept behind a failed refetch", () => {
+ expect(filterDependencyState(true, [source({ data: ["a"], isError: true })]).unresolved).toBe(false);
+ });
+
+ it("ignores sources the active filter does not read", () => {
+ expect(filterDependencyState(true, [false, loaded()]).unresolved).toBe(false);
+ expect(filterDependencyState(true, [false, pending()]).pending).toBe(true);
+ });
+
+ it("retries only the sources that failed", () => {
+ const ok = loaded();
+ const waiting = pending();
+ const broken = failed();
+ filterDependencyState(true, [ok, waiting, broken]).retry();
+ expect(broken.refetch).toHaveBeenCalledTimes(1);
+ expect(waiting.refetch).not.toHaveBeenCalled();
+ expect(ok.refetch).not.toHaveBeenCalled();
+ });
+});
+
+describe("combineFilterDependencies", () => {
+ it("waits while any part is pending, and fails once any part failed", () => {
+ const waiting = filterDependencyState(true, [pending()]);
+ const resolved = filterDependencyState(true, [loaded()]);
+ expect(combineFilterDependencies(resolved, waiting)).toMatchObject({ pending: true, error: false });
+ expect(combineFilterDependencies(resolved, resolved).unresolved).toBe(false);
+
+ const broken = failed();
+ const combined = combineFilterDependencies(waiting, filterDependencyState(true, [broken]));
+ expect(combined).toMatchObject({ pending: false, error: true, unresolved: true });
+ combined.retry();
+ expect(broken.refetch).toHaveBeenCalledTimes(1);
+ });
+});
+
+describe("statusCatalogSource", () => {
+ it("has data only once the catalog loaded, and retries through the catalog", () => {
+ const retry = vi.fn();
+ expect(statusCatalogSource(buildIssueStatusCatalog(undefined, { isPending: true })).data).toBeUndefined();
+ expect(statusCatalogSource(buildIssueStatusCatalog([])).data).toEqual([]);
+ const failedCatalog = statusCatalogSource(buildIssueStatusCatalog(undefined, { isError: true, retry }));
+ expect(failedCatalog.isError).toBe(true);
+ filterDependencyState(true, [failedCatalog]).retry();
+ expect(retry).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/packages/core/issues/surface/filter-dependency.ts b/packages/core/issues/surface/filter-dependency.ts
new file mode 100644
index 0000000000..ff30414c28
--- /dev/null
+++ b/packages/core/issues/surface/filter-dependency.ts
@@ -0,0 +1,102 @@
+import type { IssueStatusCatalog } from "../../issue-statuses/queries";
+
+/**
+ * Data a filter needs besides the rows themselves: the viewer's subscriptions,
+ * agents or unread list, the running-task projection, the project list, the
+ * status catalog. A TanStack Query result fits as is.
+ */
+export interface FilterDependencySource {
+ /** `undefined` until the data arrives. Data kept behind a failed refetch has
+ * arrived: the filter keeps answering from it. */
+ data: unknown;
+ isError: boolean;
+ refetch: () => unknown;
+}
+
+export interface FilterDependencyState {
+ /** Hold the loading state. */
+ pending: boolean;
+ /** Show a retryable error. */
+ error: boolean;
+ /** `pending || error`: the filter has no answer yet. Gate every fetch keyed
+ * by it and every "no results" claim on this. */
+ unresolved: boolean;
+ /** Re-runs each source that failed. */
+ retry: () => void;
+}
+
+export const RESOLVED_FILTER_DEPENDENCY: FilterDependencyState = {
+ pending: false,
+ error: false,
+ unresolved: false,
+ retry: () => {},
+};
+
+/**
+ * Whether a filter that reads `sources` can be evaluated.
+ *
+ * Until every source an active filter reads has data, the filter has no
+ * answer: it is pending, or an error once a source has failed. It is never
+ * "no filter" (unfiltered rows under an active chip) and never "matches
+ * nothing" (an empty list, or a loading state that never ends).
+ *
+ * `active` is whether this surface applies the filter at all; a `false` entry
+ * in `sources` is a source the active filter does not read, so one value of a
+ * dimension does not wait on another value's data.
+ *
+ * Adding a filter dimension that reads extra data means declaring its sources
+ * here and gating on `unresolved`, plus three controller regressions: loading
+ * while a source is pending, a retryable error when it fails, and correctly
+ * filtered rows after a successful retry. A source backed by a new endpoint
+ * must reject on a malformed response rather than resolve to an empty list
+ * (see `listSubscribedIssueIds`): an empty list is an answer, and the filter
+ * would apply it.
+ */
+export function filterDependencyState(
+ active: boolean,
+ sources: readonly (FilterDependencySource | false)[],
+): FilterDependencyState {
+ if (!active) return RESOLVED_FILTER_DEPENDENCY;
+ const unresolved = sources.filter(
+ (source): source is FilterDependencySource => source !== false && source.data === undefined,
+ );
+ if (unresolved.length === 0) return RESOLVED_FILTER_DEPENDENCY;
+ const failed = unresolved.filter((source) => source.isError);
+ return {
+ pending: failed.length === 0,
+ error: failed.length > 0,
+ unresolved: true,
+ retry: () => {
+ for (const source of failed) void source.refetch();
+ },
+ };
+}
+
+/** Several dependencies behind one loading state and one retry. A failure
+ * anywhere wins over pending elsewhere, and retry re-runs every failure. */
+export function combineFilterDependencies(
+ ...states: readonly FilterDependencyState[]
+): FilterDependencyState {
+ const failed = states.filter((state) => state.error);
+ const unresolved = states.some((state) => state.unresolved);
+ if (!unresolved) return RESOLVED_FILTER_DEPENDENCY;
+ return {
+ pending: failed.length === 0,
+ error: failed.length > 0,
+ unresolved: true,
+ retry: () => {
+ for (const state of failed) state.retry();
+ },
+ };
+}
+
+/** The status catalog as a filter dependency. */
+export function statusCatalogSource(
+ catalog: Pick<IssueStatusCatalog, "isLoaded" | "statuses" | "isError" | "retry">,
+): FilterDependencySource {
+ return {
+ data: catalog.isLoaded ? catalog.statuses : undefined,
+ isError: catalog.isError,
+ refetch: catalog.retry,
+ };
+}
diff --git a/packages/core/issues/unread.ts b/packages/core/issues/unread.ts
index 5c38113464..d092377c1a 100644
--- a/packages/core/issues/unread.ts
+++ b/packages/core/issues/unread.ts
@@ -51,16 +51,17 @@ export function useIssueUnread(wsId: string, issueId: string): IssueUnread | nul
const selectUnreadIssueIds = (items: IssueUnread[]) => items.map((item) => item.issue_id);
-/** The ids of the viewer's unread issues. `ids` stays `undefined` until the
- * list loads (or while `enabled` is false); `isError` means it failed with
- * nothing cached and no retry in flight. */
+/** The ids of the viewer's unread issues, shaped as a `FilterDependencySource`.
+ * `data` stays `undefined` until the list loads (or while `enabled` is
+ * false); `isError` means it failed with nothing cached and no retry in
+ * flight. */
export function useIssueUnreadIds(wsId: string, enabled = true) {
const { data, isError, isFetching, refetch } = useQuery({
...issueUnreadOptions(wsId),
select: selectUnreadIssueIds,
enabled: enabled && !!wsId,
});
- return { ids: data, isError: isError && !isFetching && data === undefined, refetch };
+ return { data, isError: isError && !isFetching && data === undefined, refetch };
}
function useSetIssueUnread(wsId: string, unread: boolean) {
diff --git a/packages/views/issues/surface/issue-surface.tsx b/packages/views/issues/surface/issue-surface.tsx
index a2cc6ab1f4..ef73eab4c3 100644
--- a/packages/views/issues/surface/issue-surface.tsx
+++ b/packages/views/issues/surface/issue-surface.tsx
@@ -53,6 +53,7 @@ import { ColumnStatusesProvider } from "./column-statuses-context";
import type { IssueCreateDefaults, IssueSurfaceProps } from "./types";
import {
useIssueSurfaceController,
+ type FilterDependencyKind,
type IssueSurfaceController,
} from "./use-issue-surface-controller";
@@ -286,18 +287,15 @@ function IssueSurfaceContent({
loading and empty states too, so a view switch that briefly shows
a skeleton keeps the peek open. */}
<IssuePeekHost>
- {/* A failed status catalog precedes loading/empty/content on purpose.
- Row fetching is suspended while it is down (a custom status filter
- cannot be routed without it), so every branch below would render an
- unexplained empty surface with no way out. (MUL-6243) */}
- {controller.isStatusCatalogError ? (
- <FilterDependencyErrorState kind="status" onRetry={controller.retryStatusCatalog} />
- ) : controller.isWorkingFilterError ? (
- <FilterDependencyErrorState kind="working" onRetry={controller.retryWorkingFilter} />
- ) : controller.isUnreadFilterError ? (
- <FilterDependencyErrorState kind="unread" onRetry={controller.retryUnreadFilter} />
- ) : controller.isRelationFilterError ? (
- <FilterDependencyErrorState kind="relation" onRetry={controller.retryRelationFilter} />
+ {/* A failed filter dependency precedes loading/empty/content on
+ purpose. Row fetching is suspended while it is down, so every
+ branch below would render an unexplained empty surface with no way
+ out. */}
+ {controller.filterDependencyError ? (
+ <FilterDependencyErrorState
+ kind={controller.filterDependencyError.kind}
+ onRetry={controller.filterDependencyError.retry}
+ />
) : controller.isLoading ? (
renderLoading ? (
renderLoading(renderContext)
@@ -424,7 +422,7 @@ function FilterDependencyErrorState({
kind,
onRetry,
}: {
- kind: "status" | "working" | "unread" | "relation";
+ kind: FilterDependencyKind;
onRetry: () => void;
}) {
const { t } = useT("issues");
diff --git a/packages/views/issues/surface/use-issue-surface-catalog.test.tsx b/packages/views/issues/surface/use-issue-surface-catalog.test.tsx
index d1b5b2b15d..53ece0df92 100644
--- a/packages/views/issues/surface/use-issue-surface-catalog.test.tsx
+++ b/packages/views/issues/surface/use-issue-surface-catalog.test.tsx
@@ -12,7 +12,12 @@ import {
pruneIssueSurfaceViewStates,
} from "@multica/core/issues/stores/surface-view-store";
import { ViewStoreProvider } from "@multica/core/issues/stores/view-store-context";
-import type { IssueStatusEntry, IssueTableGroupsRequest, IssueTableRowsRequest } from "@multica/core/types";
+import type {
+ Issue,
+ IssueStatusEntry,
+ IssueTableGroupsRequest,
+ IssueTableRowsRequest,
+} from "@multica/core/types";
import { useIssueSurfaceController } from "./use-issue-surface-controller";
/**
@@ -62,6 +67,7 @@ let rowRequests: IssueTableRowsRequest[] = [];
function installApi(
listIssueStatuses: () => Promise<unknown>,
listProjects: () => Promise<unknown> = async () => ({ projects: [], total: 0 }),
+ listIssues: () => Promise<unknown> = async () => ({ issues: [], total: 0 }),
) {
groupRequests = [];
rowRequests = [];
@@ -85,7 +91,7 @@ function installApi(
};
},
listIssueTableFacets: async () => ({ query_fingerprint: "test", total: 0, facets: [] }),
- listIssues: async () => ({ issues: [], total: 0 }),
+ listIssues,
getWorkspaceWorkingAgents: async () => [],
getChildIssueProgress: async () => ({ progress: [] }),
getAgentTaskSnapshot: async () => ({ tasks: [] }),
@@ -153,8 +159,11 @@ describe("useIssueSurfaceController — custom status filter vs a late catalog",
});
it("surfaces a retryable error instead of a silent empty board when the catalog fails", async () => {
- const catalog = deferred<never>();
- installApi(() => catalog.promise);
+ const listIssueStatuses = vi
+ .fn()
+ .mockRejectedValueOnce(new Error("catalog unavailable"))
+ .mockResolvedValue({ statuses: [QA_ENTRY], categories: [], total: 1 });
+ installApi(listIssueStatuses);
const { store, Wrapper } = makeWrapper(qc, "workspace:catalog-failed");
act(() => store.getState().toggleStatusFilter("qa"));
@@ -167,14 +176,18 @@ describe("useIssueSurfaceController — custom status filter vs a late catalog",
{ wrapper: Wrapper },
);
- await act(async () => {
- catalog.reject(new Error("catalog unavailable"));
- await catalog.promise.catch(() => {});
- });
-
- await waitFor(() => expect(result.current.isStatusCatalogError).toBe(true));
+ await waitFor(() => expect(result.current.filterDependencyError?.kind).toBe("status"));
// Not "no issues" — the surface cannot answer the question that was asked.
expect(result.current.isEmpty).toBe(false);
+ expect(rowRequests).toEqual([]);
+
+ act(() => result.current.filterDependencyError!.retry());
+ await waitFor(() => expect(result.current.filterDependencyError).toBeNull());
+ await waitFor(() => expect(result.current.visibleStatuses).toEqual(["qa"]));
+ await waitFor(() => expect(rowRequests.length).toBeGreaterThan(0));
+ for (const request of rowRequests) {
+ expect(request.query.filters.statuses).toEqual(["qa"]);
+ }
});
});
@@ -223,10 +236,106 @@ describe("useIssueSurfaceController — project-status filter vs a late catalog"
await projects.promise.catch(() => {});
});
- await waitFor(() => expect(result.current.isStatusCatalogError).toBe(true));
+ await waitFor(() => expect(result.current.filterDependencyError?.kind).toBe("status"));
expect(result.current.isEmpty).toBe(false);
});
+ describe("on a project Gantt", () => {
+ const row = (id: string, projectId: string) =>
+ ({
+ id,
+ workspace_id: "ws-1",
+ number: 1,
+ identifier: id,
+ title: id,
+ description: null,
+ status: "todo",
+ priority: "none",
+ assignee_type: null,
+ assignee_id: null,
+ creator_type: "member",
+ creator_id: "user-1",
+ parent_issue_id: null,
+ project_id: projectId,
+ position: 1,
+ stage: null,
+ start_date: "2026-01-01",
+ due_date: "2026-01-05",
+ metadata: {},
+ properties: {},
+ created_at: "2026-01-01T00:00:00Z",
+ updated_at: "2026-01-01T00:00:00Z",
+ }) as Issue;
+ const ROWS = [row("active-row", "p-active"), row("paused-row", "p-paused")];
+ const PROJECTS = {
+ projects: [
+ { id: "p-active", status: "in_progress" },
+ { id: "p-paused", status: "paused" },
+ ],
+ total: 2,
+ };
+
+ function renderProjectGantt(surfaceKey: string, listProjects: () => Promise<unknown>) {
+ installApi(
+ async () => ({ statuses: [], categories: [], total: 0 }),
+ listProjects,
+ async () => ({ issues: ROWS, total: ROWS.length }),
+ );
+ const { store, Wrapper } = makeWrapper(qc, surfaceKey);
+ act(() => {
+ store.getState().setViewMode("gantt");
+ store.getState().toggleProjectStatusFilter("in_progress");
+ });
+ return renderHook(
+ () =>
+ useIssueSurfaceController({
+ scope: { type: "project", projectId: "p-active" },
+ modes: ["gantt"],
+ }),
+ { wrapper: Wrapper },
+ );
+ }
+
+ it("draws only matching rows after a retry recovers the project list", async () => {
+ const listProjects = vi
+ .fn()
+ .mockRejectedValueOnce(new Error("projects unavailable"))
+ .mockResolvedValue(PROJECTS);
+ const { result } = renderProjectGantt("project:pstatus-retry", listProjects);
+
+ await waitFor(() => expect(result.current.filterDependencyError?.kind).toBe("status"));
+ expect(result.current.ganttIssues).toHaveLength(ROWS.length);
+
+ act(() => result.current.filterDependencyError!.retry());
+ await waitFor(() => expect(result.current.filterDependencyError).toBeNull());
+ await waitFor(() =>
+ expect(result.current.filteredGanttIssues.map((issue) => issue.id)).toEqual(["active-row"]),
+ );
+ expect(result.current.isLoading).toBe(false);
+ });
+
+ it("keeps filtering by the last project list when a refetch fails", async () => {
+ const listProjects = vi
+ .fn()
+ .mockResolvedValueOnce(PROJECTS)
+ .mockRejectedValue(new Error("refetch failed"));
+ const { result } = renderProjectGantt("project:pstatus-stale", listProjects);
+ await waitFor(() =>
+ expect(result.current.filteredGanttIssues.map((issue) => issue.id)).toEqual(["active-row"]),
+ );
+
+ await act(async () => {
+ await qc.refetchQueries({ queryKey: ["projects", "ws-1", "list"] }).catch(() => {});
+ // Query observers notify on a timer; let the failure reach the hook.
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ });
+
+ expect(qc.getQueryState(["projects", "ws-1", "list"])?.status).toBe("error");
+ expect(result.current.filterDependencyError).toBeNull();
+ expect(result.current.filteredGanttIssues.map((issue) => issue.id)).toEqual(["active-row"]);
+ });
+ });
+
it("does not hold the surface when no project-status filter is active", async () => {
const projects = deferred<{ projects: never[]; total: number }>();
installApi(
@@ -246,7 +355,7 @@ describe("useIssueSurfaceController — project-status filter vs a late catalog"
);
await waitFor(() => expect(result.current.isLoading).toBe(false));
- expect(result.current.isStatusCatalogError).toBe(false);
+ expect(result.current.filterDependencyError).toBeNull();
});
});
diff --git a/packages/views/issues/surface/use-issue-surface-controller.test.tsx b/packages/views/issues/surface/use-issue-surface-controller.test.tsx
index 12e48a31d5..22e677e9f8 100644
--- a/packages/views/issues/surface/use-issue-surface-controller.test.tsx
+++ b/packages/views/issues/surface/use-issue-surface-controller.test.tsx
@@ -1703,7 +1703,7 @@ describe("useIssueSurfaceController", () => {
act(() => store.getState().toggleAgentRunningFilter());
expect(result.current.isLoading).toBe(true);
expect(result.current.isEmpty).toBe(false);
- expect(result.current.isWorkingFilterError).toBe(false);
+ expect(result.current.filterDependencyError).toBeNull();
expect(result.current.tableQuerySpec.filters.working_issue_ids).toBeUndefined();
expect(listIssueTableRows).not.toHaveBeenCalled();
expect(submenuFacetCalls(listIssueTableFacets)).toHaveLength(0);
@@ -1765,15 +1765,15 @@ describe("useIssueSurfaceController", () => {
() => useIssueSurfaceController({ scope: { type: "project", projectId: "p1" }, modes: ["list"] }),
{ wrapper: makeWrapper(qc) },
);
- await waitFor(() => expect(result.current.isWorkingFilterError).toBe(true));
+ await waitFor(() => expect(result.current.filterDependencyError?.kind).toBe("working"));
expect(result.current.isEmpty).toBe(false);
expect(result.current.tableQuerySpec.filters.working_issue_ids).toBeUndefined();
expect(listIssueTableRows).not.toHaveBeenCalled();
mockWorkingAgents([makeWorkingAgent("agent-1", ["todo-1"])]);
- act(() => result.current.retryWorkingFilter());
+ act(() => result.current.filterDependencyError!.retry());
await waitFor(() => expect(result.current.issues.map((issue) => issue.id)).toEqual(["todo-1"]));
expect(result.current.isLoading).toBe(false);
- expect(result.current.isWorkingFilterError).toBe(false);
+ expect(result.current.filterDependencyError).toBeNull();
});
const unreadMark = (issueId: string) => ({
@@ -1783,6 +1783,37 @@ describe("useIssueSurfaceController", () => {
created_at: "2026-01-01T00:00:00Z",
});
+ it("holds loading while the unread list loads, then filters by it", async () => {
+ mockListByStatus({ todo: [makeIssue({ id: "todo-1", status: "todo" })] });
+ let finish!: (marks: ReturnType<typeof unreadMark>[]) => void;
+ listIssueUnread.mockImplementation(() => new Promise((resolve) => { finish = resolve; }));
+ const store = getIssueSurfaceViewStore("project:p1");
+ store.getState().toggleUnreadFilter();
+ const { result } = renderHook(
+ () => useIssueSurfaceController({ scope: { type: "project", projectId: "p1" }, modes: ["list"] }),
+ { wrapper: makeWrapper(qc) },
+ );
+ // Only the unread list is outstanding, so it alone holds the loading state.
+ await waitFor(() =>
+ expect(qc.getQueryState(["issue-statuses", "ws-1", "list"])?.status).toBe("success"),
+ );
+ await act(async () => {
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ });
+ expect(listIssueUnread).toHaveBeenCalled();
+ expect(result.current.isLoading).toBe(true);
+ expect(result.current.isEmpty).toBe(false);
+ expect(result.current.filterDependencyError).toBeNull();
+ expect(result.current.tableQuerySpec.filters.unread_issue_ids).toBeUndefined();
+ expect(listIssueTableRows).not.toHaveBeenCalled();
+
+ await act(async () => finish([unreadMark("todo-1")]));
+ await waitFor(() => expect(result.current.isLoading).toBe(false));
+ expect(listIssueTableRows).toHaveBeenCalledWith(expect.objectContaining({
+ query: expect.objectContaining({ filters: expect.objectContaining({ unread_issue_ids: ["todo-1"] }) }),
+ }));
+ });
+
it("offers a retry when the unread filter cannot load the unread list", async () => {
mockListByStatus({ todo: [makeIssue({ id: "todo-1", status: "todo" })] });
listIssueUnread.mockRejectedValueOnce(new Error("offline"));
@@ -1792,15 +1823,15 @@ describe("useIssueSurfaceController", () => {
() => useIssueSurfaceController({ scope: { type: "project", projectId: "p1" }, modes: ["list"] }),
{ wrapper: makeWrapper(qc) },
);
- await waitFor(() => expect(result.current.isUnreadFilterError).toBe(true));
+ await waitFor(() => expect(result.current.filterDependencyError?.kind).toBe("unread"));
expect(result.current.isLoading).toBe(false);
expect(result.current.isEmpty).toBe(false);
expect(result.current.tableQuerySpec.filters.unread_issue_ids).toBeUndefined();
expect(listIssueTableRows).not.toHaveBeenCalled();
listIssueUnread.mockResolvedValue([unreadMark("todo-1")]);
- act(() => result.current.retryUnreadFilter());
+ act(() => result.current.filterDependencyError!.retry());
await waitFor(() => expect(result.current.issues.map((issue) => issue.id)).toEqual(["todo-1"]));
- expect(result.current.isUnreadFilterError).toBe(false);
+ expect(result.current.filterDependencyError).toBeNull();
expect(result.current.tableQuerySpec.filters.unread_issue_ids).toEqual(["todo-1"]);
});
@@ -1944,7 +1975,7 @@ describe("useIssueSurfaceController", () => {
await waitFor(() => expect(result.current.ganttIssues).toHaveLength(ganttFixture.length));
expect(listSubscribedIssueIds).toHaveBeenCalled();
expect(result.current.isLoading).toBe(true);
- expect(result.current.isRelationFilterError).toBe(false);
+ expect(result.current.filterDependencyError).toBeNull();
await act(async () => finish([]));
await waitFor(() => expect(result.current.isLoading).toBe(false));
@@ -1955,12 +1986,12 @@ describe("useIssueSurfaceController", () => {
listSubscribedIssueIds.mockRejectedValueOnce(new Error("offline"));
const { result } = renderSubscribedGantt();
- await waitFor(() => expect(result.current.isRelationFilterError).toBe(true));
+ await waitFor(() => expect(result.current.filterDependencyError?.kind).toBe("relation"));
expect(result.current.isEmpty).toBe(false);
listSubscribedIssueIds.mockResolvedValue(["gantt-open"]);
- act(() => result.current.retryRelationFilter());
- await waitFor(() => expect(result.current.isRelationFilterError).toBe(false));
+ act(() => result.current.filterDependencyError!.retry());
+ await waitFor(() => expect(result.current.filterDependencyError).toBeNull());
await waitFor(() =>
expect(result.current.filteredGanttIssues.map((issue) => issue.id)).toEqual(["gantt-open"]),
);
@@ -1976,7 +2007,7 @@ describe("useIssueSurfaceController", () => {
await waitFor(() => expect(result.current.ganttIssues).toHaveLength(ganttFixture.length));
await waitFor(() => expect(result.current.isLoading).toBe(false));
- expect(result.current.isRelationFilterError).toBe(false);
+ expect(result.current.filterDependencyError).toBeNull();
expect(result.current.filteredGanttIssues).toEqual([]);
});
@@ -2000,12 +2031,12 @@ describe("useIssueSurfaceController", () => {
listSubscribedIssueIds.mockResolvedValue([]);
const { result } = renderSubscribedGantt(["subscribed", "my_agents"]);
- await waitFor(() => expect(result.current.isRelationFilterError).toBe(true));
+ await waitFor(() => expect(result.current.filterDependencyError?.kind).toBe("relation"));
expect(result.current.isEmpty).toBe(false);
listAgents.mockResolvedValue([{ id: "agent-1", owner_id: "user-1" } as Agent]);
- act(() => result.current.retryRelationFilter());
- await waitFor(() => expect(result.current.isRelationFilterError).toBe(false));
+ act(() => result.current.filterDependencyError!.retry());
+ await waitFor(() => expect(result.current.filterDependencyError).toBeNull());
await waitFor(() =>
expect(result.current.filteredGanttIssues.map((issue) => issue.id)).toEqual(["gantt-open"]),
);
diff --git a/packages/views/issues/surface/use-issue-surface-controller.ts b/packages/views/issues/surface/use-issue-surface-controller.ts
index d09e14e3da..656cb45b18 100644
--- a/packages/views/issues/surface/use-issue-surface-controller.ts
+++ b/packages/views/issues/surface/use-issue-surface-controller.ts
@@ -40,6 +40,12 @@ import {
assigneeTypesForActorKind,
type IssueScope,
} from "@multica/core/issues/surface/scope";
+import {
+ combineFilterDependencies,
+ filterDependencyState,
+ statusCatalogSource,
+ type FilterDependencyState,
+} from "@multica/core/issues/surface/filter-dependency";
import type {
IssueDateFilter,
NegatableFilterDimension,
@@ -79,6 +85,14 @@ import {
type IssueGroupBranches,
} from "./use-issue-group-branches";
+/** Which filter's data failed, for the error state's copy. */
+export type FilterDependencyKind = "status" | "working" | "unread" | "relation";
+
+export interface FilterDependencyError {
+ kind: FilterDependencyKind;
+ retry: () => void;
+}
+
interface UseIssueSurfaceControllerInput {
scope: IssueScope;
modes: IssueSurfaceMode[];
@@ -143,24 +157,9 @@ export interface IssueSurfaceController {
/** See IssueSurfaceData.isRefreshing — placeholder-backed revalidation. */
isRefreshing: boolean;
isEmpty: boolean;
- /**
- * The status catalog a CUSTOM status filter depends on failed to load. The
- * filter cannot be honoured, so the surface shows a retryable error rather
- * than an unexplained empty board. (MUL-6243)
- */
- isStatusCatalogError: boolean;
- /** Re-runs the failed catalog request behind {@link isStatusCatalogError}. */
- retryStatusCatalog: () => void;
- /** First-load failure while the working filter needs issue membership. */
- isWorkingFilterError: boolean;
- retryWorkingFilter: () => void;
- isUnreadFilterError: boolean;
- retryUnreadFilter: () => void;
- /** The viewer's subscriptions or agents behind a "subscribed" /
- * "my_agents" relation failed to load on a surface that filters by them
- * itself. */
- isRelationFilterError: boolean;
- retryRelationFilter: () => void;
+ /** Data an active filter needs failed to load, so the filter cannot be
+ * honoured. The surface shows a retryable error instead of rows. */
+ filterDependencyError: FilterDependencyError | null;
openCreateIssue: (defaults?: IssueCreateDefaults) => void;
moveIssue: (
issueId: string,
@@ -346,13 +345,10 @@ export function useIssueSurfaceController({
enabled: usesSubscribed,
});
const subscribedIssueIds = subscribedIssueIdsQuery.data;
- const agentsUnresolved = usesMyAgents && agents === undefined;
- const subscribedIdsUnresolved = usesSubscribed && subscribedIssueIds === undefined;
- const relationDepsError =
- (agentsUnresolved && agentsQuery.isError) ||
- (subscribedIdsUnresolved && subscribedIssueIdsQuery.isError);
- const relationDepsPending =
- !relationDepsError && (agentsUnresolved || subscribedIdsUnresolved);
+ const relationSources = [
+ usesMyAgents && agentsQuery,
+ usesSubscribed && subscribedIssueIdsQuery,
+ ];
const relationContext = useMemo<IssueRelationContext | undefined>(() => {
if (!userId) return undefined;
return {
@@ -463,23 +459,19 @@ export function useIssueSurfaceController({
[catalog, columnStatus],
);
/**
- * A custom-status filter cannot be routed until the catalog answers. While it
- * is pending the surface must HOLD ITS LOADING STATE, and on failure it must
- * surface a retryable error — not fetch zero branches and render an empty
- * board, which is what "return no columns" alone produced. (MUL-6243)
- */
- const statusFilterPending = statusColumnsForFilters.state === "pending" ||
- ((usesServerStatusSurface || effectiveViewMode === "swimlane") && catalog.isPending);
- const statusFilterError = statusColumnsForFilters.state === "error" ||
- ((usesServerStatusSurface || effectiveViewMode === "swimlane") && catalog.isError);
- /**
- * Fetching is suspended until the filter resolves. Not just "narrow to
- * nothing": with the filter unresolved the visible column set falls back to
- * ALL categories, so fetching anyway would briefly show the UNFILTERED board
- * to someone who opened a saved `qa` view. Holding both the request and the
- * loading state is the only honest option.
+ * A custom-status filter is routed through the catalog, and status columns
+ * come from it. Until it answers, fetching is suspended: with the filter
+ * unresolved the visible column set falls back to ALL categories, so
+ * fetching anyway would briefly show the UNFILTERED board to someone who
+ * opened a saved `qa` view.
*/
- const statusFilterUnresolved = statusFilterPending || statusFilterError;
+ const statusDependency = filterDependencyState(
+ statusColumnsForFilters.state !== "resolved" ||
+ usesServerStatusSurface ||
+ effectiveViewMode === "swimlane",
+ [statusCatalogSource(catalog)],
+ );
+ const statusFilterUnresolved = statusDependency.unresolved;
// Display preferences hide individual columns; status filters independently
// select exact keys. Selecting a key explicitly restores its hidden column.
@@ -553,12 +545,8 @@ export function useIssueSurfaceController({
enabled: usesGantt || agentRunningFilter,
});
const workspaceWorkingAgents = workingAgentsProjection.data ?? EMPTY_LIST;
- const workingFilterUnresolved =
- agentRunningFilter && workingAgentsProjection.data === undefined;
- const workingFilterPending =
- workingFilterUnresolved && workingAgentsProjection.isPending;
- const workingFilterError =
- workingFilterUnresolved && workingAgentsProjection.isError;
+ const workingDependency = filterDependencyState(agentRunningFilter, [workingAgentsProjection]);
+ const workingFilterUnresolved = workingDependency.unresolved;
const workingIssueIDs = useMemo(() => {
const issueIDs = new Set<string>();
for (const agent of workspaceWorkingAgents) {
@@ -572,9 +560,9 @@ export function useIssueSurfaceController({
// the query keeps its identity) until the filter turns off or the surface
// unmounts; a newly unread issue grows the set and refetches.
const unreadProjection = useIssueUnreadIds(wsId, unreadFilter);
- const unreadIssueList = unreadProjection.ids;
- const unreadFilterUnresolved = unreadFilter && unreadIssueList === undefined;
- const unreadFilterError = unreadFilterUnresolved && unreadProjection.isError;
+ const unreadIssueList = unreadProjection.data;
+ const unreadDependency = filterDependencyState(unreadFilter, [unreadProjection]);
+ const unreadFilterUnresolved = unreadDependency.unresolved;
const keptUnreadRef = useRef<Set<string>>(new Set());
const unreadIssueIDs = useMemo<ReadonlySet<string>>(() => {
if (!unreadFilter) {
@@ -939,8 +927,7 @@ export function useIssueSurfaceController({
ganttShowCompleted,
statusFilters,
hiddenStatusKeys,
- statusFilterPending,
- statusFilterError,
+ statusDependency,
priorityFilters,
assigneeFilters,
includeNoAssignee,
@@ -953,8 +940,7 @@ export function useIssueSurfaceController({
labelFilters,
relationFilters,
relationContext,
- relationDepsPending,
- relationDepsError,
+ relationSources,
dueDateFilters,
advancedFilter,
today,
@@ -1055,7 +1041,20 @@ export function useIssueSurfaceController({
createDefaults: resolvedCreateDefaults,
});
- const { ganttWorkingScopeIssues: _ganttWorkingScope, ...surfaceData } = data;
+ const {
+ ganttWorkingScopeIssues: _ganttWorkingScope,
+ projectCatalogDependency,
+ relationDependency,
+ ...surfaceData
+ } = data;
+ // In the order the surface reports them when several fail at once.
+ const dependencies: [FilterDependencyKind, FilterDependencyState][] = [
+ ["status", combineFilterDependencies(statusDependency, projectCatalogDependency)],
+ ["working", workingDependency],
+ ["unread", unreadDependency],
+ ["relation", relationDependency],
+ ];
+ const failedDependency = dependencies.find(([, state]) => state.error);
return {
scopeKey,
@@ -1064,8 +1063,7 @@ export function useIssueSurfaceController({
viewMode: effectiveViewMode,
allowGantt: allowedModes.has("gantt") && !!projectId,
...surfaceData,
- isLoading:
- data.isLoading || workingFilterPending || (unreadFilterUnresolved && !unreadFilterError),
+ isLoading: data.isLoading || workingDependency.pending || unreadDependency.pending,
workingAgents,
hasActiveFilters,
statusPagination: usesServerStatusSurface
@@ -1083,26 +1081,9 @@ export function useIssueSurfaceController({
data.isEmpty &&
!data.isRefreshing &&
!(usesTable && (tableSearch.trim() || debouncedActiveSearch)),
- isStatusCatalogError: data.isStatusCatalogError,
- // Either catalog can be the one that failed, and the error state offers a
- // single retry — refresh both rather than guess which.
- retryStatusCatalog: () => {
- catalog.retry();
- data.retryProjectCatalog();
- },
- isWorkingFilterError: workingFilterError,
- retryWorkingFilter: () => {
- void workingAgentsProjection.refetch();
- },
- isUnreadFilterError: unreadFilterError,
- retryUnreadFilter: () => {
- void unreadProjection.refetch();
- },
- isRelationFilterError: data.isRelationFilterError,
- retryRelationFilter: () => {
- if (agentsQuery.isError) void agentsQuery.refetch();
- if (subscribedIssueIdsQuery.isError) void subscribedIssueIdsQuery.refetch();
- },
+ filterDependencyError: failedDependency
+ ? { kind: failedDependency[0], retry: failedDependency[1].retry }
+ : null,
sort,
actions,
selection,
diff --git a/packages/views/issues/surface/use-issue-surface-data.ts b/packages/views/issues/surface/use-issue-surface-data.ts
index 7df48abc58..6dc171d05f 100644
--- a/packages/views/issues/surface/use-issue-surface-data.ts
+++ b/packages/views/issues/surface/use-issue-surface-data.ts
@@ -7,6 +7,11 @@ import { projectListOptions } from "@multica/core/projects/queries";
import { childIssueProgressOptions } from "@multica/core/issues/queries";
import { issueSurfaceGanttOptions } from "@multica/core/issues/surface/repository";
import type { IssueSurfaceQueryPlan } from "@multica/core/issues/surface/query-plan";
+import {
+ filterDependencyState,
+ type FilterDependencySource,
+ type FilterDependencyState,
+} from "@multica/core/issues/surface/filter-dependency";
import type { IssueStatus, ProjectStatus, PropertyFilterValue } from "@multica/core/types";
import { useIssueStatuses } from "@multica/core/issue-statuses/hooks";
import {
@@ -87,20 +92,12 @@ export interface IssueSurfaceData {
childProgressMap: Map<string, ChildProgress>;
}>;
isLoading: boolean;
- /**
- * A filter catalog this surface depends on failed. The filter cannot be
- * honoured without it, so the surface shows a retryable error rather than
- * an unexplained empty board (MUL-6243) — or, for the project-status
- * filter, an unfiltered one under an active chip.
- */
- isStatusCatalogError: boolean;
- /** Re-runs the project list behind the project-status half of
- * {@link isStatusCatalogError}. */
- retryProjectCatalog: () => void;
- /** The viewer's subscriptions or agents behind a "subscribed" /
- * "my_agents" relation failed to load and this surface applies the
- * relation itself. */
- isRelationFilterError: boolean;
+ /** The project list behind a project-status filter this surface applies
+ * itself. */
+ projectCatalogDependency: FilterDependencyState;
+ /** The viewer's subscriptions / agents behind a relation filter this
+ * surface applies itself. */
+ relationDependency: FilterDependencyState;
/** The window's data is being revalidated while the previous snapshot is
* shown as a placeholder (sort/date change, or any grouped-board filter
* change). Drives the header's deferred refresh indicator — content stays
@@ -120,8 +117,7 @@ export function useIssueSurfaceData({
ganttShowCompleted,
statusFilters,
hiddenStatusKeys,
- statusFilterPending,
- statusFilterError,
+ statusDependency,
priorityFilters,
assigneeFilters,
includeNoAssignee,
@@ -134,8 +130,7 @@ export function useIssueSurfaceData({
labelFilters,
relationFilters,
relationContext,
- relationDepsPending,
- relationDepsError,
+ relationSources,
dueDateFilters,
advancedFilter,
today,
@@ -158,10 +153,8 @@ export function useIssueSurfaceData({
ganttShowCompleted: boolean;
statusFilters: IssueStatus[];
hiddenStatusKeys: IssueStatus[];
- /** A custom status filter is waiting on the catalog — hold loading. */
- statusFilterPending: boolean;
- /** The catalog failed, so a custom status filter cannot be honoured. */
- statusFilterError: boolean;
+ /** The status catalog the columns and a custom status filter route through. */
+ statusDependency: FilterDependencyState;
priorityFilters: IssueFilterState["priorityFilters"];
assigneeFilters: IssueFilterState["assigneeFilters"];
includeNoAssignee: boolean;
@@ -174,10 +167,9 @@ export function useIssueSurfaceData({
labelFilters: string[];
relationFilters: IssueRelationFilter[];
relationContext: IssueRelationContext | undefined;
- /** A filter uses "subscribed" or "my_agents" and the data it reads (the
- * viewer's subscriptions / agents) has not loaded yet / failed to load. */
- relationDepsPending: boolean;
- relationDepsError: boolean;
+ /** What the active relation values read: the viewer's agents for
+ * "my_agents", their subscriptions for "subscribed". */
+ relationSources: readonly (FilterDependencySource | false)[];
dueDateFilters: DueDateFilter[];
/** The scoped, pruned rule tree. */
advancedFilter: AdvancedFilterGroup | null;
@@ -197,15 +189,11 @@ export function useIssueSurfaceData({
...issueSurfaceGanttOptions(wsId, projectId ?? "", queryPlan),
enabled: usesGantt,
});
- const {
- data: projectData,
- refetch: refetchProjects,
- isPending: projectsPending,
- isError: projectsError,
- } = useQuery({
+ const projectsQuery = useQuery({
...projectListOptions(wsId),
enabled: loadProjects,
});
+ const { data: projectData, refetch: refetchProjects } = projectsQuery;
const projects = projectData ?? EMPTY_PROJECTS;
const projectMap = useMemo(
() => new Map(projects.map((project) => [project.id, project])),
@@ -224,23 +212,15 @@ export function useIssueSurfaceData({
: undefined,
[projectData],
);
- // An unresolved catalog is "cannot answer yet", not "no filter". Showing
- // UNFILTERED rows under an active chip is as wrong as blanking the surface,
- // and a failed project request would leave it that way for good. So where a
- // surface actually applies the client predicate, hold it in loading and
- // report the failure — the same contract `statusFilterPending` /
- // `statusFilterError` give a custom status filter. Table and the
- // server-status branches filter server-side and never read the catalog.
- const usesClientProjectStatusFilter =
- (projectStatusFilters.length > 0 || advancedFilterUsesField(advancedFilter, "projectStatus")) &&
- !usesTable &&
- (usesGantt || !serverStatusBranches.enabled);
- const projectCatalogPending = usesClientProjectStatusFilter && projectsPending;
- const projectCatalogError = usesClientProjectStatusFilter && projectsError;
- // Same contract for the subscriptions / agents behind the relation filter.
- const usesClientRelationFilter = !usesTable && (usesGantt || !serverStatusBranches.enabled);
- const relationFilterPending = usesClientRelationFilter && relationDepsPending;
- const relationFilterError = usesClientRelationFilter && relationDepsError;
+ // Only where this surface applies a predicate itself does it wait on that
+ // predicate's data. Table and the server-status branches filter server-side.
+ const usesClientPredicates = !usesTable && (usesGantt || !serverStatusBranches.enabled);
+ const projectCatalogDependency = filterDependencyState(
+ usesClientPredicates &&
+ (projectStatusFilters.length > 0 || advancedFilterUsesField(advancedFilter, "projectStatus")),
+ [projectsQuery],
+ );
+ const relationDependency = filterDependencyState(usesClientPredicates, relationSources);
const workingFilterContext = useMemo(
() => ({
@@ -516,14 +496,10 @@ export function useIssueSurfaceData({
],
);
- // `statusFilterPending` holds the surface in loading while a CUSTOM status
- // filter waits for the catalog to say which column it belongs to. Without it
- // the surface reported "loaded, zero results" — an empty board with no
- // spinner — for the whole cold-load window. (MUL-6243)
const isLoading =
- statusFilterPending ||
- projectCatalogPending ||
- relationFilterPending ||
+ statusDependency.pending ||
+ projectCatalogDependency.pending ||
+ relationDependency.pending ||
(serverGroupBranches.enabled
? serverGroupBranches.isLoading
: usesGantt
@@ -568,9 +544,9 @@ export function useIssueSurfaceData({
// so this shared legacy surface projection never asserts Table empty.
isEmpty:
!isLoading &&
- !statusFilterError &&
- !projectCatalogError &&
- !relationFilterError &&
+ !statusDependency.error &&
+ !projectCatalogDependency.error &&
+ !relationDependency.error &&
!usesGantt &&
!usesTable &&
(serverStatusBranches.enabled
@@ -579,11 +555,7 @@ export function useIssueSurfaceData({
: serverGroupBranches.enabled &&
!serverGroupBranches.isError &&
serverGroupBranches.total === 0),
- // Widened past the status catalog: this flag means "a filter catalog this
- // surface depends on is down", and the error state's copy and retry fit
- // either one. `retryStatusCatalog` refetches both.
- isStatusCatalogError: statusFilterError || projectCatalogError,
- retryProjectCatalog: refetchProjects,
- isRelationFilterError: relationFilterError,
+ projectCatalogDependency,
+ relationDependency,
};
}
diff --git a/packages/views/layout/panels/views-section.tsx b/packages/views/layout/panels/views-section.tsx
index ad44a652cc..2a69621477 100644
--- a/packages/views/layout/panels/views-section.tsx
+++ b/packages/views/layout/panels/views-section.tsx
@@ -31,6 +31,7 @@ import {
} from "@multica/core/issues/sidebar-list";
import { todayDateOnly } from "@multica/core/issues/date";
import { useIssueUnreadIds } from "@multica/core/issues/unread";
+import { filterDependencyState, statusCatalogSource } from "@multica/core/issues/surface/filter-dependency";
import { useIssueStatuses } from "@multica/core/issue-statuses/hooks";
import { useSidebarProjectPrefs } from "@multica/core/issues/sidebar-project-prefs";
import { useSidebarKeptStore } from "@multica/core/issues/stores/sidebar-kept-store";
@@ -340,9 +341,10 @@ function BuiltinViewRow({
const setExpanded = useSidebarTreeStore((s) => s.setExpanded);
const statusCatalog = useIssueStatuses(wsId);
const { issueSettings } = useSidebarProjectPrefs(wsId);
- const request = statusCatalog.isLoaded
- ? builtinSidebarRequest(builtin, myIssuesRelationFromScope(myScope), issueSettings, statusCatalog.statuses)
- : undefined;
+ const catalogDependency = filterDependencyState(true, [statusCatalogSource(statusCatalog)]);
+ const request = catalogDependency.unresolved
+ ? undefined
+ : builtinSidebarRequest(builtin, myIssuesRelationFromScope(myScope), issueSettings, statusCatalog.statuses);
const prefetch = usePrefetch(wsId, source, request);
return (
@@ -388,6 +390,8 @@ function BuiltinViewRow({
wsId={wsId}
source={source}
params={request}
+ paramsError={catalogDependency.error}
+ onRetry={catalogDependency.retry}
activeIssueId={activeIssueId}
onCollapse={() => {
setExpanded(source, false);
@@ -446,10 +450,13 @@ function UnreadViewRow({
const expanded = useSidebarTreeStore((s) => s.expanded.includes(source));
const setExpanded = useSidebarTreeStore((s) => s.setExpanded);
const unread = useIssueUnreadIds(wsId);
- const count = unread.ids?.length ?? 0;
- const request = unread.ids ? viewSidebarRequest(UNREAD_VIEW, todayDateOnly(), unread.ids) : undefined;
+ const unreadDependency = filterDependencyState(true, [unread]);
+ const count = unread.data?.length ?? 0;
+ const request = unreadDependency.unresolved
+ ? undefined
+ : viewSidebarRequest(UNREAD_VIEW, todayDateOnly(), unread.data);
const prefetch = usePrefetch(wsId, source, request);
- const readingUnread = useOpenedUnread(activeIssueId, unread.ids);
+ const readingUnread = useOpenedUnread(activeIssueId, unread.data);
if (count === 0 && !open && !readingUnread) return null;
const label = t(($) => $.panels.work.unread);
@@ -475,8 +482,8 @@ function UnreadViewRow({
wsId={wsId}
source={source}
params={request}
- paramsError={unread.isError}
- onRetry={() => void unread.refetch()}
+ paramsError={unreadDependency.error}
+ onRetry={unreadDependency.retry}
activeIssueId={activeIssueId}
onCollapse={() => {
setExpanded(source, false);
@@ -528,8 +535,10 @@ function SavedViewRow({
const setExpanded = useSidebarTreeStore((s) => s.setExpanded);
const needsUnread = viewSidebarNeedsUnread(view);
const unread = useIssueUnreadIds(wsId, needsUnread);
- const request =
- needsUnread && !unread.ids ? undefined : viewSidebarRequest(view, todayDateOnly(), unread.ids);
+ const unreadDependency = filterDependencyState(needsUnread, [unread]);
+ const request = unreadDependency.unresolved
+ ? undefined
+ : viewSidebarRequest(view, todayDateOnly(), unread.data);
const prefetch = usePrefetch(wsId, source, request);
const canManage = actions.canManage(view);
@@ -609,8 +618,8 @@ function SavedViewRow({
wsId={wsId}
source={source}
params={request}
- paramsError={needsUnread && unread.isError}
- onRetry={() => void unread.refetch()}
+ paramsError={unreadDependency.error}
+ onRetry={unreadDependency.retry}
activeIssueId={activeIssueId}
onCollapse={() => {
setExpanded(source, false);
diff --git a/packages/views/layout/panels/views-section.unread.test.tsx b/packages/views/layout/panels/views-section.unread.test.tsx
index 19dcb0a458..ed2b4edf4b 100644
--- a/packages/views/layout/panels/views-section.unread.test.tsx
+++ b/packages/views/layout/panels/views-section.unread.test.tsx
@@ -6,7 +6,7 @@ import { setApiInstance } from "@multica/core/api";
import type { ApiClient } from "@multica/core/api/client";
import { useSidebarKeptStore } from "@multica/core/issues/stores/sidebar-kept-store";
import { useSidebarTreeStore } from "@multica/core/issues/stores/sidebar-tree-store";
-import { viewSidebarSource } from "@multica/core/issues/sidebar-list";
+import { builtinSidebarSource, viewSidebarSource } from "@multica/core/issues/sidebar-list";
import { issueUnreadOptions } from "@multica/core/issues/unread";
import { issueViewContainerKey, useActiveIssueViewStore } from "@multica/core/issue-views/active-view-store";
import { UNREAD_VIEW_ID } from "@multica/core/issue-views/unread-view";
@@ -47,10 +47,6 @@ vi.mock("@multica/core/hooks", async (importOriginal) => ({
...(await importOriginal<typeof import("@multica/core/hooks")>()),
useWorkspaceId: () => "ws-1",
}));
-vi.mock("@multica/core/issue-statuses/hooks", async () => {
- const { buildIssueStatusCatalog } = await import("@multica/core/issue-statuses/queries");
- return { useIssueStatuses: () => buildIssueStatusCatalog([]) };
-});
const adapter: NavigationAdapter = {
push: vi.fn(),
@@ -74,6 +70,7 @@ const UNREAD_VIEW = {
let listIssueUnread: ReturnType<typeof vi.fn>;
let listIssueTableRows: ReturnType<typeof vi.fn>;
+let listIssueStatuses: ReturnType<typeof vi.fn>;
function renderSection({ activeIssueId = null }: { activeIssueId?: string | null } = {}) {
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
@@ -104,9 +101,11 @@ beforeEach(() => {
group_key: null,
parent_id: null,
}));
+ listIssueStatuses = vi.fn(async () => ({ statuses: [], categories: [], total: 0 }));
setApiInstance({
listIssueUnread,
listIssueTableRows,
+ listIssueStatuses,
listIssueViews: vi.fn(async () => []),
getIssueViewPreference: vi.fn(() => new Promise(() => {})),
} as unknown as ApiClient);
@@ -117,6 +116,27 @@ beforeEach(() => {
});
describe("ViewsSection saved view with the unread filter", () => {
+ it("holds its placeholder while the unread list loads, then lists the view's issues", async () => {
+ let finish!: (marks: unknown[]) => void;
+ listIssueUnread.mockImplementation(() => new Promise((resolve) => { finish = resolve; }));
+ renderSection();
+
+ await waitFor(() => expect(listIssueUnread).toHaveBeenCalled());
+ expect(screen.queryByText("No issues")).toBeNull();
+ expect(screen.queryByRole("button", { name: "Retry" })).toBeNull();
+ expect(listIssueTableRows).not.toHaveBeenCalled();
+
+ finish([{ issue_id: "issue-1", outcome: "manual", agent_id: null, created_at: "2026-01-01T00:00:00Z" }]);
+ await screen.findByText("No issues");
+ expect(listIssueTableRows).toHaveBeenCalledWith(
+ expect.objectContaining({
+ query: expect.objectContaining({
+ filters: expect.objectContaining({ unread_issue_ids: ["issue-1"] }),
+ }),
+ }),
+ );
+ });
+
it("offers a retry when the unread list fails, then lists the view's issues", async () => {
listIssueUnread.mockRejectedValueOnce(new Error("offline"));
renderSection();
@@ -144,6 +164,21 @@ describe("ViewsSection saved view with the unread filter", () => {
});
});
+const TODO_STATUS = {
+ id: "s-todo",
+ workspace_id: "ws-1",
+ key: "todo",
+ name: "Todo",
+ description: "",
+ category: "unstarted",
+ color: "",
+ is_system: true,
+ position: 0,
+ archived_at: null,
+ created_at: "",
+ updated_at: "",
+};
+
const mark = (issueId: string) => ({
issue_id: issueId,
outcome: "completed",
@@ -209,3 +244,28 @@ describe("ViewsSection built-in Unread view", () => {
expect(screen.queryByRole("link", { name: /^Unread/ })).toBeNull();
});
});
+
+describe("ViewsSection built-in All issues view", () => {
+ beforeEach(() => {
+ listIssueUnread.mockResolvedValue([]);
+ actions.sidebar.items = [{ id: "builtin:all_issues", kind: "builtin", key: "all_issues" }];
+ useSidebarTreeStore.setState({ viewsCollapsed: false, expanded: [builtinSidebarSource("all_issues")] });
+ });
+
+ it("offers a retry when the status catalog fails, then lists its issues", async () => {
+ listIssueStatuses.mockRejectedValueOnce(new Error("offline"));
+ renderSection();
+
+ const retry = await screen.findByRole("button", { name: "Retry" });
+ expect(screen.getByText("Couldn't load issues")).toBeInTheDocument();
+ expect(listIssueTableRows).not.toHaveBeenCalled();
+
+ listIssueStatuses.mockResolvedValue({ statuses: [TODO_STATUS], categories: [], total: 1 });
+ fireEvent.click(retry);
+
+ await screen.findByText("No issues");
+ expect(listIssueTableRows).toHaveBeenCalledWith(
+ expect.objectContaining({ query: expect.objectContaining({ scope: { kind: "workspace" } }) }),
+ );
+ });
+});