Skip to content

Replace the JSON query editor with a structured filter builder #1920

Closed

Description

@malibio

Summary

Filtering a type today means hand-writing raw JSON. "Edit Query" opens a <textarea> holding the serialized QueryDefinition, validated only for "targetType is a string" and "filters is an array."

We know that shape exactly, and the schema tells us the fields, their types, and their legal values. Replace the textarea with a structured builder — collapsed by default, expanding to reveal what can be changed.

Depends on #1919, which establishes the default-query model: a type's default view is unpersisted, and changing filters or view materializes a query node. This issue builds the filtering UI over that model.

Current State

packages/desktop-app/src/lib/components/query/query-editor.svelte

  • One JSON <textarea> bound to jsonText (line 153), 14 rows, always fully expanded when open
  • validateAndSave (line 39) checks targetType is a non-empty string and filters is an array, then passes the object straight through — filter contents are entirely unvalidated: operators, property names, and value types are never checked
  • Collapsible "Query template examples" rendering raw JSON blocks with a "Use" button that overwrites the buffer
  • Opened by an "Edit Query" button that replaces the result view wholesale (query-node-viewer.svelte:238)

Problems

1. Raw JSON as the only filtering interface. Writing {"type":"property","operator":"equals","property":"status","value":"open"} by hand is not a filter UI.

2. The type is asked for even though it's already known. The user arrived by clicking a schema. targetType is inherited from that context and must never be an input — a typed mismatch yields a page whose columns come from one type and whose rows come from another.

3. Filters are unvalidated. A misspelled property, an operator outside the union, or a wrong-typed value all save cleanly and silently match nothing.

4. The preview count is wrong. handleQueryPreview (query-node-viewer.svelte:184) calls queryNodes({ nodeType }) and ignores filters — it reports the same whole-type count no matter what filters are entered.

5. The editor takes over the page. Setting isEditMode swaps out the results, so you can't see what your filter does while building it.

Scope

Collapsed by default, expand to edit

  • Filtering presents as a compact control in the view header — collapsed on arrival, since the default state is "no filter applied"
  • Expanding reveals the builder; collapsing hides it without discarding what was built
  • The results stay visible while the builder is open — replace the full-page isEditMode takeover so filters can be adjusted against live results
  • When filters are active, the collapsed state says so (a count, or a short summary) rather than looking identical to unfiltered

Filter rows

Each entry in filters[] is a row of controls built from QueryFilter (packages/desktop-app/src/lib/types/query.ts:64–89):

  • Property — select populated from the schema's fields, labelled field.description ?? prettified field.name (the label logic in table-view.svelte:41–48). No free-typed property names.
  • Operator — select from the QueryFilter['operator'] union, narrowed to the selected field's type: contains for strings, gt/lt/gte/lte for numbers and dates, equals/in for enums, exists for any
  • Value — control matched to field type: select of coreValues/userValues for enums, date input for dates, number input for numbers, text otherwise; omitted for exists
  • Add and remove rows; removing the last leaves a valid filters: []

Type as fixed context

  • targetType is displayed, not editable, sourced from the schema or saved query being viewed
  • No control offers to change it

Sorting and limit

  • sorting — field select plus asc/desc, matching SortConfig
  • limit — number input, defaulting to DEFAULT_QUERY.limit (50)

Preview

Fix the count to reflect the filters being edited, or remove the button. With results visible live behind the builder, a separate preview may be redundant — prefer removing it over leaving it wrong.

Templates

QUERY_TEMPLATE_EXAMPLES renders raw JSON with a "Use" button. Recommendation: drop them — a structured builder makes them redundant, and they exist to help people write JSON by hand.

Acceptance Criteria

  • Filtering presents structured controls, not a JSON textarea
  • The filter builder is collapsed on arrival and expands on demand
  • Results remain visible while the builder is open
  • Collapsing the builder preserves the filters that were built
  • An active filter is visibly distinct from no filter in the collapsed state
  • targetType is fixed context, never an input
  • Property selects are populated from the current schema's fields with schema labels
  • Operator choices are constrained to those valid for the selected field's type
  • Enum fields offer coreValues/userValues as options rather than free text
  • Filters can be added and removed; an empty filter list is valid
  • Sorting field/direction and limit are editable through controls
  • Filters round-trip: reopening shows what was saved
  • Preview reflects the filters being edited, or is removed
  • The raw JSON textarea is deleted, not kept as an alternate mode

Out of Scope

  • AND/OR nesting — QueryFilter[] is flat and implies AND; keep that
  • relationship and metadata filter types — property and content cover the schema-page case; leave the union intact and unhandled kinds untouched on save
  • Changing QueryDefinition or its storage — this is a UI over the existing shape
  • Deciding what is persisted vs. transient — owned by Separate the default type view from persisted query nodes #1919

Notes

  • QueryDefinition, QueryFilter, SortConfig are fully typed in packages/desktop-app/src/lib/types/query.ts — the builder targets that shape, no new persisted types
  • SchemaField (packages/desktop-app/src/lib/types/schema-node.ts:64–104) supplies what the controls need: name, type, description, coreValues, userValues
  • Round-tripping matters. Queries can be AI-generated (generatedBy: 'ai') and may contain relationship/metadata filters this builder won't render. A filter the builder cannot represent must be preserved on save, not silently dropped — otherwise opening an AI query and hitting Save quietly destroys part of it
  • The List/Kanban views issue is independent and can land in either order

Activity

  1. mstomar125 commented on Aug 7, 2026

    @mstomar125
    Contributor

    Board → Blocked (needs a desktop-app/browser validation env). Unblocked on the dependency axis (#1919 is merged), but this is a structured-filter-builder UX feature (collapse/expand, live preview against results, per-field operator narrowing) whose correctness needs interactive validation in the running desktop app — not available on the current headless remote. Ready to pick up on the Mac.

  2. mstomar125 commented on Aug 7, 2026

    @mstomar125
    Contributor

    Correction: unblocking. This remote box has a real display + Playwright/Chromium, so the frontend renders and is screenshot-validatable here (verified against the running app) — I was wrong to block on 'needs the Mac'. Picking it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions