Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix(nc-gui): improve field search of create new dropdown

Ramesh Mane3d3a9da6fd48
diff --git a/packages/nc-gui/components/nc/List/index.vue b/packages/nc-gui/components/nc/List/index.vue
index 7a2ee12727..9932250eea 100644
--- a/packages/nc-gui/components/nc/List/index.vue
+++ b/packages/nc-gui/components/nc/List/index.vue
@@ -425,10 +425,27 @@ defineExpose({
@click="handleSelectOption(option, idx, $event)"
>
<template #title>{{ option.ncItemTooltip }} </template>
- <slot name="listItem" :option="option" :is-selected="compareVModel(option[optionValueKey])" :index="idx">
- <slot name="listItemExtraLeft" :option="option" :is-selected="compareVModel(option[optionValueKey])"> </slot>
+ <slot
+ name="listItem"
+ :option="option"
+ :is-selected="compareVModel(option[optionValueKey])"
+ :index="idx"
+ :search-basis-info="searchBasisInfoMap[option[optionValueKey]]"
+ >
+ <slot
+ name="listItemExtraLeft"
+ :option="option"
+ :is-selected="compareVModel(option[optionValueKey])"
+ :search-basis-info="searchBasisInfoMap[option[optionValueKey]]"
+ >
+ </slot>
- <slot name="listItemContent" :option="option" :is-selected="compareVModel(option[optionValueKey])">
+ <slot
+ name="listItemContent"
+ :option="option"
+ :is-selected="compareVModel(option[optionValueKey])"
+ :search-basis-info="searchBasisInfoMap[option[optionValueKey]]"
+ >
<NcTooltip
class="truncate"
:class="{
@@ -448,7 +465,13 @@ defineExpose({
</div>
</slot>
- <slot name="listItemExtraRight" :option="option" :is-selected="compareVModel(option[optionValueKey])"> </slot>
+ <slot
+ name="listItemExtraRight"
+ :option="option"
+ :is-selected="compareVModel(option[optionValueKey])"
+ :search-basis-info="searchBasisInfoMap[option[optionValueKey]]"
+ >
+ </slot>
<slot name="listItemSelectedIcon" :option="option" :is-selected="compareVModel(option[optionValueKey])">
<GeneralIcon
diff --git a/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue b/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue
index c6ca205ecf..4d398071aa 100644
--- a/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue
+++ b/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue
@@ -547,15 +547,20 @@ const submitBtnLabel = computed(() => {
}
})
+const searchBasisInfoMap = ref<Record<string, string>>({})
+
const filterOption = (input: string, option: { value: UITypes }) => {
- return searchCompare(
- [
- option.value,
- ...(UITypesName[option.value] ? [UITypesName[option.value]] : []),
- ...(UITypesSearchTerms[option.value] || []),
- ],
- input,
- )
+ delete searchBasisInfoMap.value[option.value]
+
+ const defaultFilter = searchCompare([option.value, ...(UITypesName[option.value] ? [UITypesName[option.value]] : [])], input)
+
+ if (defaultFilter) return true
+
+ return searchCompare([...(UITypesSearchTerms[option.value as string] || [])], input, (matchKeyword) => {
+ if (!matchKeyword) return
+
+ searchBasisInfoMap.value[option.value] = `Matched by keyword: ${matchKeyword}`
+ })
}
const triggerDescriptionEnable = () => {
@@ -1146,9 +1151,20 @@ const lookupRollupFilterEnabled = computed(() => {
"
class="nc-field-type-icon w-4 h-4 !opacity-90 text-current"
/>
- <div class="flex-1">
+ <div
+ :class="{
+ 'flex-1': !searchBasisInfoMap[opt.name],
+ }"
+ >
{{ UITypesName[opt.name] }}
</div>
+
+ <div v-if="searchBasisInfoMap[opt.name]" class="flex-1 flex">
+ <NcTooltip :title="searchBasisInfoMap[opt.name]" class="flex cursor-help">
+ <GeneralIcon icon="info" class="flex-none h-3.5 w-3.5 text-nc-content-gray-muted" />
+ </NcTooltip>
+ </div>
+
<span v-if="opt.deprecated" class="!text-xs !text-gray-300">({{ $t('general.deprecated') }})</span>
<span
v-if="opt.isNew || (isAiButtonSelectOption(opt.name) && !isColumnTypeOpen)"
diff --git a/packages/nc-gui/components/smartsheet/column/UITypesOptionsWithSearch.vue b/packages/nc-gui/components/smartsheet/column/UITypesOptionsWithSearch.vue
index a5009f1c4f..eda4990c76 100644
--- a/packages/nc-gui/components/smartsheet/column/UITypesOptionsWithSearch.vue
+++ b/packages/nc-gui/components/smartsheet/column/UITypesOptionsWithSearch.vue
@@ -14,12 +14,23 @@ const searchQuery = ref('')
const { isMetaReadOnly } = useRoles()
-const filteredOptions = computed(
- () =>
- options.value?.filter((c) =>
- searchCompare([c.name, UITypesName[c.name], ...(UITypesSearchTerms[c.name] || [])], searchQuery.value),
- ) ?? [],
-)
+const searchBasisInfoMap = ref<Record<string, string>>({})
+
+const filteredOptions = computed(() => {
+ searchBasisInfoMap.value = {}
+
+ return (options.value || []).filter((c) => {
+ const defaultFilter = searchCompare([c.name, UITypesName[c.name]], searchQuery.value)
+
+ if (defaultFilter) return true
+
+ return searchCompare([...(UITypesSearchTerms[c.name] || [])], searchQuery.value, (matchKeyword) => {
+ if (!matchKeyword) return
+
+ searchBasisInfoMap.value[c.name] = 'Matched by keyword: ' + matchKeyword
+ })
+ })
+})
const inputRef = ref()
@@ -128,7 +139,20 @@ const { isSystem } = useColumnCreateStoreOrThrow()
class="w-4 h-4"
:class="isDisabledUIType(option.name) ? '!text-gray-400' : 'text-gray-700'"
/>
- <div class="flex-1 text-sm">{{ UITypesName[option.name] }}</div>
+ <div
+ class="text-sm"
+ :class="{
+ 'flex-1': !searchBasisInfoMap[option.name],
+ }"
+ >
+ {{ UITypesName[option.name] }}
+ </div>
+ <div v-if="searchBasisInfoMap[option.name]" class="flex-1 flex">
+ <NcTooltip :title="searchBasisInfoMap[option.name]" class="flex cursor-help">
+ <GeneralIcon icon="info" class="flex-none h-3.5 w-3.5 text-nc-content-gray-muted" />
+ </NcTooltip>
+ </div>
+
<span v-if="option.deprecated" class="!text-xs !text-gray-300">({{ $t('general.deprecated') }})</span>
<span v-if="option.isNew" class="text-sm text-nc-content-purple-dark bg-purple-50 px-2 rounded-md">{{
$t('general.new')
diff --git a/packages/nc-gui/utils/commonUtils.ts b/packages/nc-gui/utils/commonUtils.ts
index f952f7d44c..318e1b4469 100644
--- a/packages/nc-gui/utils/commonUtils.ts
+++ b/packages/nc-gui/utils/commonUtils.ts
@@ -109,15 +109,25 @@ export const isUnicodeEmoji = (emoji: string) => {
* searchCompare("test", undefined); // true
* ```
*/
-export const searchCompare = (source?: NestedArray<string | number | undefined>, query?: string): boolean => {
+export const searchCompare = (
+ source?: NestedArray<string | number | undefined>,
+ query?: string,
+ onMatch?: (source: string | number | undefined) => void,
+): boolean => {
if (ncIsArray(source)) {
- return source.some((item) => searchCompare(item, query))
+ return source.some((item) => searchCompare(item, query, onMatch))
}
- return (source || '')
+ const isMatch = (source || '')
.toString()
.toLowerCase()
.includes((query || '').toLowerCase())
+
+ if (isMatch && onMatch) {
+ onMatch(source)
+ }
+
+ return isMatch
}
/**