Skip to content

feat(prompts): sortable columns on All Prompts (visibility / mentions / volume / last run) with URL deep-link - #322

Merged
gkhngyk merged 1 commit into
mainfrom
feature/prompts-sortable-columns
Jun 30, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/prompts-sortable-columns

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds click-to-sort on the All Prompts table (/dashboard/prompts?tab=all) for the visibility / mentions / volume / last-run columns, with the sort persisted to the URL for deep-linking.

Behavior

  • Clicking a header sorts by that column. A new column starts desc ("show me the extremes"); re-clicking the active column toggles desc ⇄ asc.
  • The active column + direction are marked with a chevron (ChevronUp/ChevronDown).
  • The sort is written to the URL as ?tab=all&sort=visibility&dir=desc and hydrated on load, so it survives reloads and is shareable (mirrors the existing tab URL sync).
  • Unanalysed / missing rows sort last in both directions — ascending ("weakest first") never pushes empty cells to the top.
  • Default ordering (newest first) is unchanged when there's no sort param.

Implementation notes

  • The All Prompts table is one row per prompt (the aggregatePromptVolumeClusters grouping is the Insights tab, not this table), so sorting is in-memory over the already-loaded rows — no server/pagination changes.
  • Sort state is derived from the URL via useSearchParams; the header click writes it with router.replace(..., { scroll: false }), matching the page's existing tab sync.
  • The null-last comparator is extracted to a small, tested helper (prompt-sort.ts + prompt-sort.test.ts).
  • A new SortableHead keeps the InfoTip outside the sort button so the help icon doesn't trigger a sort.

Related issue

Closes #291

Type of change

  • feat — New feature

How to test

  1. /dashboard/prompts?tab=all → click Visibility / Mentions / Volume / Last run headers; the table sorts by that column (desc first).
  2. Re-click the active header → toggles asc/desc; a chevron marks the active column + direction.
  3. Reload or copy the URL (?tab=all&sort=visibility&dir=desc) into a new tab → the same sort is restored.
  4. Sort ascending on a column with unanalysed prompts → empty-cell rows stay at the bottom, not the top.
  5. Remove the sort param → default newest-first ordering.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds client-side, URL-persisted sorting to the All Prompts table so users can deep-link/share a sorted view and quickly surface extremes by key metrics.

Changes:

  • Introduces a compareNullsLast comparator helper (with Vitest coverage) to keep missing/unanalysed values sorted last in both directions.
  • Adds sortable table headers for Visibility / Mentions / Volume / Last run, including chevron indicators for the active sort.
  • Hydrates and persists sort/dir via useSearchParams + router.replace(..., { scroll: false }), mirroring the existing tab URL sync.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
web/src/app/[locale]/(dashboard)/dashboard/prompts/prompt-sort.ts Adds the nulls-last comparator used by All Prompts sorting.
web/src/app/[locale]/(dashboard)/dashboard/prompts/prompt-sort.test.ts Adds unit tests validating ascending/descending behavior and nulls-last behavior.
web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx Wires URL-driven sort state into the All Prompts tab and replaces static headers with sortable ones.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +149 to +155
<TableHead className={className}>
<span className="inline-flex items-center gap-1">
<button
type="button"
onClick={() => onSort(sortKey)}
aria-label={`Sort by ${typeof children === 'string' ? children : sortKey}`}
className={cn(
Make the visibility / mentions / volume / last-run headers clickable to
sort the All Prompts table. Click toggles desc<->asc (new column starts
desc); the active column + direction show a chevron. The sort is written
to the URL (?tab=all&sort=visibility&dir=desc) and hydrated on load, so
it survives reloads and is shareable.

Rows with missing data for the sorted column (unanalysed prompts) always
sort last in both directions, via a small tested compareNullsLast helper.
Default ordering (newest first) is unchanged when no sort param is set.
@gkhngyk
gkhngyk force-pushed the feature/prompts-sortable-columns branch from e13d514 to 9a9432e Compare June 30, 2026 11:59
@gkhngyk
gkhngyk merged commit a331c8d into main Jun 30, 2026
3 checks passed
@gkhngyk
gkhngyk deleted the feature/prompts-sortable-columns branch June 30, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(prompts): sortable columns on All Prompts (visibility / mentions / volume / last run) with URL deep-link

2 participants