Skip to content

Components · Search and discovery

SavedViews

View switcher for a list: named combinations of filters, sort and columns, with save, save as new, rename, delete, set default and an "Edited" marker.

@rookcom/monarch-react/dataComponent

Views with filters, save and discard

StatusOpen

Usage examples

The example at the top of the page is the only one for this component.

Purpose

Lets people jump between named views of a list and keep the filters, sort and columns they set up. It shows when the current state differs from the selected view and offers to save or discard the change. The app stores the views; the component only renders them and reports choices.

Use when

  • A list or table has filters, sorting or column choices people return to.
  • Built-in views and personal or shared views live side by side.

Avoid when

  • A handful of fixed views with no saving: use Tabs or TabsFilter.
  • Saving a single search query: use SearchInput history in the app.

Design principles

  • No data: views come in as views, changes go out through onSaveNew, onSaveChanges, onRename, onDelete, onSetDefault and onDiscardChanges. What a view stores is up to the app.
  • The app decides "modified" (it compares its state with the view), so any state can be part of a view.
  • Read-only views (built-in or someone else’s) can be applied and copied, never changed.
  • Destructive actions are confirmed; names are validated (required, unique, maxNameLength).

API reference

import { SavedViews, defaultSavedViewsMessages } from '@rookcom/monarch-react/data';
ExportKindRenderingRoot class
SavedViewscomponentclient.mn-saved-views
defaultSavedViewsMessagesutilityclient–

Imported from @rookcom/monarch-react/data. The ref is the trigger button.

SavedView: id, name, count, shared, isDefault, readOnly, group.

Callbacks may return a promise: the name dialog waits for it and shows messages.saveFailed if it rejects; delete uses ConfirmDialog, which shows the error.

messages translates every string.

Generated from the TypeScript declarations of packages/react/src/components/search/saved-views.

Properties

SavedViews

Switcher for named views of a list (filters, sort and columns), with save, save as new, rename, delete, set default and an "Edited" marker. The app persists views through the callbacks; the component holds no data.

PropTypeDescription
views requiredreadonly SavedView[]
classNamestring
defaultValuestring | nullInitially selected view id (uncontrolled).
disabledboolean
maxNameLengthnumberLongest allowed name. Default 80.
messagesPartial<SavedViewsMessages>
modifiedbooleanThe current filters, sort or columns differ from the selected view. Shows "Edited".
onDelete((id: string) => unknown)
onDiscardChanges(() => void)"Discard changes": the app reapplies the selected view.
onRename((id: string, name: string) => unknown)
onSaveChanges((id: string) => unknown)"Save changes": the app overwrites the selected view with the current state.
onSaveNew((name: string) => unknown)"Save as new view…": the app stores the current state under this name and selects it.
onSetDefault((id: string) => unknown)
onValueChange((id: string) => void)A view was chosen. Apply its filters, sort and columns in the app.
size"xs" | "sm" | "md"
valuestring | nullSelected view id (controlled). `null` for none.

Variants

PropValuesDescription
size'xs''sm''md'Trigger size. Default sm.
group (view)'string'Views with the same group are listed under that heading, in order.

States

StateExposed asBehaviour
Modifieddata-modifiedAn "Edited" marker in the trigger; the menu offers "Save changes to …" (editable views) and "Discard changes".
Selected viewaria-checkedRadio item of the current view.
Default view–A star, announced as "Default view".
Shared view–A "Shared" marker.
Savingaria-busyThe name dialog is busy while the save promise runs and keeps the error on failure.
No view–The trigger shows messages.noView ("All items").

Interaction behaviour

  • Choosing a view calls onValueChange; the app applies its filters, sort and columns.
  • "Save as new view…" and "Rename…" open a dialog with a name field; Enter submits.
  • "Delete view…" asks for confirmation first.
  • "Set as default" is offered for views that are not already the default.
  • After a dialog closes, focus returns to the trigger.

Keyboard support

KeysAction
Enter / Space / Arrow DownOpens the menu from the trigger.
Arrow Up / Down, Home / EndMove through views and actions; type-ahead jumps by name.
EnterSelects a view or runs an action; submits the name dialog.
EscapeCloses the menu or dialog and returns focus to the trigger.

Accessibility

Role
button with a menu (menuitemradio items)
Accessible name
Visually hidden "View:" plus the view name, count and "Edited", e.g. "View: My open tickets 7 Edited".
  • Views are a radio group, so the current one is announced as checked.
  • The default star has a text alternative; "Edited" is text, not colour alone.
  • Actions are real menu items, not buttons nested in menu items.
  • The name field is labelled and its errors are linked (FieldError).

Responsive behaviour

  • The trigger truncates long names; the menu is at most 22rem or the screen width minus 2rem.
  • Dialogs follow Dialog’s small size on phones.

Theme support

  • Trigger, menu and dialog use Button, DropdownMenu and Dialog tokens; the "Edited" marker uses the warning subtle tokens in every theme.

Do and don't

Do

  • Store filters, sort and visible columns in a view, and compute modified from all of them.
  • Mark built-in and other people’s views readOnly.
  • Return promises from callbacks so failures stay visible.

Don't

  • Do not store row data in a view, only the settings that produce it.
  • Do not apply a view without updating the URL if the app keeps filters there.
  • FilterBar: Shows and edits the filters a view stores.
  • DataTable: Sort and columns a view can store.
  • DropdownMenu: The menu SavedViews is built on.
  • Tabs: A few fixed views without saving.

Dependencies

KindDepends on
npm packagesreact
Monarch componentsButton, DropdownMenu, Dialog, ConfirmDialog, Field, Input

Testing coverage

  • Trigger shows the view, count and "Edited".
  • Switching views through grouped radio items (uncontrolled), default marker announced.
  • Save changes, discard, rename, set default and delete appear only where allowed (read-only, modified, default).
  • Save as new validates required and unique names, then returns focus to the trigger.
  • A rejected save keeps the dialog open with an error; delete is confirmed.
  • Keyboard open and Escape; server rendering.
CheckCovered
Axe in jsdomYes
Server renderingYes
Browser suitesNone yet

Tests: packages/react/src/components/search/saved-views