Browse Source

enhancement(nc-gui): conditional numeric functions in aggFunctionsList

pull/6853/head
աɨռɢӄաօռɢ 1 year ago
parent
commit
1a5ba0fd35
  1. 63
      packages/nc-gui/components/smartsheet/column/RollupOptions.vue

63
packages/nc-gui/components/smartsheet/column/RollupOptions.vue

@ -1,8 +1,22 @@
<script setup lang="ts">
import { onMounted } from '@vue/runtime-core'
import type { ColumnType, LinkToAnotherRecordType, TableType, UITypes } from 'nocodb-sdk'
import { isLinksOrLTAR, isSystemColumn, isVirtualCol } from 'nocodb-sdk'
import { MetaInj, inject, ref, storeToRefs, useBase, useColumnCreateStoreOrThrow, useMetas, useVModel } from '#imports'
import { isLinksOrLTAR, isNumericCol, isSystemColumn, isVirtualCol } from 'nocodb-sdk'
import {
MetaInj,
computed,
h,
inject,
ref,
resolveComponent,
storeToRefs,
useBase,
useColumnCreateStoreOrThrow,
useI18n,
useMetas,
useVModel,
watch,
} from '#imports'
const props = defineProps<{
value: any
@ -17,6 +31,7 @@ const meta = inject(MetaInj, ref())
const { setAdditionalValidations, validateInfos, onDataTypeChange, isEdit } = useColumnCreateStoreOrThrow()
const baseStore = useBase()
const { tables } = storeToRefs(baseStore)
const { metas } = useMetas()
@ -29,17 +44,6 @@ setAdditionalValidations({
rollup_function: [{ required: true, message: t('general.required') }],
})
const aggrFunctionsList = [
{ text: t('datatype.Count'), value: 'count' },
{ text: t('general.min'), value: 'min' },
{ text: t('general.max'), value: 'max' },
{ text: t('general.avg'), value: 'avg' },
{ text: t('general.sum'), value: 'sum' },
{ text: t('general.countDistinct'), value: 'countDistinct' },
{ text: t('general.sumDistinct'), value: 'sumDistinct' },
{ text: t('general.avgDistinct'), value: 'avgDistinct' },
]
if (!vModel.value.fk_relation_column_id) vModel.value.fk_relation_column_id = null
if (!vModel.value.fk_rollup_column_id) vModel.value.fk_rollup_column_id = null
if (!vModel.value.rollup_function) vModel.value.rollup_function = null
@ -94,6 +98,37 @@ const cellIcon = (column: ColumnType) =>
h(isVirtualCol(column) ? resolveComponent('SmartsheetHeaderVirtualCellIcon') : resolveComponent('SmartsheetHeaderCellIcon'), {
columnMeta: column,
})
const aggFunctionsList: Record<string, string>[] = ref([])
watch(
() => vModel.value.fk_rollup_column_id,
() => {
const childFieldColumn = columns.value?.find((column) => column.id === vModel.value.fk_rollup_column_id)
const showNumericFunctions = isNumericCol(childFieldColumn)
aggFunctionsList.value = [
// functions for non-numeric types,
// e.g. count / min / max date field
{ text: t('datatype.Count'), value: 'count' },
{ text: t('general.min'), value: 'min' },
{ text: t('general.max'), value: 'max' },
...(showNumericFunctions
? [
// functions for numeric type only
{ text: t('general.avg'), value: 'avg' },
{ text: t('general.sum'), value: 'sum' },
{ text: t('general.countDistinct'), value: 'countDistinct' },
{ text: t('general.sumDistinct'), value: 'sumDistinct' },
{ text: t('general.avgDistinct'), value: 'avgDistinct' },
]
: []),
]
if (!showNumericFunctions) {
// reset rollup function with a non-numeric type
vModel.value.rollup_function = aggFunctionsList.value[0].value
}
},
)
</script>
<template>
@ -141,7 +176,7 @@ const cellIcon = (column: ColumnType) =>
dropdown-class-name="nc-dropdown-rollup-function"
@change="onDataTypeChange"
>
<a-select-option v-for="(func, index) of aggrFunctionsList" :key="index" :value="func.value">
<a-select-option v-for="(func, index) of aggFunctionsList" :key="index" :value="func.value">
{{ func.text }}
</a-select-option>
</a-select>

Loading…
Cancel
Save