Files
astrolabe/docs/spec/02-snippet-library.md
T
oleh 693f5d7073 Fix dataset-ref walk false positive and wire spec-mandated success toasts
- Prune the data payload and top-level datasets keys in all three ref walks
  (extractDatasetRefs, renameDatasetInSpec, resolveDatasetRefs) so a data row
  carrying a field named "data" is no longer misread as a library reference,
  spuriously rewritten, or made to throw DatasetNotFoundError. Adds tests,
  including a guard that lookup-transform refs (from.data) still resolve.
- Wire the deferred success toasts now the Toaster has landed: publish, revert,
  extract-to-dataset, and snippet/dataset delete. Copy follows the council
  title-vs-message rule (title states the action, message adds the consequence).
- Reconcile the spec's blanket toast mandate to "toast only what the user can't
  already see": no toast on visible-result creates (snippet, dataset form);
  Copy Reference stays inline and gains an aria-live announcement (new shared
  .visually-hidden utility) instead of a toast-per-copy.
- Move the toast region to bottom-right so it stops covering the header action
  cluster (Publish/Revert, theme/datasets).
- Update docs/spec 01F/02/05 and docs/architecture/07 + 10 to match.
2026-06-05 16:34:58 +03:00

7.7 KiB

02 · Snippet Library

The Snippet Library is the left pane and the primary entry point to the app. A snippet is a saved Vega-Lite specification together with metadata (name, comment, timestamps, tags, references to external datasets). The library lets the user browse, search, sort, select, and manage their snippets. Editing the specification, the draft-vs-published workflow, the live preview, and dataset management are covered elsewhere (see Spec Editor & Draft/Published Workflow, Live Preview, Datasets); this section covers only the library and management surface.

The List

The list shows every saved snippet and is always visible. A persistent "Create New Snippet" affordance sits at the top of the list, above all snippets, so the user can always start a new snippet regardless of scroll position.

  • The list shows all snippets, ordered newest-modified first by default (see Sort).
  • A "Create New Snippet" item is pinned at the top of the list; activating it creates and selects a new snippet (see Snippet Operations).
  • Selecting a snippet makes it the active snippet: it loads into the editor and preview, becomes highlighted in the list, and the URL updates to reflect the selected snippet so the state is shareable and survives a page reload (see Application Shell & Navigation).
  • Exactly one snippet is active at a time.
  • When no snippets match the current search, the list shows an empty-state message ("No snippets match your search"); when there are genuinely no snippets, it shows "No snippets found".
  • On first run, when no snippets exist, the app seeds one sample bar-chart snippet so the user starts with a working example.

List Item

Each list item is a compact row summarizing one snippet, designed for fast scanning.

  • Shows the snippet name.
  • Shows a last-modified date, rendered relatively for recent items ("Today", "Yesterday", "Nd ago" within the past week) and as a full date beyond that, formatted per the user's date-format setting (see Settings). When sorting by Created, the item shows the created date instead of the modified date.
  • Shows the snippet size (in KB), but only once the snippet reaches at least about 1 KB; smaller snippets omit the size to reduce clutter.
  • Shows a status indicator distinguishing a snippet that has unpublished draft changes from one that is fully published (the indicator communicates "draft" vs "published"). The publish and revert actions themselves live in Spec Editor & Draft/Published Workflow.
  • Shows a small dataset icon when the snippet references one or more external datasets (see Datasets); the icon is omitted otherwise.
  • The active snippet is visually highlighted.

A live search box lets the user narrow the list as they type. It exists so users with many snippets can find one by name, by note, or by something inside the specification itself.

  • The search box filters the list immediately on each keystroke.
  • Matching is case-insensitive and spans the snippet name, the snippet comment, and the specification content (the current working/draft spec text), so a search for a field name, mark type, or dataset name in the spec will surface matching snippets.
  • The search has a clear control that empties the box and returns focus to it, restoring the full list.
  • Search affects only which snippets are shown; it does not change the active snippet or any data.

Sort

The user chooses how the list is ordered. The choice persists across sessions so the library always opens the way the user left it.

  • Sort fields: Modified, Created, Name, Size.
  • An ascending/descending toggle controls direction; the current field and direction are indicated (e.g. a directional arrow on the active field).
  • Selecting the already-active sort field flips the direction; selecting a different field switches to it and resets to descending.
  • Default ordering is Modified, descending (newest changes first).
  • Name sorts alphabetically; Size sorts by stored snippet size; Created and Modified sort chronologically.
  • The Modified time advances on every save — including silent draft auto-saves (see Spec Editor & Draft/Published Workflow) and inline name/comment edits — so under the default Modified-descending sort the active snippet continually rises to the top while it is being edited.
  • The selected sort field and direction persist across sessions.

Selected-Snippet Metadata Panel

When a snippet is active, a metadata panel (within the left pane) exposes its editable properties and key facts. It exists so the user can rename, annotate, and inspect a snippet without leaving the library.

  • Shows and lets the user edit the Name inline; edits save automatically.
  • Shows and lets the user edit a multiline Comment (free-form notes); edits save automatically.
  • Shows read-only Created and Modified timestamps, formatted per the user's date-format setting (see Settings).
  • When the snippet references external datasets, shows a Linked Datasets list of the referenced dataset names, each with a dataset icon (see Datasets). The list is omitted when there are no references.
  • The panel also exposes the Duplicate and Delete operations for the active snippet (see Snippet Operations).

Snippet Operations

The library provides the lifecycle operations for snippets. An operation whose outcome the user can't already see confirms it with a toast; an operation whose result is immediately visible needs none (see Application Shell & Navigation → Toasts).

  • Create New: starts a new snippet from a small sample Vega-Lite bar-chart template (a few inline category/value rows), assigns it an auto-generated default name (see Naming & Tags), saves it, and makes it the active snippet. Opening in the editor is the confirmation, so no toast is raised.
  • Duplicate: creates an independent copy of the active snippet with a name suffixed "(copy)". The copy carries over the specification, comment, tags, and dataset references, gets fresh created/modified timestamps and a new identity, and becomes the active snippet. A success toast confirms the duplication.
  • Delete: permanently removes the active snippet after the user confirms a warning that the action cannot be undone. After deletion no snippet is active. A toast confirms the deletion.
  • These operations never affect other snippets.

Naming & Tags

New snippets get a sensible default name, and a tag field exists on each snippet for categorization, though tags are not a primary user surface.

  • A new snippet receives an auto-generated default name based on the current date and time, so it is uniquely identifiable until the user renames it (renaming happens in the metadata panel).
  • Each snippet stores a list of tags. Tags are persisted and carried through duplication; for example, snippets brought in via import are tagged "imported" (see Import & Export).
  • There is no dedicated tag-management UI; tags are stored on the data model but are not surfaced as a primary browsing or editing control.

Storage Monitor

A small indicator at the bottom of the library shows how much of the snippet storage budget is in use, warning the user before they run out of room. This concerns snippet storage specifically; datasets are stored separately with far greater capacity (see Datasets / Data Model).

  • Displays current usage against the total budget (used vs. total), where the practical snippet budget is about 5 MB.
  • A fill indicator reflects the percentage used.
  • The indicator enters escalating warning states as usage climbs (a cautionary state past roughly 70% and a critical state past roughly 90%).
  • When storage is full, a save may fail; the system warns the user that the snippet could not be saved rather than silently losing data, so the user can delete snippets to free space.