Skip to content

Commit

Permalink
refactor: avoid duplicate code
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav C <pranavxc@gmail.com>
  • Loading branch information
pranavxc committed Apr 4, 2024
1 parent a367f5d commit fd275a1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 86 deletions.
14 changes: 7 additions & 7 deletions packages/nc-gui/components/cell/Url.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
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
95 changes: 22 additions & 73 deletions packages/nocodb/src/models/Column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit fd275a1

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR changes have been deployed. Please run the following command to verify:

docker run -d -p 8888:8080 nocodb/nocodb-timely:0.204.9-pr-8178-20240404-1110

Please sign in to comment.