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
24 changes: 24 additions & 0 deletions web/e2e/part-views.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,34 @@ test("Script / Timeline / Results are first-class stage tabs", async ({ page },
await page.locator('[data-stage-tab="results"]').click();
await expect(page.locator('[data-stage-panel="results"] [data-panel="results"]')).toBeVisible();
await expect(page).toHaveURL(/tab=results/);
// Stage Results is the one ResultsPanel. The inspector must not also mount
// it — that was the duplicate list/metrics after #6.
await expect(page.locator('[data-inspector-panel="results"]')).toHaveCount(0);
await expect(page.locator('[data-inspector-tab="results"]')).toHaveCount(0);

await archive(page, testInfo, "part-views-tabs");
});

test("the project tree lists the closed sections even when empty", async ({ page }, testInfo) => {
await open(page, route(PART));
const ids = ["analyses", "docs", "globals", "imports", "materials"] as const;
for (const id of ids) {
const row = page.locator(`[data-tree-row="section"][data-tree-section="${id}"]`);
await expect(row).toBeVisible();
await expect(row).toHaveAttribute("aria-expanded", "false");
}
await expect(page.locator("[data-tree-section-empty]")).toHaveCount(0);
// §13.1: the working tree stays a fact. Expanding a section must not hide
// dirty rows, and this page still addresses them with the same selector.
await page.locator('[data-tree-section="materials"]').click();
await expect(page.locator('[data-tree-section-empty="materials"]')).toBeVisible();
await expect(
page.locator('[data-tree-section-empty="materials"] [data-source]'),
).toHaveCount(0);

await archive(page, testInfo, "project-tree-sections");
});

test("PARAMS sliders are the GET /parts/{part}/params projection", async ({ page }, testInfo) => {
const document = await api<ParamsDocument>(`/parts/${PART}/params`);
expect(document.status).toBe("ok");
Expand Down
84 changes: 84 additions & 0 deletions web/src/components/rail/ProjectTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
// projection and from nothing else — a part can be clean and unbuilt, or dirty
// and current, and this tree shows the two axes side by side without joining
// them.
//
// Below the parts list sit five closed sections (Analyses / Docs / Globals /
// Imports / Materials). They are listed even when empty. The engine has no
// HTTP projection for those inventories, so an expanded section is an
// empty-honest absence — not a catalog invented here. Git dirty stays in
// `GitDirty` (§13.1); this tree does not hide `.heph/` rows.

import { useState } from "react";
import { useBuild, useParts } from "../../api/queries";
import { copy } from "../../copy";
import type { PartSummary } from "../../api/types";
Expand All @@ -46,10 +53,35 @@ import { Fact } from "../Fact";
import { DirtyMarker, useDirtyIndex, type DirtyIndex } from "./GitDirty";
import styles from "./ProjectTree.module.css";

/**
* Closed project-tree sections. Always listed, even when empty: the engine
* has no HTTP projection for analyses / docs / globals / imports / materials
* today, so an expanded section is an empty-honest absence — not a catalog
* invented from a registry or a walk of the project root.
*/
export const PROJECT_TREE_SECTIONS = [
"analyses",
"docs",
"globals",
"imports",
"materials",
] as const;
export type ProjectTreeSection = (typeof PROJECT_TREE_SECTIONS)[number];

export function ProjectTree(): React.JSX.Element {
const parts = useParts();
const dirty = useDirtyIndex();
const selected = useWorkspace((s) => s.part);
const [open, setOpen] = useState<ReadonlySet<ProjectTreeSection>>(() => new Set());

const toggle = (id: ProjectTreeSection): void => {
setOpen((current) => {
const next = new Set(current);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
};

return (
<Panel className={styles["panel"]} label={copy.rail.partsHeading}>
Expand Down Expand Up @@ -96,11 +128,63 @@ export function ProjectTree(): React.JSX.Element {
))}
</Tree>
)}
<ProjectSectionList open={open} onToggle={toggle} />
</PanelBody>
</Panel>
);
}

/**
* The five closed sections, as a tree. Split out so a test can assert the
* inventory and the empty-honest expanded body without standing up `GET /parts`.
*/
export function ProjectSectionList({
open,
onToggle,
}: {
readonly open: ReadonlySet<ProjectTreeSection>;
readonly onToggle: (id: ProjectTreeSection) => void;
}): React.JSX.Element {
return (
<Tree label={copy.rail.title}>
{PROJECT_TREE_SECTIONS.map((id) => {
const expanded = open.has(id);
return (
<TreeRow
key={id}
depth={0}
selected={false}
expanded={expanded}
onSelect={() => {
onToggle(id);
}}
onToggle={() => {
onToggle(id);
}}
data-tree-row="section"
data-tree-section={id}
label={copy.rail.sections[id]}
>
{expanded ? (
<TreeGroup>
<li role="none">
<EmptyState
icon="file"
density="inline"
title={copy.rail.sectionEmptyTitle}
body={copy.rail.sectionEmpty}
data-tree-section-empty={id}
/>
</li>
</TreeGroup>
) : null}
</TreeRow>
);
})}
</Tree>
);
}

interface PartNodeProps {
readonly part: PartSummary;
readonly dirty: DirtyIndex;
Expand Down
16 changes: 12 additions & 4 deletions web/src/components/stage/Inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
// is in the URL and survives a reload like everything else. Each panel is a
// projection of one read route and owns its own named absences (§6.1–§6.4,
// §4.4). Sourcing reads the same properties route as Properties, filtered to
// the declared manufacturing-identity fields.
// the declared manufacturing-identity fields. When the stage tab is Results
// the Results inspector tab is omitted so the same list is not drawn twice.
//
// The sixth is §22.7's `export`, and it is the only one containing a control that
// WRITES. Issue #12 also puts a compact Export control in header chrome, bound
Expand All @@ -37,7 +38,11 @@
import { useState } from "react";
import { copy } from "../../copy";
import { useWorkspace, workspaceStore } from "../../state/react";
import { INSPECTOR_TABS, type InspectorTab } from "../../state/workspace";
import {
effectiveInspectorTab,
inspectorTabsFor,
type InspectorTab,
} from "../../state/workspace";
import { TabBar } from "../../system";
import { ChecksPanel } from "../inspector/ChecksPanel";
import { DfmPanel, type DescriptorIntent } from "../inspector/DfmPanel";
Expand All @@ -49,7 +54,10 @@ import { SourcingPanel } from "../inspector/SourcingPanel";
import styles from "./Inspector.module.css";

export function Inspector(): React.JSX.Element {
const tab = useWorkspace((s) => s.inspector_tab);
const stageTab = useWorkspace((s) => s.stage_tab);
const requested = useWorkspace((s) => s.inspector_tab);
const tab = effectiveInspectorTab(stageTab, requested);
const tabs = inspectorTabsFor(stageTab);
const [intent, setIntent] = useState<DescriptorIntent | undefined>(undefined);

return (
Expand All @@ -61,7 +69,7 @@ export function Inspector(): React.JSX.Element {
onSelect={(next: InspectorTab) => {
workspaceStore.update({ inspector_tab: next });
}}
tabs={INSPECTOR_TABS.map((name) => ({ id: name, label: copy.inspector.tabs[name] }))}
tabs={tabs.map((name) => ({ id: name, label: copy.inspector.tabs[name] }))}
/>
<div className={styles["content"]} role="tabpanel" data-inspector-panel={tab}>
{tab === "results" ? (
Expand Down
13 changes: 10 additions & 3 deletions web/src/components/stage/Stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
//
// Diff is still the named pending tab. Script / Timeline / Results are the
// part views: Monaco + PARAMS, the last-good scrubber, and the existing
// ResultsPanel (also still the inspector's first tab).
// ResultsPanel. When the stage tab is Results the inspector omits that
// panel so the geometry list and metrics are not drawn twice.

import { useCallback, useEffect, useRef } from "react";
import { copy } from "../../copy";
import { useWorkspace, workspaceStore } from "../../state/react";
import { shellStore } from "../../state/shell";
import { STAGE_TABS, type StageTab } from "../../state/workspace";
import { effectiveInspectorTab, STAGE_TABS, type StageTab } from "../../state/workspace";
import { Badge, EmptyState, TabBar, useShell } from "../../system";
import { ResultsPanel } from "../inspector/ResultsPanel";
import { useDirtyIndex } from "../rail/GitDirty";
Expand All @@ -41,6 +42,7 @@ import styles from "./Stage.module.css";

export function Stage(): React.JSX.Element {
const tab = useWorkspace((s) => s.stage_tab);
const inspectorTab = useWorkspace((s) => s.inspector_tab);
const part = useWorkspace((s) => s.part);
const dirty = useDirtyIndex();
const shell = useShell();
Expand Down Expand Up @@ -99,7 +101,12 @@ export function Stage(): React.JSX.Element {
label={copy.stage.tabsLabel}
selected={tab}
onSelect={(next: StageTab) => {
workspaceStore.update({ stage_tab: next });
const nextInspector = effectiveInspectorTab(next, inspectorTab);
workspaceStore.update(
nextInspector === inspectorTab
? { stage_tab: next }
: { stage_tab: next, inspector_tab: nextInspector },
);
}}
tabs={STAGE_TABS.map((name) => ({
id: name,
Expand Down
14 changes: 14 additions & 0 deletions web/src/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ export const copy = {
open: "Show the project rail",
close: "Hide the project rail",
partsHeading: "Parts",
/**
* Closed project-tree sections. Always listed, even when the engine has
* projected no rows. The names are the inventory; emptiness is a fact.
*/
sections: {
analyses: "Analyses",
docs: "Docs",
globals: "Globals",
imports: "Imports",
materials: "Materials",
},
sectionEmptyTitle: "No facts",
sectionEmpty:
"The engine has not projected any items for this section. Nothing is being hidden, and no catalog is invented here.",
/** §13.1: the rail shows the git axis; the header shows the artifact axis. */
gitHeading: "Working tree",
versionsHeading: "Versions",
Expand Down
25 changes: 24 additions & 1 deletion web/src/state/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export type ChannelOverlay = (typeof CHANNEL_OVERLAYS)[number];
* Stage tabs. `viewport` / `script` / `diff` are §4.5's original closed set.
* `timeline` and `results` are the part views issue #4 adds so Script /
* Timeline / Results are first-class switches on the same tablist. `results`
* here reuses `ResultsPanel`; the inspector Results tab stays.
* here reuses `ResultsPanel`. When this tab is selected the inspector does
* not also mount Results — that was the duplicate list/metrics after #6.
*/
export const STAGE_TABS = ["viewport", "script", "timeline", "results", "diff"] as const;
export type StageTab = (typeof STAGE_TABS)[number];
Expand Down Expand Up @@ -70,6 +71,28 @@ export const INSPECTOR_TABS = [
] as const;
export type InspectorTab = (typeof INSPECTOR_TABS)[number];

/**
* Inspector tabs the drawer may show for a given stage tab.
*
* When the stage is already Results, the Results inspector tab is omitted so
* the same `ResultsPanel` is not mounted twice. Every other inspector tab
* stays; the e2e still addresses them with `[data-inspector-tab]`.
*/
export function inspectorTabsFor(stage: StageTab): readonly InspectorTab[] {
return stage === "results" ? INSPECTOR_TABS.filter((tab) => tab !== "results") : INSPECTOR_TABS;
}

/**
* The inspector panel that actually mounts.
*
* A URL that carries `tab=results&itab=results` (the defaults stacked) must
* not render two geometry lists. Properties is the next tab in the closed
* inventory and is already a statement about the pinned artifact.
*/
export function effectiveInspectorTab(stage: StageTab, tab: InspectorTab): InspectorTab {
return stage === "results" && tab === "results" ? "properties" : tab;
}

export const PIN_MODES = ["current", "pinned"] as const;
export type PinMode = (typeof PIN_MODES)[number];

Expand Down
29 changes: 29 additions & 0 deletions web/test/rail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import type { ReactElement } from "react";

import type { GitDirtyEntry } from "../src/api/types";
import { GitDirtyView, dirtySide, type DirtyIndex } from "../src/components/rail/GitDirty";
import {
PROJECT_TREE_SECTIONS,
ProjectSectionList,
} from "../src/components/rail/ProjectTree";

const here = dirname(fileURLToPath(import.meta.url));
const pathCss = readFileSync(
Expand Down Expand Up @@ -90,3 +94,28 @@ describe("GitDirty.module.css — the wrapping the screenshot named", () => {
expect(pathCss).not.toMatch(/word-break:\s*break-all/);
});
});

describe("project tree sections — closed list, empty-honest", () => {
it("lists the closed inventory even when every section is empty", () => {
const host = render(<ProjectSectionList open={new Set()} onToggle={() => undefined} />);
const rows = [...host.querySelectorAll('[data-tree-row="section"]')];
expect(rows.map((node) => node.getAttribute("data-tree-section"))).toEqual([
...PROJECT_TREE_SECTIONS,
]);
for (const row of rows) {
expect(row.getAttribute("aria-expanded")).toBe("false");
}
expect(host.querySelector("[data-tree-section-empty]")).toBeNull();
expect(host.querySelector("[data-source]")).toBeNull();
});

it("does not invent a catalog when a section is opened", () => {
const host = render(
<ProjectSectionList open={new Set(["materials"])} onToggle={() => undefined} />,
);
const empty = host.querySelector('[data-tree-section-empty="materials"]');
expect(empty).not.toBeNull();
expect(empty?.querySelector("[data-source]")).toBeNull();
expect(host.querySelectorAll("[data-tree-section-empty]")).toHaveLength(1);
});
});
23 changes: 23 additions & 0 deletions web/test/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
import { describe, expect, it } from "vitest";
import {
DEFAULT_STATE,
INSPECTOR_TABS,
PinAuthorityError,
WorkspaceStore,
clampExplode,
decodeWorkspaceUrl,
effectiveInspectorTab,
encodeWorkspaceUrl,
inspectorTabsFor,
isView,
sameState,
type WorkspaceState,
Expand Down Expand Up @@ -165,6 +168,26 @@ describe("URL serialization", () => {
}
});

it("omits the inspector Results tab when the stage is already Results", () => {
expect(inspectorTabsFor("viewport")).toEqual(INSPECTOR_TABS);
expect(inspectorTabsFor("script")).toEqual(INSPECTOR_TABS);
expect(inspectorTabsFor("results")).toEqual([
"properties",
"provenance",
"checks",
"dfm",
"export",
"sourcing",
]);
expect(inspectorTabsFor("results")).not.toContain("results");
});

it("does not mount inspector Results when the stage tab is Results", () => {
expect(effectiveInspectorTab("viewport", "results")).toBe("results");
expect(effectiveInspectorTab("results", "results")).toBe("properties");
expect(effectiveInspectorTab("results", "checks")).toBe("checks");
});

it("falls back closed on a value outside a closed vocabulary", () => {
// A URL is user input. An unknown tab does not widen the vocabulary and
// does not throw the workspace away; it lands on the default.
Expand Down
Loading