|
|
@ -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 { ComputedRef, Ref } from 'vue' |
|
|
|
import type { SelectProps } from 'ant-design-vue' |
|
|
|
import type { SelectProps } from 'ant-design-vue' |
|
|
|
import { UITypes, isSystemColumn } from 'nocodb-sdk' |
|
|
|
import { RelationTypes, UITypes, isSystemColumn } from 'nocodb-sdk' |
|
|
|
import { |
|
|
|
import { |
|
|
|
ActiveViewInj, |
|
|
|
ActiveViewInj, |
|
|
|
IsPublicInj, |
|
|
|
IsPublicInj, |
|
|
@ -32,6 +32,8 @@ export function useViewFilters( |
|
|
|
) { |
|
|
|
) { |
|
|
|
const currentFilters = ref(_currentFilters) |
|
|
|
const currentFilters = ref(_currentFilters) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const btLookupTypesMap = ref({}) |
|
|
|
|
|
|
|
|
|
|
|
const reloadHook = inject(ReloadViewDataHookInj) |
|
|
|
const reloadHook = inject(ReloadViewDataHookInj) |
|
|
|
|
|
|
|
|
|
|
|
const { nestedFilters } = useSmartsheetStoreOrThrow() |
|
|
|
const { nestedFilters } = useSmartsheetStoreOrThrow() |
|
|
@ -44,7 +46,7 @@ export function useViewFilters( |
|
|
|
|
|
|
|
|
|
|
|
const { isUIAllowed } = useRoles() |
|
|
|
const { isUIAllowed } = useRoles() |
|
|
|
|
|
|
|
|
|
|
|
const { metas } = useMetas() |
|
|
|
const { metas, getMeta } = useMetas() |
|
|
|
|
|
|
|
|
|
|
|
const { addUndo, clone, defineViewScope } = useUndoRedo() |
|
|
|
const { addUndo, clone, defineViewScope } = useUndoRedo() |
|
|
|
|
|
|
|
|
|
|
@ -101,7 +103,12 @@ export function useViewFilters( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return meta.value?.columns?.reduce((obj: any, col: any) => { |
|
|
|
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 |
|
|
|
return obj |
|
|
|
}, {}) |
|
|
|
}, {}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -425,6 +432,37 @@ 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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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 { |
|
|
|
return { |
|
|
|
filters, |
|
|
|
filters, |
|
|
|
nonDeletedFilters, |
|
|
|
nonDeletedFilters, |
|
|
@ -437,5 +475,7 @@ export function useViewFilters( |
|
|
|
saveOrUpdateDebounced, |
|
|
|
saveOrUpdateDebounced, |
|
|
|
isComparisonOpAllowed, |
|
|
|
isComparisonOpAllowed, |
|
|
|
isComparisonSubOpAllowed, |
|
|
|
isComparisonSubOpAllowed, |
|
|
|
|
|
|
|
loadBtLookupTypes, |
|
|
|
|
|
|
|
btLookupTypesMap, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|