Principle:AFK surf Open agent View Preset Addition
| Knowledge Sources | |
|---|---|
| Domains | Database, Data_View, BlockSuite |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Pattern of adding a new view to a data source by copying a view preset's default data, assigning a fresh id, and setting it as the current view — without duplicating the underlying rows or properties.
Description
A view is a particular rendering of the shared dataset (table, kanban, etc.). Adding a view via viewManager.viewAdd(type) looks up the ViewMeta for the given DataViewMode, asks its model for defaultData, assigns a fresh nanoid id and the meta's defaultName, inserts it into the data source's view data list, and switches the current view to the new one. All views share the same rows and properties; only the view-scoped settings (filters, sorts, group-by, column order/width) differ. The built-in view presets are tableViewMeta and kanbanViewMeta, exported together as the viewPresets barrel.
Usage
Apply this principle whenever you want to give users multiple representations of the same dataset — a table for dense editing and a kanban for grouped card views, or any custom view preset. The shared-data / view-scoped-settings split keeps the data consistent across views.
Theoretical Basis
The data model is a many-views-over-one-dataset relation: Dataset × ViewSettings → RenderedView. viewAdd(type) creates a new ViewSettings row initialized from the preset's defaultData. The current view is a pointer; switching it re-renders without touching the dataset.
Pseudo-code:
viewManager.viewAdd('table'); // first view
// ...add properties, populate rows, configure group-by...
viewManager.viewAdd(viewPresets.kanbanViewMeta.type); // second view