| 257 | } |
| 258 | |
| 259 | export 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 | } |