Skip to content

Commit

Permalink
Merge pull request #8178 from nocodb/nc-fix/column-delete-bug
Browse files Browse the repository at this point in the history
Nc fix/column delete bug
  • Loading branch information
pranavxc committed Apr 4, 2024
2 parents 5c821bd + 04330cb commit e721491
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 94 deletions.
14 changes: 8 additions & 6 deletions packages/nc-gui/components/cell/Url.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,30 @@ const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false))!
const isForm = inject(IsFormInj)!
const trim = (val: string) => val?.trim?.()
// Used in the logic of when to display error since we are not storing the url if it's not valid
const localState = ref(value)
const vModel = computed({
get: () => value,
set: (val) => {
localState.value = val
if (!parseProp(column.value.meta)?.validate || (val && isValidURL(val)) || !val || isForm.value) {
if (!parseProp(column.value.meta)?.validate || (val && isValidURL(trim(val))) || !val || isForm.value) {
emit('update:modelValue', val)
}
},
})
const isValid = computed(() => value && isValidURL(value))
const isValid = computed(() => value && isValidURL(trim(value)))
const url = computed(() => {
if (!value || !isValidURL(value)) return ''
if (!value || !isValidURL(trim(value))) return ''
/** add url scheme if missing */
if (/^https?:\/\//.test(value)) return value
if (/^https?:\/\//.test(trim(value))) return trim(value)
return `https://${value}`
return `https://${trim(value)}`
})
const { cellUrlOptions } = useCellUrlConfig(url)
Expand All @@ -84,7 +86,7 @@ watch(
parseProp(column.value.meta)?.validate &&
!editEnabled.value &&
localState.value &&
!isValidURL(localState.value)
!isValidURL(trim(localState.value))
) {
message.error(t('msg.error.invalidURL'))
localState.value = undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const {
activeView,
parentId?.value,
computed(() => autoSave.value),
() => reloadDataHook.trigger({ shouldShowLoading: showLoading.value }),
() => reloadDataHook.trigger({ shouldShowLoading: showLoading.value, offset: 0 }),
modelValue.value || nestedFilters.value,
!modelValue.value,
webHook.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const {
unlink,
row,
headerDisplayValue,
resetChildrenExcludedOffsetCount
resetChildrenExcludedOffsetCount,
} = useLTARStoreOrThrow()
const { addLTARRef, isNew, removeLTARRef, state: rowState } = useSmartsheetRowStoreOrThrow()
Expand Down Expand Up @@ -102,7 +102,7 @@ watch(
}
loadChildrenExcludedList(rowState.value)
}
if(!nextVal){
if (!nextVal) {
resetChildrenExcludedOffsetCount()
}
},
Expand Down Expand Up @@ -262,7 +262,7 @@ onUnmounted(() => {
})
const onFilterChange = () => {
childrenExcludedListPagination.page = 1;
childrenExcludedListPagination.page = 1
resetChildrenExcludedOffsetCount()
}
</script>
Expand Down
7 changes: 4 additions & 3 deletions packages/nc-gui/composables/useLTARStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
const loadChildrenExcludedList = async (activeState?: any) => {
if (activeState) newRowState.state = activeState
try {
let offset = childrenExcludedListPagination.size * (childrenExcludedListPagination.page - 1) - childrenExcludedOffsetCount.value
let offset =
childrenExcludedListPagination.size * (childrenExcludedListPagination.page - 1) - childrenExcludedOffsetCount.value

if (offset < 0) {
offset = 0
Expand Down Expand Up @@ -550,8 +551,8 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
})
})

const resetChildrenExcludedOffsetCount = () =>{
childrenExcludedOffsetCount.value = 0;
const resetChildrenExcludedOffsetCount = () => {
childrenExcludedOffsetCount.value = 0
}

const resetChildrenListOffsetCount = () => {
Expand Down
7 changes: 1 addition & 6 deletions packages/nocodb/src/models/CalendarViewColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,13 @@ export default class CalendarViewColumn {
insertObj.source_id = viewRef.source_id;
}

const { id, fk_column_id } = await ncMeta.metaInsert2(
const { id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.CALENDAR_VIEW_COLUMNS,
insertObj,
);

await NocoCache.set(
`${CacheScope.CALENDAR_VIEW_COLUMN}:${fk_column_id}`,
id,
);

{
const view = await View.get(column.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
Expand Down
85 changes: 27 additions & 58 deletions packages/nocodb/src/models/Column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,64 +823,33 @@ export default class Column<T = any> implements ColumnType {
);
}

// Grid View Columns
await ncMeta.metaDelete(null, null, MetaTable.GRID_VIEW_COLUMNS, {
fk_column_id: col.id,
});
const gridViewColumnId = await NocoCache.get(
`${CacheScope.GRID_VIEW_COLUMN}:${col.id}`,
CacheGetType.TYPE_STRING,
);
if (gridViewColumnId) {
await NocoCache.deepDel(
`${CacheScope.GRID_VIEW_COLUMN}:${gridViewColumnId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
}

// Form View Columns
await ncMeta.metaDelete(null, null, MetaTable.FORM_VIEW_COLUMNS, {
fk_column_id: col.id,
});
const formViewColumnId = await NocoCache.get(
`${CacheScope.FORM_VIEW_COLUMN}:${col.id}`,
CacheGetType.TYPE_STRING,
);
if (formViewColumnId) {
await NocoCache.deepDel(
`${CacheScope.FORM_VIEW_COLUMN}:${formViewColumnId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
}

// Kanban View Columns
await ncMeta.metaDelete(null, null, MetaTable.KANBAN_VIEW_COLUMNS, {
fk_column_id: col.id,
});
const kanbanViewColumnId = await NocoCache.get(
`${CacheScope.KANBAN_VIEW_COLUMN}:${col.id}`,
CacheGetType.TYPE_STRING,
);
if (kanbanViewColumnId) {
await NocoCache.deepDel(
`${CacheScope.KANBAN_VIEW_COLUMN}:${kanbanViewColumnId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
}

// Gallery View Column
await ncMeta.metaDelete(null, null, MetaTable.GALLERY_VIEW_COLUMNS, {
fk_column_id: col.id,
});
const galleryViewColumnId = await NocoCache.get(
`${CacheScope.GALLERY_VIEW_COLUMN}:${col.id}`,
CacheGetType.TYPE_STRING,
);
if (galleryViewColumnId) {
await NocoCache.deepDel(
`${CacheScope.GALLERY_VIEW_COLUMN}:${galleryViewColumnId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
// Delete from all view columns
const viewColumnTables = [
MetaTable.GRID_VIEW_COLUMNS,
MetaTable.FORM_VIEW_COLUMNS,
MetaTable.KANBAN_VIEW_COLUMNS,
MetaTable.GALLERY_VIEW_COLUMNS,
];
const viewColumnCacheScope = [
CacheScope.GRID_VIEW_COLUMN,
CacheScope.FORM_VIEW_COLUMN,
CacheScope.KANBAN_VIEW_COLUMN,
CacheScope.GALLERY_VIEW_COLUMN,
];

for (let i = 0; i < viewColumnTables.length; i++) {
const table = viewColumnTables[i];
const cacheScope = viewColumnCacheScope[i];
const viewColumns = await ncMeta.metaList2(null, null, table, {
condition: { fk_column_id: id },
});
await ncMeta.metaDelete(null, null, table, { fk_column_id: id });
for (const viewColumn of viewColumns) {
await NocoCache.deepDel(
`${cacheScope}:${viewColumn.id}`,
CacheDelDirection.CHILD_TO_PARENT,
);
}
}

// Get LTAR columns in which current column is referenced as foreign key
Expand Down
4 changes: 1 addition & 3 deletions packages/nocodb/src/models/FormViewColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ export default class FormViewColumn implements FormColumnType {
insertObj.source_id = viewRef.source_id;
}

const { id, fk_column_id } = await ncMeta.metaInsert2(
const { id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.FORM_VIEW_COLUMNS,
insertObj,
);

await NocoCache.set(`${CacheScope.FORM_VIEW_COLUMN}:${fk_column_id}`, id);

return this.get(id, ncMeta).then(async (viewColumn) => {
await NocoCache.appendToList(
CacheScope.FORM_VIEW_COLUMN,
Expand Down
7 changes: 1 addition & 6 deletions packages/nocodb/src/models/GalleryViewColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,13 @@ export default class GalleryViewColumn {
insertObj.source_id = viewRef.source_id;
}

const { id, fk_column_id } = await ncMeta.metaInsert2(
const { id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.GALLERY_VIEW_COLUMNS,
insertObj,
);

await NocoCache.set(
`${CacheScope.GALLERY_VIEW_COLUMN}:${fk_column_id}`,
id,
);

// on new view column, delete any optimised single query cache
{
const view = await View.get(column.fk_view_id, ncMeta);
Expand Down
2 changes: 0 additions & 2 deletions packages/nocodb/src/models/GridViewColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ export default class GridViewColumn implements GridColumnType {
insertObj,
);

await NocoCache.set(`${CacheScope.GRID_VIEW_COLUMN}:${fk_column_id}`, id);

await View.fixPVColumnForView(column.fk_view_id, ncMeta);

// on new view column, delete any optimised single query cache
Expand Down
4 changes: 1 addition & 3 deletions packages/nocodb/src/models/KanbanViewColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ export default class KanbanViewColumn implements KanbanColumnType {
insertObj.source_id = viewRef.source_id;
}

const { id, fk_column_id } = await ncMeta.metaInsert2(
const { id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.KANBAN_VIEW_COLUMNS,
insertObj,
);

await NocoCache.set(`${CacheScope.KANBAN_VIEW_COLUMN}:${fk_column_id}`, id);

return this.get(id, ncMeta).then(async (kanbanViewColumn) => {
await NocoCache.appendToList(
CacheScope.KANBAN_VIEW_COLUMN,
Expand Down
4 changes: 1 addition & 3 deletions packages/nocodb/src/models/MapViewColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ export default class MapViewColumn {
insertObj.source_id = viewRef.source_id;
}

const { id, fk_column_id } = await ncMeta.metaInsert2(
const { id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.MAP_VIEW_COLUMNS,
insertObj,
);

await NocoCache.set(`${CacheScope.MAP_VIEW_COLUMN}:${fk_column_id}`, id);

return this.get(id, ncMeta).then(async (viewCol) => {
await NocoCache.appendToList(
CacheScope.MAP_VIEW_COLUMN,
Expand Down
4 changes: 4 additions & 0 deletions packages/nocodb/src/services/views.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class ViewsService {
}) {
const model = await Model.get(param.tableId);

if (!model) {
NcError.tableNotFound(param.tableId);
}

const viewList = await xcVisibilityMetaGet({
baseId: model.base_id,
models: [model],
Expand Down

0 comments on commit e721491

Please sign in to comment.