Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AFK surf Open agent ViewManager ViewAdd

From Leeroopedia
Knowledge Sources
Domains Database, Data_View, BlockSuite
Last Updated 2026-10-25 00:00 GMT

Overview

Concrete API for adding a new view (table, kanban, etc.) to a data source's view list, copied from the view preset's default data and set as the current view.

Description

viewManager.viewAdd is the canonical method to create a new view on a DataSource. It looks up the ViewMeta for the given DataViewMode (e.g. table, kanban), asks the meta's model for its defaultData (a fresh DataViewDataType), assigns a nanoid id and the meta's defaultName, inserts it via dataSource.viewDataAdd, then calls setCurrentView so the new view becomes active. The two built-in view modes are tableViewMeta and kanbanViewMeta (exported together as the viewPresets barrel). Adding a view does not duplicate properties or rows — all views share the same underlying data.

Usage

Call this after wrapping a database with a DatabaseBlockDataSource. Use it to create the initial table view and to add additional views (e.g. a kanban view that groups by a previously configured group-by column).

Code Reference

Source Location

  • Repository: Open-Agent
  • File: blocksuite/affine/data-view/src/core/view-manager/view-manager.ts (L75-86); usage in blocksuite/playground/apps/starter/data/database.ts (L46, L116); view presets barrel at blocksuite/affine/data-view/src/view-presets/index.ts (L8-11)

Signature

interface ViewManager {
  viewAdd(type: DataViewMode): string;
  // ...viewGet, viewDelete, viewDuplicate, viewChangeType, moveTo, setCurrentView, etc.
}

// View preset barrel:
const viewPresets = {
  tableViewMeta: tableViewMeta,
  kanbanViewMeta: kanbanViewMeta,
};

Import

import { viewPresets } from '@blocksuite/data-view/view-presets';
// viewManager is obtained from a DataSource:
const viewManager = datasource.viewManager;

I/O Contract

Inputs

Name Type Required Description
type DataViewMode Yes View mode string, e.g. 'table' or viewPresets.kanbanViewMeta.type

Outputs

Name Type Description
viewId string The new view id; also set as the current view

Usage Examples

Add Table then Kanban

const datasource = new DatabaseBlockDataSource(database);

// 1. Initial table view
datasource.viewManager.viewAdd('table');

// 2. ...add properties, configure group-by, populate rows...

// 3. Add a kanban view that groups by the configured column
datasource.viewManager.viewAdd(viewPresets.kanbanViewMeta.type);

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment