Skip to content

Commit f242cb2

Browse files
authored
feat(ui): plan page in tabs, folder lineage and readable job graphs (#1442)
* feat(ui): drop the plan page's side panel The plan takes the full width. Permission problems already show next to the Run button, so the Permissions panel only repeated them, and the command's options now show beside the plan's summary. * feat(ui): state the plan in one sentence and list its checks in a tab * feat(ui): draw a large lineage as folders that open into their nodes * feat(ui): wrap a job graph's tall columns so large jobs stay readable
1 parent 6730e20 commit f242cb2

9 files changed

Lines changed: 645 additions & 107 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<script lang="ts">
2+
import FolderIcon from '@lucide/svelte/icons/folder';
3+
import ChevronRightIcon from '@lucide/svelte/icons/chevron-right';
4+
import { Handle, Position, type NodeProps } from '@xyflow/svelte';
5+
import type { GroupCard } from '$lib/lineage/catalog-graph';
6+
7+
let { data }: NodeProps = $props();
8+
const d = $derived(data as GroupCard);
9+
</script>
10+
11+
<!-- A collapsed folder; clicking it opens the folder into its nodes. -->
12+
<div class="group" class:dimmed={d.dimmed} title="Show the {d.count} nodes in {d.group}">
13+
<Handle type="target" position={Position.Left} class="node-handle" />
14+
<div class="head">
15+
<FolderIcon size={14} strokeWidth={1.75} class="glyph" />
16+
<span class="name">{d.group}</span>
17+
<span class="count">{d.count}</span>
18+
<ChevronRightIcon size={13} class="glyph" />
19+
</div>
20+
<div class="status">
21+
{#if d.ok}<span><i style:background="var(--sb-success)"></i>{d.ok} ok</span>{/if}
22+
{#if d.stale}<span><i style:background="var(--sb-stale)"></i>{d.stale} stale</span>{/if}
23+
{#if d.failed}<span><i style:background="var(--sb-error)"></i>{d.failed} failed</span>{/if}
24+
{#if !d.ok && !d.stale && !d.failed}<span class="faint">No builds</span>{/if}
25+
</div>
26+
<Handle type="source" position={Position.Right} class="node-handle" />
27+
</div>
28+
29+
<style>
30+
.group {
31+
width: 236px;
32+
border: 1px solid var(--node-border);
33+
border-radius: 2px;
34+
background: color-mix(in srgb, var(--card) 70%, var(--sb-inset));
35+
box-shadow: 3px 3px 0 -1px var(--card), 3px 3px 0 0 var(--node-border);
36+
color: var(--foreground);
37+
cursor: pointer;
38+
font-family: var(--font-sans);
39+
transition: opacity 0.15s, border-color 0.15s;
40+
}
41+
.group:hover {
42+
border-color: color-mix(in srgb, var(--foreground) 35%, transparent);
43+
}
44+
.group.dimmed {
45+
opacity: 0.35;
46+
}
47+
.head {
48+
display: flex;
49+
height: 34px;
50+
align-items: center;
51+
gap: 8px;
52+
padding: 0 10px;
53+
}
54+
.head :global(.glyph) {
55+
flex: 0 0 auto;
56+
color: var(--muted-foreground);
57+
}
58+
.name {
59+
min-width: 0;
60+
flex: 1;
61+
overflow: hidden;
62+
font-size: 12.5px;
63+
font-weight: 600;
64+
text-overflow: ellipsis;
65+
white-space: nowrap;
66+
}
67+
.count {
68+
color: var(--sb-text-faint);
69+
font-size: 11px;
70+
}
71+
.status {
72+
display: flex;
73+
gap: 10px;
74+
padding: 0 10px 8px 32px;
75+
color: var(--muted-foreground);
76+
font-size: 11px;
77+
}
78+
.status span {
79+
display: inline-flex;
80+
align-items: center;
81+
gap: 5px;
82+
}
83+
.status i {
84+
width: 6px;
85+
height: 6px;
86+
border-radius: 50%;
87+
}
88+
.faint {
89+
color: var(--sb-text-faint);
90+
}
91+
.group :global(.node-handle) {
92+
width: 6px;
93+
height: 6px;
94+
min-width: 0;
95+
min-height: 0;
96+
border: 0;
97+
background: transparent;
98+
}
99+
</style>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { describe, expect, it } from 'vitest';
2+
import type { CatalogNode } from '$lib/api';
3+
import { folderOf, groupedGraph } from './catalog-graph';
4+
5+
function node(key: string, path: string, upstream: string[] = [], extra: Partial<CatalogNode> = {}): CatalogNode {
6+
const kind = key.startsWith('source:') ? 'source' : key.startsWith('seed:') ? 'seed' : 'table';
7+
return { key, kind, path, upstream, group: null, stale: [], lastOutcome: null, lastBuild: { builtAt: '2026-11-07T06:00:00Z' }, ...extra } as CatalogNode;
8+
}
9+
10+
describe('lineage folders', () => {
11+
it('groups models by folder, sources by file, and lets a declared group win', () => {
12+
expect([
13+
folderOf(node('model:dim_orders', 'models/marts/core/dim_orders.sql')),
14+
folderOf(node('source:shop__orders', 'sources/shop.yml')),
15+
folderOf(node('seed:countries', 'seeds/countries.csv')),
16+
folderOf(node('model:orders', 'orders.sql')),
17+
folderOf(node('model:stg_orders', 'models/staging/stg_orders.sql', [], { group: 'shop' }))
18+
]).toEqual(['marts/core', 'sources/shop', 'seeds', 'models', 'shop']);
19+
});
20+
21+
const nodes = [
22+
node('source:shop__orders', 'sources/shop.yml'),
23+
node('source:shop__customers', 'sources/shop.yml'),
24+
node('model:stg_orders', 'models/staging/shop/stg_orders.sql', ['source:shop__orders']),
25+
node('model:stg_customers', 'models/staging/crm/stg_customers.sql', ['source:shop__customers'], { stale: [{ reason: 'behind', upstream: [], detail: '', since: '' }] }),
26+
node('model:orders', 'models/marts/orders.sql', ['model:stg_orders', 'model:stg_customers'], { lastOutcome: 'failed' }),
27+
node('model:order_totals', 'models/marts/order_totals.sql', ['model:orders'])
28+
];
29+
30+
it('draws each closed top folder once, with one edge per folder pair and none inside a folder', () => {
31+
const graph = groupedGraph(nodes, new Set());
32+
expect(graph.nodes.map((n) => [n.id, n.data.count])).toEqual([
33+
['group:sources', 2],
34+
['group:staging', 2],
35+
['group:marts', 2]
36+
]);
37+
expect(graph.edges.map((e) => e.id)).toEqual(['group:sources-group:staging', 'group:staging-group:marts']);
38+
expect(graph.nodes.map((n) => [n.data.ok, n.data.stale, n.data.failed])).toEqual([[0, 0, 0], [1, 1, 0], [1, 0, 1]]);
39+
});
40+
41+
it('opens a folder into the folders inside it, and those into their nodes, joined to the closed folders around them', () => {
42+
expect(groupedGraph(nodes, new Set(['staging'])).nodes.map((n) => n.id)).toEqual(['group:sources', 'group:staging/shop', 'group:staging/crm', 'group:marts']);
43+
const graph = groupedGraph(nodes, new Set(['staging', 'staging/shop']));
44+
expect(graph.nodes.map((n) => n.id)).toEqual(['group:sources', 'model:stg_orders', 'group:staging/crm', 'group:marts']);
45+
expect(graph.edges.map((e) => e.id)).toEqual([
46+
'group:sources-model:stg_orders',
47+
'group:sources-group:staging/crm',
48+
'model:stg_orders-group:marts',
49+
'group:staging/crm-group:marts'
50+
]);
51+
});
52+
53+
it('draws every node once all folders around it are open', () => {
54+
const graph = groupedGraph(nodes, new Set(['sources', 'sources/shop', 'staging', 'staging/shop', 'staging/crm', 'marts']));
55+
expect(graph.nodes.every((n) => n.type === 'asset')).toBe(true);
56+
expect(graph.edges).toHaveLength(5);
57+
});
58+
});

‎ui/src/lib/lineage/catalog-graph.ts‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,83 @@ export function catalogGraph(nodes: CatalogNode[]): { nodes: Node[]; edges: Edge
5757
edges: nodes.flatMap((n) => n.upstream.map((up) => ({ id: `${up}-${n.key}`, source: up, target: n.key, type: 'bezier' })))
5858
};
5959
}
60+
61+
/** Above this many nodes the lineage opens with each folder collapsed into one card. */
62+
export const GROUPED_ABOVE = 150;
63+
64+
/**
65+
* The folder a node lives in, such as `marts/core`, or its source file, such as `sources/orders`;
66+
* a declared group wins.
67+
*/
68+
export function folderOf(node: CatalogNode): string {
69+
if (node.group) return node.group;
70+
const path = node.path.replace(/^models\//, '');
71+
if (node.kind === 'source') return path.replace(/\.[^./]+$/, '') || 'sources';
72+
const slash = path.lastIndexOf('/');
73+
return slash > 0 ? path.slice(0, slash) : node.kind === 'seed' ? 'seeds' : 'models';
74+
}
75+
76+
export type GroupCard = { group: string; count: number; ok: number; stale: number; failed: number; dimmed?: boolean };
77+
78+
const groupId = (group: string) => `group:${group}`;
79+
80+
/** A folder's card: how many nodes it holds, and how many last built fine, are stale or failed. */
81+
function groupCard(group: string, members: CatalogNode[]): GroupCard {
82+
const built = members.filter((n) => n.kind !== 'source');
83+
return {
84+
group,
85+
count: members.length,
86+
ok: built.filter((n) => cardStatus(n) === 'ok' && !n.stale?.length).length,
87+
stale: built.filter((n) => !!n.stale?.length).length,
88+
failed: built.filter((n) => n.lastOutcome === 'failed').length
89+
};
90+
}
91+
92+
/** `expanded` with every folder around the node open, so the node itself is drawn. */
93+
export function withFoldersOpen(node: CatalogNode, expanded: ReadonlySet<string>): Set<string> {
94+
const parts = folderOf(node).split('/');
95+
return new Set([...expanded, ...parts.map((_, i) => parts.slice(0, i + 1).join('/'))]);
96+
}
97+
98+
/** The outermost folder around a node that is not open, or null when every folder around it is. */
99+
function closedFolder(node: CatalogNode, expanded: ReadonlySet<string>): string | null {
100+
const parts = folderOf(node).split('/');
101+
for (let depth = 1; depth <= parts.length; depth++) {
102+
const folder = parts.slice(0, depth).join('/');
103+
if (!expanded.has(folder)) return folder;
104+
}
105+
return null;
106+
}
107+
108+
/**
109+
* The lineage with every folder that is not open drawn as one card. Folders nest, so opening
110+
* `marts` shows `marts/core` and the other folders inside it. An edge joins whatever stands for
111+
* each end, once per pair, and an edge inside a closed folder disappears.
112+
*/
113+
export function groupedGraph(nodes: CatalogNode[], expanded: ReadonlySet<string>): { nodes: Node[]; edges: Edge[] } {
114+
const standIn = new Map<string, string>();
115+
const folders = new Map<string, CatalogNode[]>();
116+
const cards: Node[] = [];
117+
for (const n of nodes) {
118+
const folder = closedFolder(n, expanded);
119+
standIn.set(n.key, folder === null ? n.key : groupId(folder));
120+
if (folder === null) cards.push({ id: n.key, type: 'asset', position: { x: 0, y: 0 }, data: cardData(n) });
121+
else if (folders.has(folder)) folders.get(folder)!.push(n);
122+
else {
123+
folders.set(folder, [n]);
124+
cards.push({ id: groupId(folder), type: 'folder', position: { x: 0, y: 0 }, selectable: false, data: {} });
125+
}
126+
}
127+
for (const card of cards) if (card.type === 'folder') card.data = groupCard(card.id.slice('group:'.length), folders.get(card.id.slice('group:'.length))!);
128+
const pairs = new Map<string, Edge>();
129+
for (const n of nodes) {
130+
for (const up of n.upstream) {
131+
const source = standIn.get(up);
132+
const target = standIn.get(n.key)!;
133+
if (!source || source === target) continue;
134+
const id = `${source}-${target}`;
135+
if (!pairs.has(id)) pairs.set(id, { id, source, target, type: 'bezier' });
136+
}
137+
}
138+
return { nodes: cards, edges: [...pairs.values()] };
139+
}

‎ui/src/lib/lineage/job-graph.test.ts‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,63 @@ describe('job graph', () => {
7272
expect(laid.find((n) => n.id === boxId('staging'))!.height).toBeLessThan(61);
7373
});
7474

75+
it('wraps a tall column into several, keeping every node right of what it reads', () => {
76+
// 40 marts with no lineage inside the job, and 30 models off one source: 71 cards, at most 15 to a column.
77+
const wide = [
78+
...Array.from({ length: 40 }, (_, i) => node(`model:mart_${i}`)),
79+
node('model:src'),
80+
...Array.from({ length: 30 }, (_, i) => node(`model:stg_${i}`, ['model:src']))
81+
];
82+
const { nodes, edges } = jobGraph(wide.map((n) => n.key), wide);
83+
const laid = layoutJobGraph(measured(nodes), edges);
84+
const columns = Map.groupBy(laid, (n) => Math.round(n.position.x));
85+
expect(Math.max(...[...columns.values()].map((c) => c.length))).toBeLessThanOrEqual(15);
86+
// The wrapped columns sit side by side rather than staggered: the graph is no taller than one full column.
87+
const ys = laid.map((n) => n.position.y);
88+
expect(Math.max(...ys) - Math.min(...ys)).toBeLessThan(15 * (61 + 24));
89+
const x = (id: string) => laid.find((n) => n.id === id)!.position.x;
90+
for (let i = 0; i < 30; i++) expect(x(`model:stg_${i}`)).toBeGreaterThan(x('model:src'));
91+
});
92+
93+
it('leaves a graph that needs no wrapping as dagre lays it out', () => {
94+
// `extra` only feeds the end of a long chain, so it sits just before it, not back at the start.
95+
const chain = [node('model:a'), node('model:b', ['model:a']), node('model:c', ['model:b']), node('model:d', ['model:c']), node('model:extra'), node('model:end', ['model:d', 'model:extra'])];
96+
const { nodes, edges } = jobGraph(chain.map((n) => n.key), chain);
97+
const x = new Map(layoutJobGraph(measured(nodes), edges).map((n) => [n.id, n.position.x]));
98+
expect(x.get('model:extra')).toBe(x.get('model:d'));
99+
});
100+
101+
it('keeps every box right of the boxes it runs after when their columns wrap', () => {
102+
const many = (job: string) => Array.from({ length: 30 }, (_, i) => node(`model:${job}_${i}`));
103+
const wide = [...many('a'), ...many('b')];
104+
const groupBoxes = [
105+
{ jobKey: 'a', nodes: wide.slice(0, 30).map((n) => n.key) },
106+
{ jobKey: 'b', nodes: wide.slice(30).map((n) => n.key) },
107+
{ jobKey: 'empty', nodes: [] }
108+
];
109+
const after = (jobKey: string) => ({ jobKey, upstream: [{ jobKey: 'a', source: 'after' as const }], stage: 1 });
110+
const { nodes, edges } = jobGraph(wide.map((n) => n.key), wide, groupBoxes, [{ jobKey: 'a', upstream: [], stage: 0 }, after('b'), after('empty')]);
111+
const laid = layoutJobGraph(measured(nodes), edges);
112+
const box = (k: string) => laid.find((n) => n.id === boxId(k))!;
113+
expect(box('a').height).toBeLessThan(15 * (61 + 24) + 60);
114+
expect(box('b').position.x).toBeGreaterThan(box('a').position.x + box('a').width!);
115+
expect(box('empty').position.x).toBeGreaterThan(box('a').position.x + box('a').width!);
116+
});
117+
118+
it('keeps lineage left to right when it leaves a box and comes back', () => {
119+
// `broad` builds raw → stg → mart, but `narrow` builds only stg, so stg sits in narrow's box.
120+
const chain = [node('model:raw'), node('model:stg', ['model:raw']), node('model:mart', ['model:stg'])];
121+
const nested = [{ jobKey: 'broad', nodes: chain.map((n) => n.key) }, { jobKey: 'narrow', nodes: ['model:stg'] }];
122+
const { nodes, edges } = jobGraph(chain.map((n) => n.key), chain, nested);
123+
const laid = layoutJobGraph(measured(nodes), edges);
124+
const x = (id: string) => {
125+
const card = laid.find((n) => n.id === id)!;
126+
return card.position.x + (laid.find((n) => n.id === card.parentId)?.position.x ?? 0);
127+
};
128+
expect(x('model:raw')).toBeLessThan(x('model:stg'));
129+
expect(x('model:stg')).toBeLessThan(x('model:mart'));
130+
});
131+
75132
it('draws a plain job without boxes', () => {
76133
const { nodes } = jobGraph(['model:raw', 'model:stg'], catalog);
77134
expect(nodes.map((n) => [n.id, n.type, n.parentId])).toEqual([

0 commit comments

Comments
 (0)