Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

refactor: cleanup and refactoring

Pranav Cc60bc8e66e89
diff --git a/packages/nc-gui/components/cell/attachment/Card.vue b/packages/nc-gui/components/cell/attachment/Card.vue
index eb63ceb4c4..36eb8e4a01 100644
--- a/packages/nc-gui/components/cell/attachment/Card.vue
+++ b/packages/nc-gui/components/cell/attachment/Card.vue
@@ -126,8 +126,8 @@ const handleFileDeleteStart = () => {
/>
<component :is="FileIcon(attachment.icon)" v-else-if="attachment.icon" :height="45" :width="45" class="text-white" />
<GeneralIcon
- :icon ="getAttachmentIcon(attachment.title, attachment.mimetype)"
v-else
+ :icon="getAttachmentIcon(attachment.title, attachment.mimetype)"
:height="45"
:width="45"
class="text-white"
diff --git a/packages/nc-gui/composables/useGridViewData.ts b/packages/nc-gui/composables/useGridViewData.ts
index 9534bce08d..b61fbf57ac 100644
--- a/packages/nc-gui/composables/useGridViewData.ts
+++ b/packages/nc-gui/composables/useGridViewData.ts
@@ -102,8 +102,7 @@ export function useGridViewData(
callbacks: {
syncVisibleData,
getCount,
- getWhereFilter: getGroupFilter,
- getWhereFilterArr: getGroupFilterJsonArr,
+ getWhereFilterArr: getGroupFilterArr,
reloadAggregate: triggerAggregateReload,
findGroupByPath: (path?: Array<number>) => {
return findGroupByPath(cachedGroups.value, path)
@@ -251,7 +250,7 @@ export function useGridViewData(
return buildNestedWhere(group, ignoreWhereFilter ? '' : where?.value)
}
- async function getGroupFilterJsonArr(path: Array<number> = [], ignoreWhereFilter = false) {
+ async function getGroupFilterArr(path: Array<number> = [], ignoreWhereFilter = false) {
let group = findGroupByPath(cachedGroups.value, path)
if (!group) {
diff --git a/packages/nc-gui/composables/useInfiniteData.ts b/packages/nc-gui/composables/useInfiniteData.ts
index 9a433f0eae..91cb258410 100644
--- a/packages/nc-gui/composables/useInfiniteData.ts
+++ b/packages/nc-gui/composables/useInfiniteData.ts
@@ -67,7 +67,7 @@ export function useInfiniteData(args: {
syncVisibleData?: () => void
getCount?: (path: Array<number>) => void
getWhereFilter?: (path: Array<number>, ignoreWhereFilter?: boolean) => Promise<string>
- getWhereFilterArr?: (path: Array<number>) => Promise<string>
+ getWhereFilterArr?: (path: Array<number>) => Promise<FilterType[]>
reloadAggregate?: (params: {
fields?: Array<{ title: string; aggregation?: string | undefined }>
path: Array<number>
@@ -376,17 +376,17 @@ export function useInfiniteData(args: {
for (let i = 0; i < batch.length; i++) {
const req = batch[i]
- // const where = await callbacks?.getWhereFilter?.(req.path)
- const filterArrJson = await callbacks?.getWhereFilterArr(req.path)
+ const where = await callbacks?.getWhereFilter?.(req.path)
+ const filterArrJson = (await callbacks?.getWhereFilterArr(req.path)) ?? []
bulkRequests.push({
- // where,
+ where,
offset: req.chunkId * CHUNK_SIZE,
limit: CHUNK_SIZE,
alias: `chunk_${req.chunkId}_${req.path.join('_')}`,
...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }),
...(isUIAllowed('filterSync')
? { filterArrJson: JSON.stringify(filterArrJson) }
- : { filterArrJson: JSON.stringify([...nestedFilters.value, ...filterArrJson]) }),
+ : { filterArrJson: JSON.stringify([...(nestedFilters.value ?? []), ...filterArrJson]) }),
})
}
@@ -596,8 +596,8 @@ export function useInfiniteData(args: {
): Promise<Row[]> {
if ((!base?.value?.id || !meta.value?.id || !viewMeta.value?.id) && !isPublic?.value) return []
- // const whereFilter = await callbacks?.getWhereFilter?.(path)
- const jsonWhereFilterArr = await callbacks?.getWhereFilterArr?.(path)
+ const whereFilter = await callbacks?.getWhereFilter?.(path)
+ const jsonWhereFilterArr = (await callbacks?.getWhereFilterArr?.(path)) ?? []
if (!disableSmartsheet && !path.length && params.offset && blockExternalSourceRecordVisibility(isExternalSource.value)) {
if (!isAlreadyShownUpgradeModal.value && params.offset >= EXTERNAL_SOURCE_VISIBLE_ROWS) {
@@ -627,16 +627,16 @@ export function useInfiniteData(args: {
...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }),
...(isUIAllowed('filterSync')
? { filterArrJson: JSON.stringify(jsonWhereFilterArr) }
- : { filterArrJson: JSON.stringify([...nestedFilters.value, ...jsonWhereFilterArr]) }),
+ : { filterArrJson: JSON.stringify([...(nestedFilters.value || []), ...jsonWhereFilterArr]) }),
includeSortAndFilterColumns: true,
- // where: whereFilter,
+ where: whereFilter,
include_row_color: true,
} as any)
: await fetchSharedViewData(
{
sortsArr: sorts.value,
- filtersArr: [...nestedFilters.value, ...jsonWhereFilterArr],
- // where: whereFilter,
+ filtersArr: [...(nestedFilters.value || []), ...jsonWhereFilterArr],
+ where: whereFilter,
offset: params.offset,
limit: params.limit,
},
diff --git a/packages/nc-gui/composables/useInfiniteGroups.ts b/packages/nc-gui/composables/useInfiniteGroups.ts
index ae7cecf35b..2898cf6f05 100644
--- a/packages/nc-gui/composables/useInfiniteGroups.ts
+++ b/packages/nc-gui/composables/useInfiniteGroups.ts
@@ -112,7 +112,7 @@ export const useInfiniteGroups = (
if (!groupCol || !view.value?.id || !base.value?.id) return
try {
- const nestedWhere = where.value
+ const nestedGrpWhereArr = buildNestedFilterArr(parentGroup) ?? []
const response = isPublic.value
? await $api.public.dataGroupBy(
@@ -120,12 +120,12 @@ export const useInfiniteGroups = (
{
offset,
limit: GROUP_CHUNK_SIZE,
- where: nestedWhere,
+ where: where.value,
sort: `${getSortParams(groupCol.sort)}${groupCol.column.title}` as any,
column_name: groupCol.column.title,
subGroupColumnName: groupByColumns.value[level + 1]?.column.title,
sortArrJson: JSON.stringify(sorts.value),
- filterArrJson: JSON.stringify([...nestedFilters.value, ...buildNestedFilterArr(parentGroup) ]),
+ filterArrJson: JSON.stringify([...(nestedFilters.value ?? []), ...nestedGrpWhereArr]),
},
{
headers: {
@@ -140,7 +140,7 @@ export const useInfiniteGroups = (
sort: `${getSortParams(groupCol.sort)}${groupCol.column.title}` as any,
column_name: groupCol.column.title,
sortArrJson: JSON.stringify(sorts.value),
- filterArrJson: JSON.stringify([...nestedFilters.value, ...buildNestedFilterArr(parentGroup) ]),
+ filterArrJson: JSON.stringify([...(nestedFilters.value || []), ...nestedGrpWhereArr]),
subGroupColumnName: groupByColumns.value[level + 1]?.column.title,
})
@@ -368,7 +368,7 @@ export const useInfiniteGroups = (
}, existing)
}
- function buildNestedFilterArr(group: CanvasGroup, existing: any[] = []): string {
+ function buildNestedFilterArr(group: CanvasGroup, existing: FilterType[] = []): FilterType[] {
// Use nestedIn array instead of traversing parents
if (!group?.nestedIn?.length) return existing
@@ -380,8 +380,6 @@ export const useInfiniteGroups = (
comparison_op: 'gb_null',
})
} else if (curr.column_uidt === UITypes.Checkbox) {
- // acc += `${acc.length ? '~and' : '@'}(${curr.title},${curr.key === GROUP_BY_VARS.TRUE ? 'checked' : 'notchecked'})`
-
acc.push({
fk_column_id: curr.column_id,
comparison_op: 'is',
@@ -390,7 +388,6 @@ export const useInfiniteGroups = (
} else if (
[UITypes.Date, UITypes.DateTime, UITypes.CreatedTime, UITypes.LastModifiedTime].includes(curr.column_uidt as UITypes)
) {
- // acc += `${acc.length ? '~and' : '@'}(${curr.title},gb_eq,exactDate,"${sanitiseValue(curr.key)}")`
acc.push({
fk_column_id: curr.column_id,
comparison_op: 'gb_eq',
@@ -400,9 +397,6 @@ export const useInfiniteGroups = (
} else if ([UITypes.User, UITypes.CreatedBy, UITypes.LastModifiedBy].includes(curr.column_uidt as UITypes)) {
try {
const value = JSON.parse(curr.key)
- // acc += `${acc.length ? '~and' : '@'}(${curr.title},gb_eq,"${sanitiseValue(
- // (Array.isArray(value) ? value : [value]).map((v: any) => v.id).join(','),
- // )}")`
acc.push({
fk_column_id: curr.column_id,
@@ -413,14 +407,13 @@ export const useInfiniteGroups = (
console.error(e)
}
} else {
- // acc += `${acc.length ? '~and' : '@'}(${curr.title},gb_eq,"${sanitiseValue(curr.key)}")`
acc.push({
fk_column_id: curr.column_id,
comparison_op: 'gb_eq',
value: curr.key,
})
}
- return acc
+ return acc ?? []
}, existing)
}
@@ -520,7 +513,7 @@ export const useInfiniteGroups = (
if (!groupCol) return
- const groupWhere = buildNestedWhere(group, where?.value)
+ const groupFilterArr = buildNestedFilterArr(group) ?? []
group.groupCount = isPublic.value
? await $api.public.dataGroupByCount(
@@ -528,10 +521,7 @@ export const useInfiniteGroups = (
{
where: where?.value,
column_name: groupCol.column.title,
- filterArrJson: JSON.stringify([
- ...(nestedFilters.value || []),
- ...buildNestedFilterArr(group)
- ]),
+ filterArrJson: JSON.stringify([...(nestedFilters.value || []), ...groupFilterArr]),
},
{
headers: {
@@ -540,8 +530,9 @@ export const useInfiniteGroups = (
},
)
: await $api.dbViewRow.groupByCount('noco', base.value.id!, view.value.fk_model_id, view.value.id!, {
- where: groupWhere,
+ where: where?.value,
column_name: groupCol.column.title,
+ filterArrJson: JSON.stringify(groupFilterArr),
})
}
}
@@ -595,7 +586,7 @@ export const useInfiniteGroups = (
const aggregationParams = batchGroups.map((group) => ({
where: where?.value,
alias: aggregationAliasMapper.generateAlias(createGroupUniqueIdentifier(group)),
- filterArrJson: JSON.stringify([...nestedFilters.value, ...buildNestedFilterArr(group)]),
+ filterArrJson: JSON.stringify([...(nestedFilters.value || []), ...buildNestedFilterArr(group)]),
}))
try {
diff --git a/packages/nc-gui/composables/useViewGroupBy.ts b/packages/nc-gui/composables/useViewGroupBy.ts
index bbaccbc470..1c70d0c6ee 100644
--- a/packages/nc-gui/composables/useViewGroupBy.ts
+++ b/packages/nc-gui/composables/useViewGroupBy.ts
@@ -163,7 +163,7 @@ const [useProvideViewGroupBy, useViewGroupBy] = useInjectionState(
console.error(e)
}
} else {
- acc += `${acc.length ? '~and' : '@'}(${curr.title},gb_eq,"${curr.key}")`
+ acc += `${acc.length ? '~and' : ''}(${curr.title},gb_eq,${curr.key})`
}
return acc
}, existing)
diff --git a/packages/nc-gui/utils/fileUtils.ts b/packages/nc-gui/utils/fileUtils.ts
index 5279ab439d..667d5264b9 100644
--- a/packages/nc-gui/utils/fileUtils.ts
+++ b/packages/nc-gui/utils/fileUtils.ts
@@ -176,8 +176,10 @@ export const getReadableFileSize = (sizeInBytes: number) => {
return `${(sizeInBytes / 1024 ** i).toFixed(2) * 1} ${['B', 'KB', 'MB', 'GB', 'TB'][i]}`
}
-export const getAttachmentIcon = ( title: MaybeRefOrGetter<string | undefined>,
- mimetype: MaybeRefOrGetter<string | undefined>,) => {
+export const getAttachmentIcon = (
+ title: MaybeRefOrGetter<string | undefined>,
+ mimetype: MaybeRefOrGetter<string | undefined>,
+) => {
if (isImage(toValue(title) || '', toValue(mimetype))) {
return 'ncFileTypeImage'
}