Skip to content

Commit 19fe03b

Browse files
agorischekCopilot
andcommitted
Host core: a headless view model every UI shares
Which views a host offers and which controls show were worked out separately in the default UI, the VS Code UI and the Playground's Primer UI, and the copies had drifted. They are now the core's (`view-model.ts`), with one default each and typed options to change it: - `offeredViews`, `shownView`, `recoveryView`, `viewLabel` and the `useViewChoice` hook; - `viewControls(projection, {features, view, playbackInViews?})`: the modes and mode switch, scope, playback, zoom and the varied toggle; - `scopeChoice`: the scope switch's options, titles and "nothing hidden" note; - `summaryToggle`, `summaryToggleTitle` and `summaryFactTitle`; - `ProjectionFeatures`, `featureOn`, `offeredModes` and `rendererLabel`, moved from the default UI. Playback now shows only in the Animated mode, in every view, as the VS Code UI and Primer already did; the default UI showed it beside the table and text views in every mode. `playbackInViews: 'always'` keeps that. The default UI's zoom group, like the VS Code UI's, now also needs `rendererControls`. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 6046adc commit 19fe03b

25 files changed

Lines changed: 521 additions & 288 deletions

‎docs/guides/host-core.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,47 @@ calling `close`, or clicking outside the card (inside `container` or outside
250250
`view`, while toolbar clicks and popovers keep it open) dismisses it and
251251
restores focus, leaving the item selected until a new selection reopens it.
252252

253+
## The view model
254+
255+
A host UI decides which views it offers and which controls show. The core makes
256+
those decisions once, so every UI (the default UI, the VS Code UI and yours)
257+
shares the same defaults, and a host changes them only through the options
258+
below.
259+
260+
- `offeredViews(projection, features)`: the renderer's view when there is one,
261+
then the table and text views the features keep; never empty.
262+
`useViewChoice(projection, features, initialView)` is the stateful part:
263+
`{views, view, setView, recoverView}`. It shows `initialView` when offered,
264+
else the first view, and shows the renderer's view when a renderer arrives
265+
where there was none. `recoverView` is the built-in view to offer when the
266+
renderer fails. `viewLabel` names a view ("Built-in table view").
267+
- `viewControls(projection, {features, view, playbackInViews?})` says what
268+
shows:
269+
- `modes` and `modeSwitch`: the modes the features offer that the renderer
270+
supports, in its order; the switch shows comparing, in the renderer's view,
271+
with more than one;
272+
- `scope`: comparing, with `changesOnly` on;
273+
- `playback`: comparing, with `playback` on, **in the Animated mode only, in
274+
every view**. `playbackInViews: 'always'` also shows it beside the table and
275+
text views in the other modes, which present the transition's progress too;
276+
- `zoom` and `zoomControls`: the renderer's `zoom` group, with both `zoom` and
277+
`rendererControls` on, in the renderer's view; no controls to draw while the
278+
renderer has failed;
279+
- `varied`: the varied toggle belongs in the toolbar only when something
280+
varied and there is no summary bar.
281+
- `scopeChoice(projection)`: what a scope switch offers. `options` are Changes
282+
and All, and Noise while it is the scope, each with its `label` and a `title`
283+
ending in its count; `nothingHidden` says to show the note "Changes · nothing
284+
hidden" instead, with `noteTitle`.
285+
- `summaryToggle(applied, figure, status?)` is a summary figure's filter toggle
286+
(`{pressed, next}`), `summaryToggleTitle` its tooltip, and `summaryFactTitle`
287+
a fact's.
288+
- `ProjectionFeatures`, `featureOn`, `offeredModes` and `rendererLabel` are the
289+
feature switches every UI takes.
290+
291+
The default scope is Changes (`changesOnly`, which a definition's
292+
`presentation.changesOnly: false` turns off).
293+
253294
## Targets, annotations and anchors
254295

255296
These primitives let you attach application data—like pull request comments—to

‎docs/guides/host-ui.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ The toolbar is organized into three regions from start to end:
3232
`toolbarStart`).
3333
- **Center:** the comparison mode switch (showing `availableModes`, hidden when
3434
only one mode exists; Animated uses a clapperboard icon so no mode icon looks
35-
like a play, pause, or step button), plus playback controls in animated mode
36-
and alongside table/text views—**one round play button**, compact step
37-
buttons, a flexible "Transition" slider, and a fixed-width percentage readout.
35+
like a play, pause, or step button), plus playback controls in animated mode,
36+
beside every view (`playbackInViews: 'always'` also shows them beside the
37+
table and text views in the other modes)—**one round play button**, compact
38+
step buttons, a flexible "Transition" slider, and a fixed-width percentage
39+
readout.
3840
- **End:**
3941
1. When viewing Table or Text, a one-click return chip ("Table ×", labeled
4042
"Showing table; show the Graph renderer", or simply what is shown when no
@@ -144,7 +146,9 @@ so mouse wheels continue scrolling the page. Use `features` to disable
144146
individual blocks (`playback`, `modes`, `highlighting`, `changesOnly`, `search`,
145147
`rendererChoice`, `speed`, `rendererControls`, `zoom`, `table`, `text`, `info`,
146148
`fullscreen`, `title`, `annotations`, `summary`), and `actions` to inject custom
147-
toolbar items.
149+
toolbar items. Which views and controls show follows the core's view model
150+
(`viewControls`, in [the core guide](host-core.md#the-view-model)), the same in
151+
the VS Code UI.
148152

149153
### The summary bar
150154

‎packages/host/core/browser/modes.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ test('side by side shows both revisions in labeled panes, without playback contr
3636
await expect(entity(pane(page, 'before'), 'legacy')).toBeVisible()
3737
await expect(pane(page, 'after').locator('[data-entity-id="legacy"]')).toHaveCount(0)
3838
await expect(entity(pane(page, 'after'), 'audit')).toBeVisible()
39-
// The table and text views keep the host's playback.
39+
// Playback is Animated's: the table and text views have none in side by side either.
4040
await showAs(page, 'Table')
41-
await expect(page.getByRole('group', {name: 'Comparison playback'})).toBeVisible()
41+
await expect(page.getByRole('group', {name: 'Comparison playback'})).toHaveCount(0)
4242
await expect(modeControls(page)).toHaveCount(0)
4343
})
4444

‎packages/host/core/src/index.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,31 @@ export {
5959
sameSummaryFilter,
6060
summaryFigures,
6161
summaryFilterable,
62+
summaryFactTitle,
6263
summaryFilterOf,
64+
summaryToggle,
65+
summaryToggleTitle,
6366
useSummaryFit,
6467
} from './summary.js'
6568
export type {SummaryFigure, SummaryFilter, SummaryKind} from './summary.js'
6669
export {chooseFitPlan, fitWidth, toolbarHysteresis, useFitPlan} from './fit-plan.js'
6770
export type {FitChoice, FitHysteresis, FitPlanOptions} from './fit-plan.js'
71+
export {
72+
featureOn,
73+
offeredModes,
74+
offeredViews,
75+
recoveryView,
76+
rendererLabel,
77+
scopeChoice,
78+
scopeNames,
79+
shownView,
80+
viewControls,
81+
viewLabel,
82+
viewNotices,
83+
} from './view-model.js'
84+
export type {FeatureName, ProjectionFeatures, ScopeChoice, ScopeOption, ViewControls, ViewControlsOptions, ViewKind} from './view-model.js'
85+
export {useViewChoice} from './view-choice.js'
86+
export type {ViewChoice} from './view-choice.js'
6887
export {rowDetails} from './details.js'
6988
export {changeContextItems} from './context-items.js'
7089
export type {ContextItems} from './context-items.js'

‎packages/host/core/src/summary.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,28 @@ export function sameSummaryFilter(a: SummaryFilter | null | undefined, b: Summar
124124
return a.status === b.status && kinds(a) === kinds(b) && ids(a) === ids(b)
125125
}
126126

127+
/**
128+
* A summary filter toggle: a figure's total (`status` omitted) or one of its change counts. `pressed` while its filter
129+
* is the one applied; `next` is the filter pressing it applies, `null` (every item) when it is pressed.
130+
*/
131+
export function summaryToggle(
132+
applied: SummaryFilter | null,
133+
figure: SummaryFigure,
134+
status?: SummaryDelta,
135+
): {pressed: boolean; next: SummaryFilter | null} {
136+
const filter = summaryFilterOf(figure, status)
137+
const pressed = sameSummaryFilter(applied, filter)
138+
return {pressed, next: pressed ? null : filter}
139+
}
140+
141+
/** What pressing a filter toggle does, as its tooltip: `Show every item` while it is pressed, else `Show only the tables`. */
142+
export const summaryToggleTitle = (figure: SummaryFigure, pressed: boolean): string =>
143+
pressed ? 'Show every item' : `Show only the ${figure.noun.plural}`
144+
145+
/** A fact's tooltip: its description, then, when it filters (`pressed` given), what pressing it does. */
146+
export const summaryFactTitle = (figure: SummaryFigure, pressed?: boolean): string | undefined =>
147+
[figure.description, pressed === undefined ? undefined : summaryToggleTitle(figure, pressed)].filter(Boolean).join('\n') || undefined
148+
127149
/**
128150
* The figures as the summary bar's one sentence (`12 workspaces +1 −1 · 18 dependencies +2 · 1 newly enforced`), for
129151
* text and labels: counts and facts alike, each with its changes in a comparison.

‎packages/host/core/src/ui/about.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {Diagnostic} from '@githubnext/projections-schemas'
33
import type {ProjectionController} from '../projection.js'
44
import {Badge} from './components/badge.js'
55
import {cn} from './lib/utils.js'
6-
import {rendererLabel} from './features.js'
6+
import {rendererLabel} from '../view-model.js'
77
import {ToolbarPopover} from './toolbar-popover.js'
88

99
/** Limitations the extractions declare in `metadata.limitations`. */

‎packages/host/core/src/ui/blocks.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The building blocks, one module per concern (features, toolbar, pickers, view controls, playback, settings, about,
22
// full screen), gathered under their public names.
3-
export {featureOn, offeredModes, rendererLabel} from './features.js'
4-
export type {ProjectionFeatures, ViewKind} from './features.js'
3+
export {featureOn, offeredModes, rendererLabel} from '../view-model.js'
4+
export type {ProjectionFeatures, ViewKind} from '../view-model.js'
55
export {MoreMenu, MoreSection, Toolbar, ToolbarRow} from './toolbar.js'
66
export {PairPicker} from './pickers.js'
77
export type {PairForm} from './pickers.js'

‎packages/host/core/src/ui/explorer.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface ComparisonExplorerProps
4141
| 'controllerRef'
4242
| 'onProgressChange'
4343
| 'initialView'
44+
| 'playbackInViews'
4445
| 'progress'
4546
| 'playing'
4647
| 'onPlayingChange'
@@ -229,6 +230,7 @@ export function ComparisonExplorer(props: ComparisonExplorerProps) {
229230
swipePosition={props.swipePosition ?? swipe}
230231
onSwipePositionChange={changeSwipe}
231232
{...(props.initialView ? {initialView: props.initialView} : {})}
233+
{...(props.playbackInViews ? {playbackInViews: props.playbackInViews} : {})}
232234
/>
233235
)}
234236
</ScopedRoot>

‎packages/host/core/src/ui/features.ts‎

Lines changed: 0 additions & 64 deletions
This file was deleted.

‎packages/host/core/src/ui/scope-switch.tsx‎

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import type {ViewScope} from '@githubnext/projections-renderer-sdk/presentation'
22
import type {ProjectionController} from '../projection.js'
3-
import {nothingHiddenTitle} from '../scope.js'
3+
import {scopeChoice} from '../view-model.js'
44
import {SegmentedControl, SegmentedControlItem} from './components/segmented-control.js'
55
import {cn} from './lib/utils.js'
66

7-
const scopeNames: Record<ViewScope, {label: string; title: string}> = {
8-
changes: {label: 'Changes', title: 'Show the changes and what they need to be read, folding the rest'},
9-
all: {label: 'All', title: 'Show every item'},
10-
noise: {label: 'Noise', title: 'Show only the items that varied within tolerance or were regenerated'},
11-
}
12-
137
/**
148
* The "Scope" radio group (arrow keys select): Changes and All, their counts in the tooltip ("… (4)"), and Noise while
159
* it is the scope (chosen from Settings or the summary bar). When the Changes scope hides nothing, a note says so
@@ -18,8 +12,7 @@ const scopeNames: Record<ViewScope, {label: string; title: string}> = {
1812
export function ScopeSwitch({projection: p}: {projection: ProjectionController}) {
1913
if (!p.comparing) return null
2014
// Every item is a change or gives one context: Changes and All show the same, so there is nothing to switch.
21-
const nothingHidden = !p.scopeCounts.hidden && p.scope !== 'noise'
22-
const scopes: ViewScope[] = p.scope === 'noise' ? ['changes', 'all', 'noise'] : ['changes', 'all']
15+
const {nothingHidden, noteTitle, options} = scopeChoice(p)
2316
// Both forms share one cell, the other one invisible, so the slot keeps its width when the form changes.
2417
const form = (shown: boolean) => cn('pj:col-start-1 pj:row-start-1', !shown && 'pj:invisible')
2518
return (
@@ -29,7 +22,7 @@ export function ScopeSwitch({projection: p}: {projection: ProjectionController})
2922
'ph-scope ph-scope-note pj:inline-flex pj:h-8 pj:shrink-0 pj:items-center pj:gap-1.5 pj:px-2 pj:text-sm pj:text-muted-foreground',
3023
form(nothingHidden),
3124
)}
32-
title={`${nothingHiddenTitle} (${p.scopeCounts.changes.toLocaleString()})`}
25+
title={noteTitle}
3326
data-scope="none"
3427
aria-hidden={!nothingHidden || undefined}
3528
>
@@ -44,20 +37,11 @@ export function ScopeSwitch({projection: p}: {projection: ProjectionController})
4437
onValueChange={value => p.setScope(value as ViewScope)}
4538
className={cn('ph-scope pj:shrink-0', form(!nothingHidden))}
4639
>
47-
{scopes.map(scope => {
48-
const {label, title} = scopeNames[scope]
49-
return (
50-
<SegmentedControlItem
51-
key={scope}
52-
value={scope}
53-
data-scope={scope}
54-
title={`${title} (${p.scopeCounts[scope].toLocaleString()})`}
55-
className="pj:px-2"
56-
>
57-
<span className="ph-scope-label">{label}</span>
58-
</SegmentedControlItem>
59-
)
60-
})}
40+
{options.map(({scope, label, title}) => (
41+
<SegmentedControlItem key={scope} value={scope} data-scope={scope} title={title} className="pj:px-2">
42+
<span className="ph-scope-label">{label}</span>
43+
</SegmentedControlItem>
44+
))}
6145
</SegmentedControl>
6246
</span>
6347
)

0 commit comments

Comments
 (0)