@@ -2078,6 +2078,28 @@ export function TableGrid({
20782078 const updateMetadataRef = useRef ( updateMetadataMutation . mutate )
20792079 updateMetadataRef . current = onPersistLayout ?? updateMetadataMutation . mutate
20802080
2081+ /**
2082+ * Records columns created since the layout was last saved. A new column already
2083+ * *renders* — `displayColumns` appends anything missing from `columnOrder` — but
2084+ * without this only the insert-left/right path wrote it back, so creating one via
2085+ * "+ New column", a workflow group, or an enrichment left it out of the stored
2086+ * order. With a view active this writes into that view, which is what makes a
2087+ * column added while a view is open belong to it.
2088+ *
2089+ * No-ops when the table has no explicit order (schema order governs, nothing to
2090+ * record) and when nothing is missing, so it self-heals once and stays quiet.
2091+ */
2092+ useEffect ( ( ) => {
2093+ const order = columnOrderRef . current
2094+ if ( ! order || columns . length === 0 ) return
2095+ const known = new Set ( order )
2096+ const appended = columns . map ( getColumnId ) . filter ( ( id ) => ! known . has ( id ) )
2097+ if ( appended . length === 0 ) return
2098+ const nextOrder = [ ...order , ...appended ]
2099+ setColumnOrder ( nextOrder )
2100+ updateMetadataRef . current ( { columnOrder : nextOrder } )
2101+ } , [ columns ] )
2102+
20812103 const deleteWorkflowGroupRef = useRef ( deleteWorkflowGroupMutation . mutate )
20822104 deleteWorkflowGroupRef . current = deleteWorkflowGroupMutation . mutate
20832105
0 commit comments