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

Function moveColumnToField

packages/app-core/src/lib/database-cells.ts:200–218  ·  view source on GitHub ↗
(
  doc: DatabaseDoc,
  viewId: string,
  fieldId: string,
  targetFieldId: string
)

Source from the content-addressed store, hash-verified

198 * column order — used by header drag-and-drop (#317). No-op for a non-table
199 * view, unknown ids, or a self-drop. */
200export function moveColumnToField(
201 doc: DatabaseDoc,
202 viewId: string,
203 fieldId: string,
204 targetFieldId: string
205): DatabaseDoc {
206 if (fieldId === targetFieldId) return doc
207 const view = doc.views.find((v) => v.id === viewId)
208 if (!view || view.type !== 'table') return doc
209 const fieldIds = doc.fields.map((f) => f.id)
210 const stored = view.columnOrder ?? fieldIds
211 const order = [...stored, ...fieldIds.filter((id) => !stored.includes(id))].filter((id) =>
212 fieldIds.includes(id)
213 )
214 if (!order.includes(fieldId) || !order.includes(targetFieldId)) return doc
215 const without = order.filter((id) => id !== fieldId)
216 without.splice(without.indexOf(targetFieldId), 0, fieldId)
217 return updateView(doc, viewId, { columnOrder: without })
218}
219
220export function ensureSelectOption(doc: DatabaseDoc, fieldId: string, rawValue: string): DatabaseDoc {
221 const value = rawValue.trim().replace(/,/g, ' ') // option values may not contain commas

Callers 2

DatabaseTableViewFunction · 0.90

Calls 1

updateViewFunction · 0.85

Tested by

no test coverage detected