π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix: use filterArrJson for group by filter to avoid issue with special chars
Pranav Ccefc4a6b1ba6
diff --git a/packages/nc-gui/composables/useGridViewData.ts b/packages/nc-gui/composables/useGridViewData.tsindex 4398fb9e0c..9534bce08d 100644--- a/packages/nc-gui/composables/useGridViewData.ts+++ b/packages/nc-gui/composables/useGridViewData.ts@@ -52,6 +52,7 @@ export function useGridViewData(groupByColumns,isGroupBy,buildNestedWhere,+ buildNestedFilterArr,clearGroupCache,syncCount: groupSyncCount,fetchMissingGroupChunks,@@ -102,6 +103,7 @@ export function useGridViewData(syncVisibleData,getCount,getWhereFilter: getGroupFilter,+ getWhereFilterArr: getGroupFilterJsonArr,reloadAggregate: triggerAggregateReload,findGroupByPath: (path?: Array<number>) => {return findGroupByPath(cachedGroups.value, path)@@ -249,6 +251,51 @@ export function useGridViewData(return buildNestedWhere(group, ignoreWhereFilter ? '' : where?.value)}+ async function getGroupFilterJsonArr(path: Array<number> = [], ignoreWhereFilter = false) {+ let group = findGroupByPath(cachedGroups.value, path)++ if (!group) {+ try {+ let currentGroups = cachedGroups.value+ let parentGroup: CanvasGroup | undefined+ let targetIndex: number | undefined++ for (let depth = 0; depth < path.length; depth++) {+ const groupIndex = path[depth]+ const currentGroup = currentGroups.get(groupIndex)++ if (!currentGroup) {+ targetIndex = groupIndex+ break+ }++ if (depth === path.length - 1) {+ targetIndex = groupIndex+ break+ }++ if (!currentGroup.isExpanded || !currentGroup.groups) {+ return ''+ }++ parentGroup = currentGroup+ currentGroups = currentGroup.groups+ }++ if (targetIndex !== undefined) {+ await fetchMissingGroupChunks(targetIndex, targetIndex, parentGroup)+ }++ group = findGroupByPath(cachedGroups.value, path)+ } catch (error) {+ console.error(`Failed to load group for path ${path}:`, error)+ return ''+ }+ }++ return buildNestedFilterArr(group)+ }+function syncVisibleData() {reloadVisibleDataHook?.trigger()}diff --git a/packages/nc-gui/composables/useInfiniteData.ts b/packages/nc-gui/composables/useInfiniteData.tsindex 24416bfdba..9a433f0eae 100644--- a/packages/nc-gui/composables/useInfiniteData.ts+++ b/packages/nc-gui/composables/useInfiniteData.ts@@ -67,6 +67,7 @@ export function useInfiniteData(args: {syncVisibleData?: () => voidgetCount?: (path: Array<number>) => voidgetWhereFilter?: (path: Array<number>, ignoreWhereFilter?: boolean) => Promise<string>+ getWhereFilterArr?: (path: Array<number>) => Promise<string>reloadAggregate?: (params: {fields?: Array<{ title: string; aggregation?: string | undefined }>path: Array<number>@@ -375,14 +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 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(nestedFilters.value) }),+ ...(isUIAllowed('filterSync')+ ? { filterArrJson: JSON.stringify(filterArrJson) }+ : { filterArrJson: JSON.stringify([...nestedFilters.value, ...filterArrJson]) }),})}@@ -592,7 +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 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) {@@ -620,16 +625,18 @@ export function useInfiniteData(args: {? await $api.dbViewRow.list('noco', base.value.id!, meta.value!.id!, viewMeta.value!.id!, {...params,...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }),- ...(isUIAllowed('filterSync') ? {} : { filterArrJson: JSON.stringify(nestedFilters.value) }),+ ...(isUIAllowed('filterSync')+ ? { filterArrJson: JSON.stringify(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,- 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.tsindex c151880aaf..ae7cecf35b 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) returntry {- const nestedWhere = parentGroup ? buildNestedWhere(parentGroup, where?.value) : where.value+ const nestedWhere = where.valueconst response = isPublic.value? await $api.public.dataGroupBy(@@ -125,7 +125,7 @@ export const useInfiniteGroups = (column_name: groupCol.column.title,subGroupColumnName: groupByColumns.value[level + 1]?.column.title,sortArrJson: JSON.stringify(sorts.value),- filterArrJson: JSON.stringify(nestedFilters.value),+ filterArrJson: JSON.stringify([...nestedFilters.value, ...buildNestedFilterArr(parentGroup) ]),},{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),+ filterArrJson: JSON.stringify([...nestedFilters.value, ...buildNestedFilterArr(parentGroup) ]),subGroupColumnName: groupByColumns.value[level + 1]?.column.title,})@@ -220,6 +220,7 @@ export const useInfiniteGroups = (column_name: groupCol.column.title!,key: value,column_uidt: groupCol.column.uidt,+ column_id: groupCol.column.id,groupIndex,},]@@ -229,6 +230,7 @@ export const useInfiniteGroups = (column_name: groupCol.column.title!,key: value,column_uidt: groupCol.column.uidt,+ column_id: groupCol.column.id,groupIndex,},],@@ -273,9 +275,9 @@ export const useInfiniteGroups = (.filter((f) => f.type !== CommonAggregations.None)const aggregationParams = groups.map((group) => ({- where: buildNestedWhere(group, where?.value),+ where: where?.value,alias: aggregationAliasMapper.generateAlias(group.value),- filterArrJson: JSON.stringify(nestedFilters.value),+ filterArrJson: JSON.stringify([...nestedFilters.value, ...buildNestedFilterArr(group)]),}))let aggResponse = {}@@ -337,26 +339,86 @@ export const useInfiniteGroups = (// Use nestedIn array instead of traversing parentsif (!group?.nestedIn?.length) return existing+ const sanitiseValue = (value: string) => {+ return `"${value}"` // .replace(/"/g, '\\"')}`+ }++ return group.nestedIn.reduce((acc, curr) => {+ if (curr.key === GROUP_BY_VARS.NULL) {+ acc += `${acc.length ? '~and' : '@'}(${curr.title},gb_null)`+ } else if (curr.column_uidt === UITypes.Checkbox) {+ acc += `${acc.length ? '~and' : '@'}(${curr.title},${curr.key === GROUP_BY_VARS.TRUE ? 'checked' : 'notchecked'})`+ } 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)})`+ } 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(','),+ )})`+ } catch (e) {+ console.error(e)+ }+ } else {+ acc += `${acc.length ? '~and' : '@'}(${curr.title},gb_eq,${sanitiseValue(curr.key)})`+ }+ return acc+ }, existing)+ }++ function buildNestedFilterArr(group: CanvasGroup, existing: any[] = []): string {+ // Use nestedIn array instead of traversing parents+ if (!group?.nestedIn?.length) return existing+return group.nestedIn.reduce((acc, curr) => {if (curr.key === GROUP_BY_VARS.NULL) {- acc += `${acc.length ? '~and' : ''}(${curr.title},gb_null)`+ // acc += `${acc.length ? '~and' : '@'}(${curr.title},gb_null)`+ acc.push({+ fk_column_id: curr.column_id,+ 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 += `${acc.length ? '~and' : '@'}(${curr.title},${curr.key === GROUP_BY_VARS.TRUE ? 'checked' : 'notchecked'})`++ acc.push({+ fk_column_id: curr.column_id,+ comparison_op: 'is',+ value: curr.key === GROUP_BY_VARS.TRUE ? 'checked' : 'notchecked',+ })} 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,${curr.key})`+ // acc += `${acc.length ? '~and' : '@'}(${curr.title},gb_eq,exactDate,"${sanitiseValue(curr.key)}")`+ acc.push({+ fk_column_id: curr.column_id,+ comparison_op: 'gb_eq',+ comparison_sub_op: 'exactDate',+ value: curr.key,+ })} 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,${(Array.isArray(value) ? value : [value])- .map((v: any) => v.id)- .join(',')})`+ // 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,+ comparison_op: 'gb_eq',+ value: (Array.isArray(value) ? value : [value]).map((v: any) => v.id).join(','),+ })} catch (e) {console.error(e)}} else {- acc += `${acc.length ? '~and' : ''}(${curr.title},gb_eq,${curr.key})`+ // 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}, existing)@@ -464,9 +526,12 @@ export const useInfiniteGroups = (? await $api.public.dataGroupByCount(sharedView.value!.uuid!,{- where: groupWhere,+ where: where?.value,column_name: groupCol.column.title,- filterArrJson: JSON.stringify(nestedFilters.value),+ filterArrJson: JSON.stringify([+ ...(nestedFilters.value || []),+ ...buildNestedFilterArr(group)+ ]),},{headers: {@@ -481,7 +546,13 @@ export const useInfiniteGroups = (}}- async function updateGroupAggregations(groups: CanvasGroup[], fields?: Array<{ title: string; aggregation?: string }>) {+ async function updateGroupAggregations(+ groups: CanvasGroup[],+ fields?: Array<{+ title: string+ aggregation?: string+ }>,+ ) {if (!appInfo.value?.ee) returnconst BATCH_SIZE = 100@@ -522,9 +593,9 @@ export const useInfiniteGroups = (const batchGroups = groups.slice(i, i + BATCH_SIZE)const aggregationParams = batchGroups.map((group) => ({- where: buildNestedWhere(group, where?.value),+ where: where?.value,alias: aggregationAliasMapper.generateAlias(createGroupUniqueIdentifier(group)),- filterArrJson: JSON.stringify(nestedFilters.value),+ filterArrJson: JSON.stringify([...nestedFilters.value, ...buildNestedFilterArr(group)]),}))try {@@ -645,6 +716,7 @@ export const useInfiniteGroups = (toggleExpand,GROUP_CHUNK_SIZE,buildNestedWhere,+ buildNestedFilterArr,CHUNK_SIZE: 50,columnsById,gridViewColByTitle,diff --git a/packages/nc-gui/composables/useViewGroupBy.ts b/packages/nc-gui/composables/useViewGroupBy.tsindex 057c0a3561..bbaccbc470 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)@@ -214,6 +214,7 @@ const [useProvideViewGroupBy, useViewGroupBy] = useInjectionState(column_name: groupby.column.title!,key: valueToTitle(curr[groupby.column.title!], groupby.column),column_uidt: groupby.column.uidt,+ column_id: groupby.column.id,},],aggregations: curr.aggregations ?? {},diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.tsindex e264f728b8..10ab88470c 100644--- a/packages/nc-gui/lib/types.ts+++ b/packages/nc-gui/lib/types.ts@@ -247,6 +247,7 @@ interface GroupNestedIn {column_name: stringkey: stringcolumn_uidt: string+ column_id: stringgroupIndex?: number}