|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import type { ColumnType, FilterType, ViewType } from 'nocodb-sdk' |
|
|
|
|
import type { ColumnType, FilterType, LinkToAnotherRecordType, LookupType, ViewType } from 'nocodb-sdk' |
|
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
|
import type { SelectProps } from 'ant-design-vue' |
|
|
|
|
import { UITypes, isSystemColumn } from 'nocodb-sdk' |
|
|
|
|
import { RelationTypes, UITypes, isSystemColumn } from 'nocodb-sdk' |
|
|
|
|
import { |
|
|
|
|
ActiveViewInj, |
|
|
|
|
IsPublicInj, |
|
|
|
@ -32,6 +32,8 @@ export function useViewFilters(
|
|
|
|
|
) { |
|
|
|
|
const currentFilters = ref(_currentFilters) |
|
|
|
|
|
|
|
|
|
const btLookupTypesMap = ref({}) |
|
|
|
|
|
|
|
|
|
const reloadHook = inject(ReloadViewDataHookInj) |
|
|
|
|
|
|
|
|
|
const { nestedFilters } = useSmartsheetStoreOrThrow() |
|
|
|
@ -44,7 +46,7 @@ export function useViewFilters(
|
|
|
|
|
|
|
|
|
|
const { isUIAllowed } = useRoles() |
|
|
|
|
|
|
|
|
|
const { metas } = useMetas() |
|
|
|
|
const { metas, getMeta } = useMetas() |
|
|
|
|
|
|
|
|
|
const { addUndo, clone, defineViewScope } = useUndoRedo() |
|
|
|
|
|
|
|
|
@ -101,7 +103,12 @@ export function useViewFilters(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return meta.value?.columns?.reduce((obj: any, col: any) => { |
|
|
|
|
obj[col.id] = col.uidt |
|
|
|
|
// if column is a lookup column, then use the lookup type extracted from the column
|
|
|
|
|
if (btLookupTypesMap.value[col.id]) { |
|
|
|
|
obj[col.id] = btLookupTypesMap.value[col.id].uidt |
|
|
|
|
} else { |
|
|
|
|
obj[col.id] = col.uidt |
|
|
|
|
} |
|
|
|
|
return obj |
|
|
|
|
}, {}) |
|
|
|
|
}) |
|
|
|
@ -425,6 +432,43 @@ export function useViewFilters(
|
|
|
|
|
}, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// method to extract looked up column meta for all bt lookup columns
|
|
|
|
|
// it helps to decide the condition operations for the column
|
|
|
|
|
const loadBtLookupTypes = async () => { |
|
|
|
|
const btLookupTypes = {} |
|
|
|
|
try { |
|
|
|
|
for (const col of meta.value?.columns || []) { |
|
|
|
|
if (col.uidt !== UITypes.Lookup) continue |
|
|
|
|
let nextCol = col |
|
|
|
|
let btLookup = true |
|
|
|
|
// check all the relation of nested lookup columns is bt or not
|
|
|
|
|
// include the column only if all only if all relations are bt
|
|
|
|
|
while (btLookup && nextCol && nextCol.uidt === UITypes.Lookup) { |
|
|
|
|
const lookupRelation = (await getMeta(nextCol.fk_model_id))?.columns?.find( |
|
|
|
|
(c) => c.id === (nextCol.colOptions as LookupType).fk_relation_column_id, |
|
|
|
|
) |
|
|
|
|
if ((lookupRelation.colOptions as LinkToAnotherRecordType).type !== RelationTypes.BELONGS_TO) { |
|
|
|
|
btLookup = false |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
const relatedTableMeta = await getMeta((lookupRelation.colOptions as LinkToAnotherRecordType).fk_related_model_id) |
|
|
|
|
nextCol = relatedTableMeta?.columns?.find((c) => c.id === (nextCol.colOptions as LookupType).fk_lookup_column_id) |
|
|
|
|
|
|
|
|
|
// if next column is same as root lookup column then break the loop
|
|
|
|
|
// since it's going to be a circular loop
|
|
|
|
|
if (nextCol.id === col.id) { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
btLookupTypes[col.id] = nextCol |
|
|
|
|
} |
|
|
|
|
btLookupTypesMap.value = btLookupTypes |
|
|
|
|
} catch (e) { |
|
|
|
|
// ignore error since it is not blocking any functionality of the app
|
|
|
|
|
console.error(e) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
filters, |
|
|
|
|
nonDeletedFilters, |
|
|
|
@ -437,5 +481,7 @@ export function useViewFilters(
|
|
|
|
|
saveOrUpdateDebounced, |
|
|
|
|
isComparisonOpAllowed, |
|
|
|
|
isComparisonSubOpAllowed, |
|
|
|
|
loadBtLookupTypes, |
|
|
|
|
btLookupTypesMap, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|