π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
refactor: unify selector components with auto-select and disabled props
DarkPhoenix2704441b43f162c3
diff --git a/packages/nc-gui/components/nc/List/AggregationSelector.vue b/packages/nc-gui/components/nc/List/AggregationSelector.vueindex ad64f89fd4..f335476b90 100644--- a/packages/nc-gui/components/nc/List/AggregationSelector.vue+++ b/packages/nc-gui/components/nc/List/AggregationSelector.vue@@ -6,17 +6,19 @@ interface Props {tableId?: stringcolumnId?: stringvalue?: string- showAggregationSelector?: booleanforceLayout?: 'vertical' | 'horizontal'filterAggregation?: (aggregation: string) => booleanforceLoadColumnMeta?: booleandisableLabel?: boolean+ autoSelect?: boolean+ disabled?: boolean}const props = withDefaults(defineProps<Props>(), {- showAggregationSelector: true,forceLoadColumnMeta: false,disableLabel: false,+ autoSelect: false,+ disabled: false,})const emit = defineEmits<{@@ -39,31 +41,37 @@ const handleValueUpdate = (value: any) => {const column = ref<ColumnType | null>(null)const isLoading = ref(false)+const aggregationList = ref<Array<{ label: string; value: string; ncItemDisabled: boolean; ncItemTooltip: string }>>([])-const aggregationList = computedAsync(async () => {- if (!props.tableId || !props.columnId) return []+const loadAggregationList = async () => {+ if (!props.tableId || !props.columnId) {+ isLoading.value = false+ aggregationList.value = []+ return+ }try {isLoading.value = true- const tableMeta = await getMeta(props.tableId)+ const tableMeta = await getMeta(props.tableId, undefined, undefined, undefined, true)if (!tableMeta) {- console.error('Failed to fetch table metadata')- return []+ aggregationList.value = []+ return}const columnMeta = tableMeta.columns?.find((col) => col.id === props.columnId)if (!columnMeta) {- return []+ aggregationList.value = []+ return}column.value = columnMetalet availableAggregations: string[]- if (columnMeta.uidt === UITypes.Formula && columnMeta.colOptions?.parsed_tree) {- availableAggregations = getAvailableAggregations(columnMeta.uidt, columnMeta.colOptions.parsed_tree)+ if (columnMeta.uidt === UITypes.Formula && columnMeta.colOptions && 'parsed_tree' in columnMeta.colOptions) {+ availableAggregations = getAvailableAggregations(columnMeta.uidt, (columnMeta.colOptions as any).parsed_tree)} else {- availableAggregations = getAvailableAggregations(columnMeta.uidt)+ availableAggregations = getAvailableAggregations(columnMeta.uidt!)}// Filter out None aggregation@@ -74,7 +82,7 @@ const aggregationList = computedAsync(async () => {availableAggregations = availableAggregations.filter(props.filterAggregation)}- return availableAggregations.map((agg) => {+ aggregationList.value = availableAggregations.map((agg) => {return {label: t(`aggregation_type.${agg}`),value: agg,@@ -83,27 +91,45 @@ const aggregationList = computedAsync(async () => {}})} catch (error) {- console.error('Error fetching column metadata:', error)- return []+ aggregationList.value = []} finally {isLoading.value = false}-}, [])+}+++watch([() => props.tableId, () => props.columnId], () => {+ loadAggregationList()+})+const selectedAggregation = computed(() => {if (!aggregationList.value || aggregationList.value.length === 0) return undefined- return aggregationList.value.find((agg) => agg.value === modelValue.value) || aggregationList.value[0]+ return aggregationList.value.find((agg) => agg.value === modelValue.value) || undefined})watch(aggregationList, (newAggregationList) => {- if (!modelValue.value && newAggregationList && newAggregationList.length > 0) {- const newAggregationValue = newAggregationList[0]?.value+ if (newAggregationList && newAggregationList.length > 0) {+ // Check if current value exists in the new aggregation list+ if (modelValue.value && !newAggregationList.find((agg) => agg.value === modelValue.value)) {+ // Current value is not in the list, emit null to clear it+ modelValue.value = undefined+ emit('update:value', undefined)+ return+ }++ // Auto-select logic (only if autoSelect is enabled and no current value)+ if (!modelValue.value && props.autoSelect) {+ const newAggregationValue = newAggregationList[0]?.value- modelValue.value = newAggregationValue+ modelValue.value = newAggregationValue+ emit('update:value', newAggregationValue)+ }}}, { immediate: true })+defineExpose({modelValue,selectedAggregation,@@ -127,17 +153,25 @@ defineExpose({</template><NcListDropdownv-model:is-open="isOpenAggregationSelectDropdown"- :disabled="!showAggregationSelector || isLoading"+ :disabled="isLoading || disabled":default-slot-wrapper-class="- !showAggregationSelector || isLoading+ isLoading || disabled? 'text-nc-content-gray-muted cursor-not-allowed bg-nc-bg-gray-light children:opacity-60': 'text-nc-content-gray'":has-error="!!selectedAggregation?.ncItemDisabled"><div class="flex-1 flex items-center gap-2 min-w-0">- <span :key="selectedAggregation?.value" class="text-sm flex-1 truncate">{{ selectedAggregation?.label || t('general.aggregation') }}</span>-+ <NcTooltip hide-on-click class="flex-1 truncate" show-on-truncate-only>+ <span v-if="selectedAggregation" :key="selectedAggregation?.value" class="text-sm flex-1 truncate" :class="{ 'text-nc-content-gray-muted': !selectedAggregation }">+ {{ selectedAggregation?.label }}+ </span>+ <span v-else class="text-sm flex-1 truncate text-nc-content-gray-muted">-- Select aggregation --</span>++ <template #title>+ {{ selectedAggregation?.label || 'Select aggregation' }}+ </template>+ </NcTooltip><GeneralIconicon="ncChevronDown"class="flex-none h-4 w-4 transition-transform opacity-70"diff --git a/packages/nc-gui/components/nc/List/ColumnSelector.vue b/packages/nc-gui/components/nc/List/ColumnSelector.vueindex 4f41a8675e..310b3b3429 100644--- a/packages/nc-gui/components/nc/List/ColumnSelector.vue+++ b/packages/nc-gui/components/nc/List/ColumnSelector.vue@@ -5,17 +5,19 @@ interface Props {tableId?: stringcolumnId?: stringvalue?: string- showColumnSelector?: booleanforceLayout?: 'vertical' | 'horizontal'filterColumn?: (column: ColumnType) => booleanforceLoadTableFields?: booleandisableLabel?: boolean+ autoSelect?: boolean+ disabled?: boolean}const props = withDefaults(defineProps<Props>(), {- showColumnSelector: true,forceLoadTableFields: false,disableLabel: false,+ autoSelect: false,+ disabled: false,})const emit = defineEmits<{@@ -74,21 +76,35 @@ const columnList = computedAsync(async () => {const selectedColumn = computed(() => {if (!columnList.value || columnList.value.length === 0) return undefined- return columnList.value.find((column) => column.value === modelValue.value) || columnList.value[0]+ return columnList.value.find((column) => column.value === modelValue.value) || undefined})// Watch for columnList changes and set initial valuewatch(columnList, (newColumnList) => {- if (!modelValue.value && newColumnList && newColumnList.length > 0) {- const newColumnId = props.columnId || newColumnList[0]?.value+ if (newColumnList && newColumnList.length > 0) {+ // Check if current value exists in the new column list+ if (modelValue.value && !newColumnList.find((column) => column.value === modelValue.value)) {+ // Current value is not in the list, emit null to clear it+ modelValue.value = undefined+ emit('update:value', undefined)+ return+ }++ // Auto-select logic (only if autoSelect is enabled and no current value)+ if (!modelValue.value && props.autoSelect) {+ const newColumnId = props.columnId || newColumnList[0]?.value- const columnObj = newColumnList.find((column) => column.value === newColumnId)+ const columnObj = newColumnList.find((column) => column.value === newColumnId)- // Change column id only if it is default column selected initially and its not enabled- if (columnObj && columnObj.ncItemDisabled && columnObj.value === newColumnList[0]?.value) {- modelValue.value = newColumnList.find((column) => !column.ncItemDisabled)?.value || newColumnList[0]?.value- } else {- modelValue.value = newColumnId+ // Change column id only if it is default column selected initially and its not enabled+ if (columnObj && columnObj.ncItemDisabled && columnObj.value === newColumnList[0]?.value) {+ const selectedValue = newColumnList.find((column) => !column.ncItemDisabled)?.value || newColumnList[0]?.value+ modelValue.value = selectedValue+ emit('update:value', selectedValue)+ } else {+ modelValue.value = newColumnId+ emit('update:value', newColumnId)+ }}}}, { immediate: true })@@ -103,7 +119,6 @@ defineExpose({<template><a-form-item- v-if="selectedColumn"name="columnId"class="!mb-0 nc-column-selector":class="`nc-force-layout-${forceLayout}`"@@ -117,19 +132,28 @@ defineExpose({</template><NcListDropdownv-model:is-open="isOpenColumnSelectDropdown"- :disabled="!showColumnSelector"+ :disabled="disabled":default-slot-wrapper-class="- !showColumnSelector+ disabled? 'text-nc-content-gray-muted cursor-not-allowed bg-nc-bg-gray-light children:opacity-60': 'text-nc-content-gray'":has-error="!!selectedColumn?.ncItemDisabled"><div class="flex-1 flex items-center gap-2 min-w-0">- <div class="min-w-5 flex items-center justify-center">+ <div v-if="selectedColumn" class="min-w-5 flex items-center justify-center"><NIconField :field="selectedColumn" class="text-gray-500" /></div>- <span class="text-sm flex-1 truncate">{{ selectedColumn?.label || t('general.column') }}</span>+ <NcTooltip hide-on-click class="flex-1 truncate" show-on-truncate-only>+ <span v-if="selectedColumn" class="text-sm flex-1 truncate text-nc-content-gray-default">+ {{ selectedColumn?.label }}+ </span>+ <span v-else class="text-sm flex-1 truncate text-nc-content-gray-muted">-- Select field --</span>++ <template #title>+ {{ selectedColumn?.label || 'Select field' }}+ </template>+ </NcTooltip><GeneralIconicon="ncChevronDown"diff --git a/packages/nc-gui/components/nc/List/TableSelector.vue b/packages/nc-gui/components/nc/List/TableSelector.vueindex 4c28c9ecba..17527d13ea 100644--- a/packages/nc-gui/components/nc/List/TableSelector.vue+++ b/packages/nc-gui/components/nc/List/TableSelector.vue@@ -4,22 +4,24 @@ import type { TableType } from 'nocodb-sdk'interface Props {baseId?: stringtableId?: string- value?: string- showTableSelector?: boolean+ value?: string | null | undefinedforceLayout?: 'vertical' | 'horizontal'filterTable?: (table: TableType) => booleanforceLoadBaseTables?: booleandisableLabel?: boolean+ autoSelect?: boolean+ disabled?: boolean}const props = withDefaults(defineProps<Props>(), {- showTableSelector: true,forceLoadBaseTables: false,disableLabel: false,+ autoSelect: false,+ disabled: false,})const emit = defineEmits<{- 'update:value': [value: string | undefined]+ 'update:value': [value: string | null | undefined]}>()const { t } = useI18n()@@ -68,19 +70,33 @@ const tableList = computedAsync(async () => {const selectedTable = computed(() => {if (!tableList.value || tableList.value.length === 0) return undefined- return tableList.value.find((table) => table.value === modelValue.value) || tableList.value[0]+ return tableList.value.find((table) => table.value === modelValue.value) || undefined})watch(tableList, (newTableList) => {- if (!modelValue.value && newTableList && newTableList.length > 0) {- const newTableId = props.tableId || newTableList[0]?.value+ if (newTableList && newTableList.length > 0) {+ // Check if current value exists in the new table list+ if (modelValue.value && !newTableList.find((table) => table.value === modelValue.value)) {+ // Current value is not in the list, emit null to clear it+ modelValue.value = null+ emit('update:value', null)+ return+ }++ // Auto-select logic (only if autoSelect is enabled and no current value)+ if (!modelValue.value && props.autoSelect) {+ const newTableId = props.tableId || newTableList[0]?.value- const tableObj = newTableList.find((table) => table.value === newTableId)+ const tableObj = newTableList.find((table) => table.value === newTableId)- if (tableObj && tableObj.ncItemDisabled && tableObj.value === newTableList[0]?.value) {- modelValue.value = newTableList.find((table) => !table.ncItemDisabled)?.value || newTableList[0]?.value- } else {- modelValue.value = newTableId+ if (tableObj && tableObj.ncItemDisabled && tableObj.value === newTableList[0]?.value) {+ const selectedValue = newTableList.find((table) => !table.ncItemDisabled)?.value || newTableList[0]?.value+ modelValue.value = selectedValue+ emit('update:value', selectedValue)+ } else {+ modelValue.value = newTableId+ emit('update:value', newTableId)+ }}}}, { immediate: true })@@ -95,7 +111,6 @@ defineExpose({<template><a-form-item- v-if="selectedTable"name="tableId"class="!mb-0 nc-table-selector":class="`nc-force-layout-${forceLayout}`"@@ -109,19 +124,28 @@ defineExpose({</template><NcListDropdownv-model:is-open="isOpenTableSelectDropdown"- :disabled="!showTableSelector"+ :disabled="disabled":default-slot-wrapper-class="- !showTableSelector+ disabled? 'text-nc-content-gray-muted cursor-not-allowed bg-nc-bg-gray-light children:opacity-60': 'text-nc-content-gray'":has-error="!!selectedTable?.ncItemDisabled"><div class="flex-1 flex items-center gap-2 min-w-0">- <div class="min-w-5 flex items-center justify-center">- <NIconTable :table="selectedTable" class="text-gray-500" />+ <div v-if="selectedTable" class="min-w-5 flex items-center justify-center">+ <NIconTable :table="selectedTable || { title: '', table_name: '' }" class="text-gray-500" /></div>- <span :key="selectedTable?.value" class="text-sm flex-1 truncate">{{ selectedTable?.label || t('general.table') }}</span>+ <NcTooltip hide-on-click class="flex-1 truncate" show-on-truncate-only>+ <span v-if="selectedTable" :key="selectedTable?.value" class="text-sm flex-1 truncate" :class="{ 'text-nc-content-gray-muted': !selectedTable }">+ {{ selectedTable?.label }}+ </span>+ <span v-else class="text-sm flex-1 truncate text-nc-content-gray-muted">-- Select table --</span>++ <template #title>+ {{ selectedTable?.label || 'Select table' }}+ </template>+ </NcTooltip><GeneralIconicon="ncChevronDown"diff --git a/packages/nc-gui/components/nc/List/ViewSelector.vue b/packages/nc-gui/components/nc/List/ViewSelector.vueindex ea4e02f31f..133645057a 100644--- a/packages/nc-gui/components/nc/List/ViewSelector.vue+++ b/packages/nc-gui/components/nc/List/ViewSelector.vue@@ -5,21 +5,23 @@ interface Props {tableId?: stringviewId?: stringvalue?: string- showViewSelector?: booleanforceLayout?: 'vertical' | 'horizontal'filterView?: (view: ViewType) => booleanignoreLoading?: booleanforceFetchViews?: booleanlabelDefaultViewAsDefault?: booleandisableLabel?: boolean+ autoSelect?: boolean+ disabled?: boolean}const props = withDefaults(defineProps<Props>(), {- showViewSelector: true,ignoreLoading: false,forceFetchViews: false,labelDefaultViewAsDefault: false,disableLabel: false,+ autoSelect: false,+ disabled: false,})const emit = defineEmits<{@@ -84,16 +86,30 @@ const selectedView = computed(() => {})watch(viewList, (newViewList) => {- if (!modelValue.value && newViewList && newViewList.length > 0) {- const newViewId = props.viewId || newViewList[0]?.value+ if (newViewList && newViewList.length > 0) {+ // Check if current value exists in the new view list+ if (modelValue.value && !newViewList.find((view) => view.value === modelValue.value)) {+ // Current value is not in the list, emit null to clear it+ modelValue.value = undefined+ emit('update:value', undefined)+ return+ }++ // Auto-select logic (only if autoSelect is enabled and no current value)+ if (!modelValue.value && props.autoSelect) {+ const newViewId = props.viewId || newViewList[0]?.value- const viewObj = newViewList.find((view) => view.value === newViewId)+ const viewObj = newViewList.find((view) => view.value === newViewId)- // Change view id only if it is default view selected initially and its not enabled- if (viewObj && viewObj.ncItemDisabled && viewObj.value === newViewList[0]?.value) {- modelValue.value = newViewList.find((view) => !view.ncItemDisabled)?.value || newViewList[0]?.value- } else {- modelValue.value = newViewId+ // Change view id only if it is default view selected initially and its not enabled+ if (viewObj && viewObj.ncItemDisabled && viewObj.value === newViewList[0]?.value) {+ const selectedValue = newViewList.find((view) => !view.ncItemDisabled)?.value || newViewList[0]?.value+ modelValue.value = selectedValue+ emit('update:value', selectedValue)+ } else {+ modelValue.value = newViewId+ emit('update:value', newViewId)+ }}}}, { immediate: true })@@ -108,7 +124,6 @@ defineExpose({<template><a-form-item- v-if="selectedView"name="viewId"class="!mb-0 nc-view-selector":class="`nc-force-layout-${forceLayout}`"@@ -122,19 +137,28 @@ defineExpose({</template><NcListDropdownv-model:is-open="isOpenViewSelectDropdown"- :disabled="!showViewSelector"+ :disabled="disabled":default-slot-wrapper-class="- !showViewSelector+ disabled? 'text-nc-content-gray-muted cursor-not-allowed bg-nc-bg-gray-light children:opacity-60': 'text-nc-content-gray'":has-error="!!selectedView?.ncItemDisabled"><div class="flex-1 flex items-center gap-2 min-w-0">- <div class="min-w-5 flex items-center justify-center">+ <div v-if="selectedView" class="min-w-5 flex items-center justify-center"><NIconView :view="selectedView" class="text-gray-500" /></div>- <span class="text-sm flex-1 truncate">{{ selectedView?.label || t('general.view') }}</span>+ <NcTooltip hide-on-click class="flex-1 truncate" show-on-truncate-only>+ <span v-if="selectedView" :key="selectedView?.value" class="text-sm flex-1 truncate" :class="{ 'text-nc-content-gray-muted': !selectedView }">+ {{ selectedView?.label }}+ </span>+ <span v-else class="text-sm flex-1 truncate text-nc-content-gray-muted">-- Select view --</span>++ <template #title>+ {{ selectedView?.label || 'Select view' }}+ </template>+ </NcTooltip><GeneralIconicon="ncChevronDown"