Browse Source

refactor: avoid duplicate code

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/8178/head
Pranav C 8 months ago
parent
commit
fd275a143d
  1. 14
      packages/nc-gui/components/cell/Url.vue
  2. 6
      packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue
  3. 7
      packages/nc-gui/composables/useLTARStore.ts
  4. 95
      packages/nocodb/src/models/Column.ts

14
packages/nc-gui/components/cell/Url.vue

@ -47,7 +47,7 @@ const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false))!
const isForm = inject(IsFormInj)!
const trimVal = (val:string) => val && (val + '').trim();
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)
@ -56,21 +56,21 @@ const vModel = computed({
get: () => value,
set: (val) => {
localState.value = val
if (!parseProp(column.value.meta)?.validate || (val && isValidURL(trimVal(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(trimVal(value)))
const isValid = computed(() => value && isValidURL(trim(value)))
const url = computed(() => {
if (!value || !isValidURL(trimVal(value))) return ''
if (!value || !isValidURL(trim(value))) return ''
/** add url scheme if missing */
if (/^https?:\/\//.test(trimVal(value))) return trimVal(value)
if (/^https?:\/\//.test(trim(value))) return trim(value)
return `https://${trimVal(value)}`
return `https://${trim(value)}`
})
const { cellUrlOptions } = useCellUrlConfig(url)
@ -86,7 +86,7 @@ watch(
parseProp(column.value.meta)?.validate &&
!editEnabled.value &&
localState.value &&
!isValidURL(trimVal(localState.value))
!isValidURL(trim(localState.value))
) {
message.error(t('msg.error.invalidURL'))
localState.value = undefined

6
packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue

@ -51,7 +51,7 @@ const {
unlink,
row,
headerDisplayValue,
resetChildrenExcludedOffsetCount
resetChildrenExcludedOffsetCount,
} = useLTARStoreOrThrow()
const { addLTARRef, isNew, removeLTARRef, state: rowState } = useSmartsheetRowStoreOrThrow()
@ -102,7 +102,7 @@ watch(
}
loadChildrenExcludedList(rowState.value)
}
if(!nextVal){
if (!nextVal) {
resetChildrenExcludedOffsetCount()
}
},
@ -262,7 +262,7 @@ onUnmounted(() => {
})
const onFilterChange = () => {
childrenExcludedListPagination.page = 1;
childrenExcludedListPagination.page = 1
resetChildrenExcludedOffsetCount()
}
</script>

7
packages/nc-gui/composables/useLTARStore.ts

@ -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
@ -550,8 +551,8 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
})
})
const resetChildrenExcludedOffsetCount = () =>{
childrenExcludedOffsetCount.value = 0;
const resetChildrenExcludedOffsetCount = () => {
childrenExcludedOffsetCount.value = 0
}
const resetChildrenListOffsetCount = () => {

95
packages/nocodb/src/models/Column.ts

@ -823,84 +823,33 @@ export default class Column<T = any> implements ColumnType {
);
}
// Grid View Columns
const gridViewColumns = await ncMeta.metaList2(
null,
null,
// Delete from all view columns
const viewColumnTables = [
MetaTable.GRID_VIEW_COLUMNS,
{
condition: { fk_column_id: id },
},
);
await ncMeta.metaDelete(null, null, MetaTable.GRID_VIEW_COLUMNS, {
fk_column_id: id,
});
for (const gridViewColumn of gridViewColumns) {
await NocoCache.deepDel(
`${CacheScope.GRID_VIEW_COLUMN}:${gridViewColumn.id}`,
CacheDelDirection.CHILD_TO_PARENT,
);
}
// Form View Columns
const formViewColumns = await ncMeta.metaList2(
null,
null,
MetaTable.FORM_VIEW_COLUMNS,
{
condition: { fk_column_id: id },
},
);
await ncMeta.metaDelete(null, null, MetaTable.FORM_VIEW_COLUMNS, {
fk_column_id: id,
});
for (const formViewColumn of formViewColumns) {
await NocoCache.deepDel(
`${CacheScope.FORM_VIEW_COLUMN}:${formViewColumn.id}`,
CacheDelDirection.CHILD_TO_PARENT,
);
}
// Kanban View Columns
const kanbanViewColumns = await ncMeta.metaList2(
null,
null,
MetaTable.KANBAN_VIEW_COLUMNS,
{
condition: { fk_column_id: id },
},
);
await ncMeta.metaDelete(null, null, MetaTable.KANBAN_VIEW_COLUMNS, {
fk_column_id: id,
});
for (const kanbanViewColumn of kanbanViewColumns) {
await NocoCache.deepDel(
`${CacheScope.KANBAN_VIEW_COLUMN}:${kanbanViewColumn.id}`,
CacheDelDirection.CHILD_TO_PARENT,
);
}
// Gallery View Column
const galleryViewColumns = await ncMeta.metaList2(
null,
null,
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; 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, MetaTable.GALLERY_VIEW_COLUMNS, {
fk_column_id: id,
});
for (const galleryViewColumn of galleryViewColumns) {
await NocoCache.deepDel(
`${CacheScope.GALLERY_VIEW_COLUMN}:${galleryViewColumn.id}`,
CacheDelDirection.CHILD_TO_PARENT,
);
});
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

Loading…
Cancel
Save