|
|
@ -57,6 +57,27 @@ const selectColors = [ |
|
|
|
|
|
|
|
|
|
|
|
const logger = new Logger('Column'); |
|
|
|
const logger = new Logger('Column'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const requiredColumnsToRecreate = { |
|
|
|
|
|
|
|
[UITypes.LinkToAnotherRecord]: [ |
|
|
|
|
|
|
|
'type', |
|
|
|
|
|
|
|
'fk_child_column_id', |
|
|
|
|
|
|
|
'fk_parent_column_id', |
|
|
|
|
|
|
|
'fk_related_model_id', |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[UITypes.Links]: [ |
|
|
|
|
|
|
|
'type', |
|
|
|
|
|
|
|
'fk_child_column_id', |
|
|
|
|
|
|
|
'fk_parent_column_id', |
|
|
|
|
|
|
|
'fk_related_model_id', |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[UITypes.Rollup]: ['fk_relation_column_id', 'fk_rollup_column_id'], |
|
|
|
|
|
|
|
[UITypes.Lookup]: ['fk_relation_column_id', 'fk_lookup_column_id'], |
|
|
|
|
|
|
|
[UITypes.QrCode]: ['fk_qr_value_column_id'], |
|
|
|
|
|
|
|
[UITypes.Barcode]: ['fk_barcode_value_column_id'], |
|
|
|
|
|
|
|
[UITypes.Button]: ['type', 'label'], |
|
|
|
|
|
|
|
[UITypes.Formula]: ['formula'], |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default class Column<T = any> implements ColumnType { |
|
|
|
export default class Column<T = any> implements ColumnType { |
|
|
|
public fk_model_id: string; |
|
|
|
public fk_model_id: string; |
|
|
|
public fk_workspace_id?: string; |
|
|
|
public fk_workspace_id?: string; |
|
|
@ -1112,157 +1133,148 @@ export default class Column<T = any> implements ColumnType { |
|
|
|
skipFormulaInvalidate = false, |
|
|
|
skipFormulaInvalidate = false, |
|
|
|
) { |
|
|
|
) { |
|
|
|
const oldCol = await Column.get(context, { colId }, ncMeta); |
|
|
|
const oldCol = await Column.get(context, { colId }, ncMeta); |
|
|
|
let insertColOpt = true; |
|
|
|
const requiredColAvail = |
|
|
|
switch (oldCol.uidt) { |
|
|
|
!requiredColumnsToRecreate[oldCol.uidt] || |
|
|
|
case UITypes.Lookup: { |
|
|
|
requiredColumnsToRecreate[oldCol.uidt].every((k) => column[k]); |
|
|
|
// LookupColumn.insert()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await ncMeta.metaDelete( |
|
|
|
if (requiredColAvail) { |
|
|
|
context.workspace_id, |
|
|
|
switch (oldCol.uidt) { |
|
|
|
context.base_id, |
|
|
|
case UITypes.Lookup: { |
|
|
|
MetaTable.COL_LOOKUP, |
|
|
|
// LookupColumn.insert()
|
|
|
|
{ |
|
|
|
|
|
|
|
fk_column_id: colId, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
|
|
|
|
`${CacheScope.COL_LOOKUP}:${colId}`, |
|
|
|
|
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case UITypes.Rollup: { |
|
|
|
|
|
|
|
await ncMeta.metaDelete( |
|
|
|
|
|
|
|
context.workspace_id, |
|
|
|
|
|
|
|
context.base_id, |
|
|
|
|
|
|
|
MetaTable.COL_ROLLUP, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fk_column_id: colId, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
|
|
|
|
`${CacheScope.COL_ROLLUP}:${colId}`, |
|
|
|
|
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case UITypes.Links: |
|
|
|
await ncMeta.metaDelete( |
|
|
|
case UITypes.LinkToAnotherRecord: { |
|
|
|
context.workspace_id, |
|
|
|
// delete only if all required fields are present
|
|
|
|
context.base_id, |
|
|
|
if ( |
|
|
|
MetaTable.COL_LOOKUP, |
|
|
|
[ |
|
|
|
{ |
|
|
|
'type', |
|
|
|
fk_column_id: colId, |
|
|
|
'fk_child_column_id', |
|
|
|
}, |
|
|
|
'fk_parent_column_id', |
|
|
|
); |
|
|
|
'fk_related_model_id', |
|
|
|
await NocoCache.deepDel( |
|
|
|
].some((k) => !column[k]) |
|
|
|
`${CacheScope.COL_LOOKUP}:${colId}`, |
|
|
|
) { |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
insertColOpt = false; |
|
|
|
); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case UITypes.Rollup: { |
|
|
|
|
|
|
|
await ncMeta.metaDelete( |
|
|
|
|
|
|
|
context.workspace_id, |
|
|
|
|
|
|
|
context.base_id, |
|
|
|
|
|
|
|
MetaTable.COL_ROLLUP, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fk_column_id: colId, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
|
|
|
|
`${CacheScope.COL_ROLLUP}:${colId}`, |
|
|
|
|
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
|
|
|
|
); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await ncMeta.metaDelete( |
|
|
|
case UITypes.Links: |
|
|
|
context.workspace_id, |
|
|
|
case UITypes.LinkToAnotherRecord: { |
|
|
|
context.base_id, |
|
|
|
await ncMeta.metaDelete( |
|
|
|
MetaTable.COL_RELATIONS, |
|
|
|
context.workspace_id, |
|
|
|
{ |
|
|
|
context.base_id, |
|
|
|
fk_column_id: colId, |
|
|
|
MetaTable.COL_RELATIONS, |
|
|
|
}, |
|
|
|
{ |
|
|
|
); |
|
|
|
fk_column_id: colId, |
|
|
|
await NocoCache.deepDel( |
|
|
|
}, |
|
|
|
`${CacheScope.COL_RELATION}:${colId}`, |
|
|
|
); |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
await NocoCache.deepDel( |
|
|
|
); |
|
|
|
`${CacheScope.COL_RELATION}:${colId}`, |
|
|
|
break; |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
} |
|
|
|
); |
|
|
|
case UITypes.Formula: { |
|
|
|
break; |
|
|
|
await ncMeta.metaDelete( |
|
|
|
} |
|
|
|
context.workspace_id, |
|
|
|
case UITypes.Formula: { |
|
|
|
context.base_id, |
|
|
|
await ncMeta.metaDelete( |
|
|
|
MetaTable.COL_FORMULA, |
|
|
|
context.workspace_id, |
|
|
|
{ |
|
|
|
context.base_id, |
|
|
|
fk_column_id: colId, |
|
|
|
MetaTable.COL_FORMULA, |
|
|
|
}, |
|
|
|
{ |
|
|
|
); |
|
|
|
fk_column_id: colId, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.deepDel( |
|
|
|
`${CacheScope.COL_FORMULA}:${colId}`, |
|
|
|
`${CacheScope.COL_FORMULA}:${colId}`, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
); |
|
|
|
); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case UITypes.Button: { |
|
|
|
case UITypes.Button: { |
|
|
|
await ncMeta.metaDelete( |
|
|
|
await ncMeta.metaDelete( |
|
|
|
context.workspace_id, |
|
|
|
context.workspace_id, |
|
|
|
context.base_id, |
|
|
|
context.base_id, |
|
|
|
MetaTable.COL_BUTTON, |
|
|
|
MetaTable.COL_BUTTON, |
|
|
|
{ |
|
|
|
{ |
|
|
|
fk_column_id: colId, |
|
|
|
fk_column_id: colId, |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.deepDel( |
|
|
|
`${CacheScope.COL_BUTTON}:${colId}`, |
|
|
|
`${CacheScope.COL_BUTTON}:${colId}`, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
); |
|
|
|
); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case UITypes.QrCode: { |
|
|
|
case UITypes.QrCode: { |
|
|
|
await ncMeta.metaDelete( |
|
|
|
await ncMeta.metaDelete( |
|
|
|
context.workspace_id, |
|
|
|
context.workspace_id, |
|
|
|
context.base_id, |
|
|
|
context.base_id, |
|
|
|
MetaTable.COL_QRCODE, |
|
|
|
MetaTable.COL_QRCODE, |
|
|
|
{ |
|
|
|
{ |
|
|
|
fk_column_id: colId, |
|
|
|
fk_column_id: colId, |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.deepDel( |
|
|
|
`${CacheScope.COL_QRCODE}:${colId}`, |
|
|
|
`${CacheScope.COL_QRCODE}:${colId}`, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
); |
|
|
|
); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case UITypes.Barcode: { |
|
|
|
case UITypes.Barcode: { |
|
|
|
await ncMeta.metaDelete( |
|
|
|
await ncMeta.metaDelete( |
|
|
|
context.workspace_id, |
|
|
|
context.workspace_id, |
|
|
|
context.base_id, |
|
|
|
context.base_id, |
|
|
|
MetaTable.COL_BARCODE, |
|
|
|
MetaTable.COL_BARCODE, |
|
|
|
{ |
|
|
|
{ |
|
|
|
fk_column_id: colId, |
|
|
|
fk_column_id: colId, |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.deepDel( |
|
|
|
`${CacheScope.COL_BARCODE}:${colId}`, |
|
|
|
`${CacheScope.COL_BARCODE}:${colId}`, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
); |
|
|
|
); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case UITypes.MultiSelect: |
|
|
|
case UITypes.MultiSelect: |
|
|
|
case UITypes.SingleSelect: { |
|
|
|
case UITypes.SingleSelect: { |
|
|
|
await ncMeta.metaDelete( |
|
|
|
await ncMeta.metaDelete( |
|
|
|
context.workspace_id, |
|
|
|
context.workspace_id, |
|
|
|
context.base_id, |
|
|
|
context.base_id, |
|
|
|
MetaTable.COL_SELECT_OPTIONS, |
|
|
|
MetaTable.COL_SELECT_OPTIONS, |
|
|
|
{ |
|
|
|
{ |
|
|
|
fk_column_id: colId, |
|
|
|
fk_column_id: colId, |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.deepDel( |
|
|
|
`${CacheScope.COL_SELECT_OPTION}:${colId}:list`, |
|
|
|
`${CacheScope.COL_SELECT_OPTION}:${colId}:list`, |
|
|
|
CacheDelDirection.PARENT_TO_CHILD, |
|
|
|
CacheDelDirection.PARENT_TO_CHILD, |
|
|
|
); |
|
|
|
); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const updateObj = extractProps(column, [ |
|
|
|
const updateObj = extractProps(column, [ |
|
|
|
'column_name', |
|
|
|
'column_name', |
|
|
|
'title', |
|
|
|
'title', |
|
|
@ -1362,7 +1374,7 @@ export default class Column<T = any> implements ColumnType { |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// insert new col options only if existing colOption meta is deleted
|
|
|
|
// insert new col options only if existing colOption meta is deleted
|
|
|
|
if (insertColOpt) |
|
|
|
if (requiredColAvail) |
|
|
|
await this.insertColOption(context, column, colId, ncMeta); |
|
|
|
await this.insertColOption(context, column, colId, ncMeta); |
|
|
|
|
|
|
|
|
|
|
|
// on column update, delete any optimised single query cache
|
|
|
|
// on column update, delete any optimised single query cache
|
|
|
|