Browse Source

feat: show corresponding filter op/subop for lookup column(only bt)

pull/6507/head
Pranav C 1 year ago
parent
commit
92c2f42f79
  1. 10
      packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
  2. 48
      packages/nc-gui/composables/useViewFilters.ts

10
packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue

@ -14,6 +14,7 @@ import {
useNuxtApp,
useViewFilters,
watch,
onMounted
} from '#imports'
import type { Filter } from '#imports'
@ -68,6 +69,8 @@ const {
saveOrUpdateDebounced,
isComparisonOpAllowed,
isComparisonSubOpAllowed,
loadBtLookupTypes,
btLookupTypesMap,
} = useViewFilters(
activeView,
parentId?.value,
@ -86,7 +89,8 @@ const addFiltersRowDomRef = ref<HTMLElement>()
const columns = computed(() => meta.value?.columns)
const getColumn = (filter: Filter) => {
return columns.value?.find((col: ColumnType) => col.id === filter.fk_column_id)
// extract looked up column if available
return btLookupTypesMap.value[filter.fk_column_id] || columns.value?.find((col: ColumnType) => col.id === filter.fk_column_id)
}
const filterPrevComparisonOp = ref<Record<string, string>>({})
@ -289,6 +293,10 @@ const showFilterInput = (filter: Filter) => {
onMounted(() => {
loadFilters(hookId?.value)
})
onMounted(async () => {
await loadBtLookupTypes()
})
</script>
<template>

48
packages/nc-gui/composables/useViewFilters.ts

@ -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,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 {
filters,
nonDeletedFilters,
@ -437,5 +475,7 @@ export function useViewFilters(
saveOrUpdateDebounced,
isComparisonOpAllowed,
isComparisonSubOpAllowed,
loadBtLookupTypes,
btLookupTypesMap,
}
}

Loading…
Cancel
Save