Skip to content
Open
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
5 changes: 5 additions & 0 deletions changelog.d/402-kit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
section: kit
---

- **`useMassFolds` folds mass changes for a renderer with its own layout** (#402). `useMassFolds(props)` from `@githubnext/projections-renderer-kit/react` returns the props to draw, with `model` and `schedule` folded (`foldMassChanges`), emphasis, selection and focus requests moved onto each fold's card, and `onSelect` of a fold or its links opening it, along with the items each closed fold presents (`aliases`) for its `data-entity-aliases`. `GraphCanvas` folds through the same hook. See [the graph canvas guide](docs/guides/renderer-kit-graphs.md).
5 changes: 5 additions & 0 deletions changelog.d/402.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
section: renderers
---

- **The database renderer folds a dozen or more tables removed together into one card** (#402). A comparison that removes a whole set of tables (48 in one schema) used to draw every removed table, which could make the frame too tall to render as an image. The database renderer now draws one card in the removed style, such as "48 tables removed", worded with the definition's noun, and draws each foreign key or enum type from those tables to what stays once from its header. Views and enums fold the same way, and a dozen or more columns or keys removed from a table that stays fold into one row of it ("17 columns removed"). Activating a fold opens its items in place. The host's selection, hover, filter and focus (`--entity`) of a folded item find the fold. Additions of a dozen or more fold the same way.
9 changes: 9 additions & 0 deletions docs/guides/renderer-kit-graphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ status and kind from its `change` row, and a card a fold takes keeps its place,
hidden. A single revision folds nothing. `Fold` takes an `id` and the IDs it
`presents` for a fold the host can find its items on.

A renderer that lays out its own model, as the database renderer does, folds the
same way with `useMassFolds(props)`: it returns the props to draw (`model` and
`schedule` folded, emphasis, selection and focus request moved onto the cards,
and `onSelect` of a fold's card or link opening it) and, for each card (an
entity row whose ID `isMassFold`), the items it presents (`aliases`). Draw the
card in its status's style with its `label`, `data-fold`,
`data-projections-action` and `data-entity-aliases`, and draw a fold's links
without a `data-entity-id`, since they stand for no item of the host's.

**Sibling blocks.** When six or more cards (`blockMinimum`) share every
relationship, they wrap into a block instead of stretching their layer into one
long row. Sharing every relationship means having the same sources and targets,
Expand Down
169 changes: 165 additions & 4 deletions docs/reference/renderer-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,30 @@ A list with every run of items `shown` leaves out folded into one entry, keyed b
names is listed after its fold, `open`. A run of one item stays, as its fold would take as much room. Every item is shown when `shown` is
undefined. Fold the union of a comparison (or each pane's list in the union's order) so both revisions fold alike.

### `foldMassChanges`

```ts
foldMassChanges<X extends Extraction>(model: ComparisonModel<X>, options?: MassFoldOptions): MassFolded<X>
```

Folds every run of `minimum` or more sibling items removed together, or added together, into one card: items of
one kind with the same status in the same container (or at the top level, outside any) when the container itself
stays. The card takes their kind and status, so it is drawn in the removed (or added) style, and counts them with the
definition's noun (`48 tables removed`). It stands for the items, the parts they contain and the relationships among
them; a relationship from one of them to an item that stays is drawn once from the card, for each item, kind and
direction. Steps place the card and its links in the first step that changes what they stand for. A fold in `open`
draws its items, and its card stays, labeled `Hide 48 removed tables`, as the way to fold them again. A model with no
such run is returned as it is.

### `foldMassSteps`

```ts
foldMassSteps<S extends PresentedStep>(steps: Array<S>, folding: Pick<MassFolded<Extraction>, "folded" | "folds" | "stands">): Array<S>
```

Steps (a model's, or a schedule) with a fold's cards and links in place of what they stand for: each in the first
step that changes any of it, and in no other. A step left with nothing keeps its place, so timing doesn't move.

### `foldPrefix`

```ts
Expand Down Expand Up @@ -1951,6 +1975,14 @@ isKind(change: EntityChange<Entity>, ...kinds: Array<string>): false | true

Whether either version of the row has one of `kinds`, so a row that changed kind matches both.

### `isMassFold`

```ts
isMassFold(id: string): false | true
```

Whether an item is a card or link `foldMassChanges` adds.

### `isSortable`

```ts
Expand Down Expand Up @@ -2005,6 +2037,15 @@ kindNote(kind: KindLineText | undefined, inferred: false | true): string

The note after a kind line (the renderer's, then `Inferred`), or nothing.

### `kindNoun`

```ts
kindNoun(kind: string, kinds?: Record<string, RendererKind> | undefined, nouns?: Readonly<Record<string, SummaryKindCount | SummaryNoun | false>> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryKindCount | SummaryNoun | false | undefined }): SummaryNoun
```

A kind's words, as the summary bar words its count: the definition's noun (`presentation.kinds.<kind>.noun`), else
the renderer's (`SummaryNouns`), else the host's (`humanizeKind`).

### `kindText`

```ts
Expand Down Expand Up @@ -2177,6 +2218,89 @@ lineSpline(from: Point, to: Point): Spline

A straight segment as one cubic, so every route is a uniform chain.

### `MassFold`

```ts
interface MassFold
```

One fold of sibling items removed or added together.

| Member | Signature | Description |
|---|---|---|
| `id` | `"id": string` | The fold card's row ID (`massFoldPrefix`). |
| `items` | `"items": Array<string>` | The sibling entity rows it folds, in the model's order. |
| `kind` | `"kind": string` | The folded items' kind, which the card takes. |
| `label` | `"label": string` | The card's label: `48 tables removed`, or open, `Hide 48 removed tables`. |
| `open` | `"open": false \| true` | Whether it is open: its items drawn on their own, and the card the way to fold them again. |
| `presents` | `"presents": Array<string>` | Every row the card presents while closed: the siblings, the parts they contain and the relationships among them or to them, for the card's `data-entity-aliases`. |
| `status` | `"status": MassStatus` | Whether its items were removed or added: the card's status, and so its style. |

### `MassFolded`

```ts
interface MassFolded<X extends Extraction = Extraction>
```

A model with its mass changes folded (`foldMassChanges`), and what each fold stands for.

| Member | Signature | Description |
|---|---|---|
| `folded` | `"folded": ReadonlyMap<string, string>` | Each row a closed fold hides (entity or relationship), and the card or link drawn for it. |
| `folds` | `"folds": ReadonlyMap<string, MassFold>` | Each fold, by its card's ID; empty when nothing folds (and `model` is the one passed). |
| `model` | `"model": ComparisonModel<X>` | The model with each fold's card and links in place of what they stand for, steps included. |
| `stands` | `"stands": ReadonlyMap<string, Array<string>>` | Each card and link a fold adds, and the rows it stands for: their step and emphasis are its. |

### `massFoldLabel`

```ts
massFoldLabel(count: number, status: MassStatus, noun: SummaryNoun, open?: false | true, locale?: string): string
```

A fold's card label: `48 tables removed`; open, `Hide 48 removed tables`.

### `massFoldMinimum`

```ts
massFoldMinimum: 12
```

The fewest sibling items removed (or added) together that fold into one card: twice a sibling block's
`blockMinimum`, two full lines of its tray, past which more cards add height without saying more than their count.
It is also where a stack of removed database tables alone outgrows a frame: on one schema, 48 removed tables drew a
frame 81,546 px tall, about 1,700 px a table, so a dozen pass the 20,000 px most hosts render.

### `MassFoldOptions`

```ts
interface MassFoldOptions
```

How `foldMassChanges` folds.

| Member | Signature | Description |
|---|---|---|
| `locale` | `"locale"?: string` | BCP 47 locale for the count (`en-US` by default). |
| `minimum` | `"minimum"?: number` | The fewest siblings that fold (`massFoldMinimum` by default). |
| `noun` | `"noun"?: { (kind: string): SummaryNoun \| undefined }` | A kind's words (the definition's noun); `humanizeKind` by default. |
| `open` | `"open"?: ReadonlySet<string>` | Folds the person opened, by card ID: their items are drawn, and the card stays as the way to fold them again. |

### `massFoldPrefix`

```ts
massFoldPrefix: "pk-mass:"
```

The ID prefix of the cards and links `foldMassChanges` adds.

### `MassStatus`

```ts
type MassStatus = "added" | "removed"
```

The statuses that fold: items that only one revision has.

### `maxZoom`

```ts
Expand Down Expand Up @@ -3986,7 +4110,10 @@ The corner radius a graph card's shape is drawn with, in card units, where the t
CardGrid(__0: { "children": ReactNode; "label"?: string }): Element
```

Cards in a responsive grid: as many columns as fit, one on a phone.
Cards in a responsive grid: as many columns as fit, one on a phone. In a comparison, a dozen or more of its
`EntityCard`s removed (or added) together, of one kind, fold into one card that counts them and opens in place
(`GridFoldCard`), and a run of a dozen or more unchanged ones folds into a band across the grid (`GridBand`), except
under the Changes scope.

### `CategoriesView`

Expand Down Expand Up @@ -4302,12 +4429,14 @@ labels ("Runs on"), use `Facts` and `Fact`.
### `Fold`

```ts
Fold(__0: { "as"?: ElementType; "className"?: string; "columns"?: number; "count": number; "noun": string; "onToggle": { (): void }; "open"?: false | true | undefined }): Element
Fold(__0: { "as"?: ElementType; "className"?: string; "columns"?: number; "count": number; "id"?: string | undefined; "noun": string; "onToggle": { (): void }; "open"?: false | true | undefined; "presents"?: Array<string> | undefined }): Element
```

A fold: "12 unchanged declarations", a button that opens the run in place; `open`, "Hide 12 unchanged declarations"
above the opened run, which folds it again. `as` sets its element (`div` by default, `tr` or `li` in tables and lists;
a `tr` puts the button in one cell spanning `columns`).
a `tr` puts the button in one cell spanning `columns`). Given an `id`, the fold is an item the host sees, and while
closed it presents the items it folds (`presents`, in `data-entity-aliases`), so the host's selection, hover and
filter of one find it.

### `GeneratedMark`

Expand Down Expand Up @@ -4362,7 +4491,9 @@ The staged graph canvas shared by the graph, DAG and architecture renderers:
ELK layouts per comparison step (laid out off the main thread before the
first paint), identity-stable cards, spline relationships that morph on the
same clock as their cards, stable framing across the whole transition, and
host-driven change emphasis.
host-driven change emphasis. A dozen or more sibling cards removed (or added)
together fold into one card that counts them and opens in place
(`foldMassChanges`).

### `graphCanvasControls`

Expand Down Expand Up @@ -4556,6 +4687,23 @@ KitRenderer(__0: { "component": ComponentType<RendererProps<undefined>>; "option

Connects a kit renderer component to its host through the renderer frame protocol.

### `MassFolding`

```ts
interface MassFolding<P>
```

A renderer's props with its mass changes folded (`useMassFolds`), and the folds.

| Member | Signature | Description |
|---|---|---|
| `aliases` | `"aliases": { (id: string): Array<string> \| undefined }` | The items a closed fold's card presents (for its `data-entity-aliases`, the SDK's `entityAliasesAttribute`), so the host's selection, hover and filter of one find the card; undefined for an open fold or any other item. |
| `drawnFor` | `"drawnFor": { (id: string): string }` | The card or link drawn for an item: the fold's, while it hides the item, else the item itself. |
| `foldOf` | `"foldOf": { (id: string): string \| undefined }` | The fold a card, or a link drawn for one, opens or closes. |
| `folds` | `"folds": ReadonlyMap<string, MassFold>` | Each fold, by its card's ID; empty when nothing folds. |
| `props` | `"props": P` | The props to draw: `model` and `schedule` with each fold's card and links in place of what they stand for, a card's or link's emphasis the most of what it stands for, the host's selection and focus of a folded item moved onto its card, and `onSelect` of a fold's card, or of a link drawn for it, opening or closing the fold. The props passed, when nothing folds. |
| `toggle` | `"toggle": { (id: string): void }` | Opens a fold, or closes an open one. |

### `MatrixAxis`

```ts
Expand Down Expand Up @@ -5105,6 +5253,19 @@ host draws it once beside every pane. Pass `undefined` (or no items) to
clear it; unmounting clears it too. Describe the whole document, not the current progress, so the
legend never changes while scrubbing.

### `useMassFolds`

```ts
useMassFolds<P extends Pick<RendererProps<undefined>, "comparing" | "emphasis" | "focusRequest" | "locale" | "model" | "onSelect" | "schedule" | "scope" | "selectedId">>(props: P, document?: unknown): MassFolding<P>
```

Folds a renderer's mass changes (`foldMassChanges`) as the graph canvas and card grid do, for a renderer that lays out
its own model: draw `props` and give each fold's card (an entity row whose ID `isMassFold`) its label, its status's
style, `data-entity-aliases` from `aliases` and `data-fold`, and activate it with `onSelect` (or `toggle`). The cards
are labeled with the definition's plural noun for their kind, as the summary bar counts it. What the person opened
stays open while the same `document` is shown (by default the Changes scope's `all`, else `model`), the Changes
scope's views of it included. A single revision folds nothing.

### `useOpeningFloor`

```ts
Expand Down
23 changes: 19 additions & 4 deletions packages/renderers/database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ dashed while emphasized. Status text, link colors and tag tints use only the
host's change highlighting, so nothing looks changed at either endpoint or for a
single extraction.

A dozen or more tables, views or enums removed together (or added together) fold
into one card in the removed (or added) style, its header alone, counting them
with the definition's noun: `48 tables removed`. Their columns, keys and links
fold with them; a foreign key from one of them to a table that stays, or a
column typed by an enum that stays, is drawn once from the card's header. A
dozen or more columns or keys removed together from a table that stays fold the
same way into one row of it, `14 columns removed`. Activating a fold, or a link
drawn from it, opens its items in place; it stays, labeled
`Hide 48 removed tables`, as the way to fold them again. A fold presents its
items to the host (`data-entity-aliases`), so selecting, hovering, filtering or
focusing (`--entity`) one finds it. A comparison that drops a whole schema stays
a frame the host can draw.

## Diff mode

The renderer declares all four comparison modes; `diff` draws one static schema
Expand Down Expand Up @@ -140,9 +153,11 @@ with highlighting off the diff draws plainly in the same boxes.

## Fixtures

`fixtures/prisma-shop-{before,after}.json` and
`fixtures/django-library-{before,after}.json` are real extractions by
`prisma-schema` and `django-schema` of the small projects in
`fixtures/prisma-shop/` and `fixtures/django-library/`, regenerated with
`fixtures/prisma-shop-{before,after}.json`,
`fixtures/prisma-partners-{before,after}.json` (a partner program of 14 tables
retired at once) and `fixtures/django-library-{before,after}.json` are real
extractions by `prisma-schema` and `django-schema` of the small projects in
`fixtures/prisma-shop/`, `fixtures/prisma-partners/` and
`fixtures/django-library/`, regenerated with
`node packages/renderers/database/fixtures/make-schemas.mjs --python <python with Django>`.
`fixtures/invoicing-*.json` are EF Core–shaped synthetic extractions.
2 changes: 1 addition & 1 deletion packages/renderers/database/browser/diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {Extraction} from '@githubnext/projections-schemas'
* draws the same boxes. Set `PROJECTIONS_DIFF_SCREENSHOTS` to a directory to
* save every comparison's diff in light and dark at the project's width.
*/
const comparisons = ['prisma-shop', 'django-library', 'organizations', 'cleanup']
const comparisons = ['prisma-shop', 'django-library', 'organizations', 'cleanup', 'prisma-partners']
const shots = process.env.PROJECTIONS_DIFF_SCREENSHOTS

for (const name of comparisons) {
Expand Down
45 changes: 45 additions & 0 deletions packages/renderers/database/browser/mass-fold.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {expect, test} from '@playwright/test'
import {openStage} from '@githubnext/projections-renderer-testing/playwright'
import {harnessInspector} from '@githubnext/projections-renderer-harness/playwright'

const fold = 'pk-mass:removed:table:'

test('14 tables removed together fold into one card that presents them to the host and opens in place', async ({page}) => {
for (const comparisonMode of ['animated', 'diff'] as const) {
const renderer = await openStage(page, harnessInspector(), {scenario: 'database/prisma-partners', comparisonMode, progress: 0})
const card = renderer.frame.locator(`.database-table[data-entity-id="${fold}"]`)
const button = card.locator('.database-fold-button')
const program = renderer.frame.locator('.database-table[data-entity-id="table:/Program"]')
await expect(card).toHaveCount(1)
await expect(button).toHaveAttribute('title', 'Show 14 tables removed')
await expect(button).toHaveAttribute('aria-expanded', 'false')
await expect(card).toHaveAttribute('data-fold', 'closed')
await expect(program).toHaveCount(0)
const aliases: unknown = JSON.parse((await card.getAttribute('data-entity-aliases')) ?? '[]')
expect(aliases).toEqual(expect.arrayContaining(['table:/Program', 'table:/FraudAlert', 'column:table%3A%2FCommission/amount']))
// The host's selection and hover of a folded table find the card.
await renderer.select('table:/Program')
await expect(card).toHaveClass(/\bselected\b/u)
await expect(card).toHaveAttribute('data-projections-ring-selected', /.*/u)
await renderer.select(null)
await renderer.hover('table:/Program')
await expect(card).toHaveAttribute('data-projections-ring-hover', /.*/u)
await renderer.hover(null)
// Activating it opens the tables in place and selects nothing; again folds them.
await button.click()
await expect(program).toHaveCount(1)
await expect(renderer.frame.locator('.database-table[data-entity-id^="table:/"]')).toHaveCount(16)
await expect(button).toHaveAttribute('aria-expanded', 'true')
await expect(button).toHaveAttribute('title', 'Hide 14 removed tables')
expect((await renderer.state()).selections).toEqual([])
await button.click()
await expect(program).toHaveCount(0)
}
// `--entity` on a folded table opens on its card.
const focused = await openStage(page, harnessInspector(), {
scenario: 'database/prisma-partners',
progress: 0,
focus: {id: 'table:/Program'},
})
await expect(focused.frame.locator(`.database-table[data-entity-id="${fold}"]`)).toBeInViewport()
})
Loading
Loading