( doc: DatabaseDoc, viewId: string, fieldId: string, targetFieldId: string )
| 198 | * column order — used by header drag-and-drop (#317). No-op for a non-table |
| 199 | * view, unknown ids, or a self-drop. */ |
| 200 | export 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 | |
| 220 | export function ensureSelectOption(doc: DatabaseDoc, fieldId: string, rawValue: string): DatabaseDoc { |
| 221 | const value = rawValue.trim().replace(/,/g, ' ') // option values may not contain commas |
no test coverage detected