Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,78 @@ describe("sanitizePaneLayout", () => {
expect(result.activeTabId).toBe("tab-1");
});

it("keeps pull-request panes keyed by repository and panes of other kinds", () => {
const layout: PaneLayout = {
version: 1,
tabs: [
{
...validTab,
layout: {
type: "split",
direction: "horizontal",
first: { type: "pane", paneId: "pane-1" },
second: { type: "pane", paneId: "pane-2" },
},
panes: {
"pane-1": { id: "pane-1", kind: "terminal", data: { prNumber: 1 } },
"pane-2": {
id: "pane-2",
kind: "pull-request",
data: { repoFullName: "acme/app", number: 7 },
},
},
},
],
activeTabId: "tab-1",
};
expect(sanitizePaneLayout(layout)).toEqual(layout);
});

it("drops a pull-request pane saved by number alone and keeps its siblings", () => {
const result = sanitizePaneLayout({
version: 1,
tabs: [
{
...validTab,
activePaneId: "pane-pr",
layout: {
type: "split",
direction: "horizontal",
first: { type: "pane", paneId: "pane-1" },
second: { type: "pane", paneId: "pane-pr" },
},
panes: {
"pane-1": validTab.panes["pane-1"],
"pane-pr": {
id: "pane-pr",
kind: "pull-request",
data: { prNumber: 7, projectId: "project-1" },
},
},
},
{
id: "tab-pr",
createdAt: 0,
activePaneId: "pane-pr-only",
layout: { type: "pane", paneId: "pane-pr-only" },
panes: {
"pane-pr-only": {
id: "pane-pr-only",
kind: "pull-request",
data: { prNumber: 8 },
},
},
},
],
activeTabId: "tab-pr",
});
expect(result).toEqual({
version: 1,
tabs: [validTab],
activeTabId: "tab-1",
});
});

it("repairs activeTabId when it points at a dropped/absent tab", () => {
const result = sanitizePaneLayout({
version: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import type { AppRouter } from "@superset/host-service";
import type { LayoutNode, Tab, WorkspaceState } from "@superset/panes";
import {
findFirstPaneId,
type LayoutNode,
type Pane,
removePaneFromLayout,
type Tab,
type WorkspaceState,
} from "@superset/panes";
import { tagFolderScopeInputSchema } from "@superset/shared/workspace-tags";
import type { inferRouterInputs } from "@trpc/server";
import { z } from "zod";
Expand Down Expand Up @@ -62,6 +69,35 @@ const EMPTY_PANE_LAYOUT: WorkspaceState<unknown> = {
activeTabId: null,
};

// Before #7823 a pull-request pane stored `{ prNumber }` and borrowed its
// repository from the workspace; that shape cannot be read by repository.
function isPullRequestPaneWithoutRepository(pane: Pane<unknown>): boolean {
return (
pane.kind === "pull-request" &&
typeof (pane.data as { repoFullName?: unknown } | null)?.repoFullName !==
"string"
);
}

function withoutUnreadablePanes(tab: Tab<unknown>): Tab<unknown> | null {
const unreadable = Object.values(tab.panes).filter(
isPullRequestPaneWithoutRepository,
);
if (unreadable.length === 0) return tab;
let layout: LayoutNode | null = tab.layout;
const panes = { ...tab.panes };
for (const pane of unreadable) {
layout = layout && removePaneFromLayout(layout, pane.id);
delete panes[pane.id];
}
if (!layout) return null;
const activePaneId =
tab.activePaneId && panes[tab.activePaneId]
? tab.activePaneId
: findFirstPaneId(layout);
return { ...tab, layout, panes, activePaneId };
}

/**
* Read-time heal for a persisted pane layout. An unparseable top-level shape
* (missing `version`/`tabs`, or the legacy `{ panes, focusedPaneId }` layout)
Expand All @@ -78,7 +114,9 @@ export function sanitizePaneLayout(raw: unknown): WorkspaceState<unknown> {
}
const tabs = value.tabs.flatMap((tab): Tab<unknown>[] => {
const parsed = tabNodeSchema.safeParse(tab);
return parsed.success ? [parsed.data as Tab<unknown>] : [];
if (!parsed.success) return [];
const healed = withoutUnreadablePanes(parsed.data as Tab<unknown>);
return healed ? [healed] : [];
});
const activeTabId =
typeof value.activeTabId === "string" &&
Expand Down
Loading