MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / addView

Function addView

packages/app-core/src/lib/database-cells.ts:259–277  ·  view source on GitHub ↗
(doc: DatabaseDoc, type: 'table' | 'board')

Source from the content-addressed store, hash-verified

257}
258
259export function addView(doc: DatabaseDoc, type: 'table' | 'board'): DatabaseDoc {
260 const id = genId()
261 const base = { id, name: type === 'board' ? 'Board' : 'Table', filters: [], sorts: [] }
262 const view: DbView =
263 type === 'board'
264 ? {
265 ...base,
266 type: 'board',
267 groupByFieldId: doc.fields.find((f) => f.type === 'select')?.id,
268 cardFieldIds: doc.fields.filter((f) => f.id !== doc.idFieldId).map((f) => f.id)
269 }
270 : {
271 ...base,
272 type: 'table',
273 columnOrder: doc.fields.map((f) => f.id),
274 hiddenFieldIds: doc.fields.filter((f) => f.hidden).map((f) => f.id)
275 }
276 return { ...doc, views: [...doc.views, view], activeViewId: id }
277}

Callers 1

DatabaseViewFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected