@@ -1182,6 +1182,24 @@ export function useDeleteTableRowsAsync({ workspaceId, tableId }: RowMutationCon
11821182
11831183type UpdateColumnParams = Omit < UpdateTableColumnBodyInput , 'workspaceId' >
11841184
1185+ /**
1186+ * Whether an update drops a `select` option the column currently declares —
1187+ * the one options edit the server answers by rewriting cells.
1188+ */
1189+ function removesSelectOption (
1190+ previousDetail : TableDefinition | undefined ,
1191+ { columnName, updates } : UpdateColumnParams
1192+ ) : boolean {
1193+ if ( updates . options === undefined || previousDetail === undefined ) return false
1194+ const lower = columnName . toLowerCase ( )
1195+ const column = previousDetail . schema . columns . find (
1196+ ( c ) => getColumnId ( c ) === columnName || c . name . toLowerCase ( ) === lower
1197+ )
1198+ if ( ! column ?. options ?. length ) return false
1199+ const keptIds = new Set ( updates . options . map ( ( o ) => o . id ) )
1200+ return column . options . some ( ( o ) => ! keptIds . has ( o . id ) )
1201+ }
1202+
11851203/**
11861204 * Update a column (rename, type change, or constraint update).
11871205 */
@@ -1227,13 +1245,17 @@ export function useUpdateColumn({ workspaceId, tableId }: RowMutationContext) {
12271245 if ( isValidationError ( error ) ) return
12281246 toast . error ( error . message , { duration : 5000 } )
12291247 } ,
1230- onSettled : ( _data , _error , variables ) => {
1231- // A type change, or a select single↔multi toggle, rewrites stored cells
1232- // server-side (option ids ↔ names, scalar ↔ array). Those need the rows
1233- // refetched too — the schema-only path would leave the grid rendering the
1234- // pre-migration values. Everything else really is metadata-only.
1248+ onSettled : ( _data , _error , variables , context ) => {
1249+ // A type change, a select single↔multi toggle, or removing an option
1250+ // rewrites stored cells server-side (option ids ↔ names, scalar ↔ array,
1251+ // removed ids cleared). Those need the rows refetched too — the
1252+ // schema-only path would leave the cache holding pre-migration values,
1253+ // which the grid hides but emptiness checks, filters, and dependent-group
1254+ // eligibility still act on. Everything else really is metadata-only.
12351255 const rewritesRows =
1236- variables . updates . type !== undefined || variables . updates . multiple !== undefined
1256+ variables . updates . type !== undefined ||
1257+ variables . updates . multiple !== undefined ||
1258+ removesSelectOption ( context ?. previousDetail , variables )
12371259 if ( rewritesRows ) invalidateTableSchema ( queryClient , tableId )
12381260 else invalidateTableSchemaOnly ( queryClient , tableId )
12391261 } ,
0 commit comments