π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat(nc-gui): add search basis functionality in ncList component
Ramesh Maned8140746ce29
diff --git a/packages/nc-gui/components/nc/List/index.vue b/packages/nc-gui/components/nc/List/index.vueindex 6271c502de..ee951229b6 100644--- a/packages/nc-gui/components/nc/List/index.vue+++ b/packages/nc-gui/components/nc/List/index.vue@@ -29,6 +29,7 @@ const props = withDefaults(defineProps<NcListProps>(), {hideTopDivider: false,itemFullWidth: false,stopPropagationOnItemClick: false,+ searchBasisOptions: () => [] as NcListSearchBasisOptionType[],})const emits = defineEmits<Emits>()@@ -63,6 +64,8 @@ const listRef = ref<HTMLDivElement>()const searchQuery = ref('')+const searchBasisInfo = ref<string | null>(null)+const inputRef = ref()const activeOptionIndex = ref(-1)@@ -86,13 +89,35 @@ const keyDown = ref(false)const list = computed(() => {const query = searchQuery.value.toLowerCase()- return props.list.filter((item, i) => {+ searchBasisInfo.value = null+ // If no query, return all items+ if (!query) return props.list++ const defaultFilter = (item: NcListItemType, i: number, _array: NcListItemType[]) => {if (props?.filterOption) {return props.filterOption(query, item, i)- } else {- return searchCompare(item[optionLabelKey], query)}- })++ return searchCompare(item[optionLabelKey], query)+ }++ let result = props.list.filter(defaultFilter)++ // If search result is found based on default search basis or search basis options are not provided then return the result+ if (result.length || !props.searchBasisOptions?.length) return result++ for (const basisOption of props.searchBasisOptions) {+ result = props.list.filter((item, i) => {+ return basisOption.filterCallback(query, item, i)+ })++ if (result.length) {+ searchBasisInfo.value = basisOption.searchBasisInfo ?? ''+ return result+ }+ }++ return result})const {@@ -335,8 +360,13 @@ defineExpose({@keydown.enter.stop="handleKeydownEnter"@change="handleResetHoverEffect(false, 0)">- <template #prefix> <GeneralIcon icon="search" class="nc-search-icon h-3.5 w-3.5 mr-1" /> </template- ></a-input>+ <template #prefix> <GeneralIcon icon="search" class="nc-search-icon h-3.5 w-3.5 mr-1" /> </template>+ <template #suffix>+ <NcTooltip v-if="searchBasisInfo" :title="searchBasisInfo" class="flex cursor-help ml-0.5" placement="topRight">+ <GeneralIcon icon="info" class="flex-none h-3.5 w-3.5 text-primary" />+ </NcTooltip>+ </template>+ </a-input><slot name="headerExtraRight"> </slot></div><NcDivider v-if="!hideTopDivider" class="!my-1" />diff --git a/packages/nc-gui/components/smartsheet/toolbar/FieldListWithSearch.vue b/packages/nc-gui/components/smartsheet/toolbar/FieldListWithSearch.vueindex ea50a24843..d7ef2bcd08 100644--- a/packages/nc-gui/components/smartsheet/toolbar/FieldListWithSearch.vue+++ b/packages/nc-gui/components/smartsheet/toolbar/FieldListWithSearch.vue@@ -1,5 +1,5 @@<script lang="ts" setup>-import { type ColumnType, isSystemColumn } from 'nocodb-sdk'+import { type ButtonType, type ColumnType, isSystemColumn } from 'nocodb-sdk'const props = withDefaults(defineProps<{@@ -25,6 +25,8 @@ const { fieldsMap, isLocalMode } = useViewColumnsOrThrow()const { $e } = useNuxtApp()+const { t } = useI18n()+const options = computed(() =>(props.options || []).filter((c) => (isLocalMode.value && c?.id && fieldsMap.value[c.id] ? fieldsMap.value[c.id]?.initialShow : true))@@ -88,6 +90,31 @@ const handleSelect = (c: ColumnType) => {}const isLocked = inject(IsLockedInj)++const fieldSearchBasisOptions = computed<NcListSearchBasisOptionType[]>(() => [+ {+ searchBasisInfo: t('msg.info.searchResultBasedOnButtonLabel'),+ filterCallback: (query, option) => {+ if (!option) return false++ const column = option as ColumnType++ return isButton(column) && searchCompare([(column.colOptions as ButtonType)?.label], query)+ },+ },+ {+ searchBasisInfo: t('msg.info.searchResultBasedOnFieldDescription'),+ filterCallback: (query, option) => {+ if (!option) return false++ const column = option as ColumnType++ if (!column.description) return false++ return searchCompare([column.description], query)+ },+ },+])</script><template>@@ -109,6 +136,7 @@ const isLocked = inject(IsLockedInj):list="options":value="selectedOptionId":item-height="32"+ :search-basis-options="fieldSearchBasisOptions"@change="handleSelect"><template #listItemExtraLeft="{ option }">diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.tsindex b6fe3c3563..9979662862 100644--- a/packages/nc-gui/lib/types.ts+++ b/packages/nc-gui/lib/types.ts@@ -733,6 +733,18 @@ interface NcListItemType {[key: string]: any}+interface NcListSearchBasisOptionType {+ /**+ * The search basis info to use for the list.+ * This will tell user that the search is based on this property.+ */+ searchBasisInfo: string+ /**+ * The filter callback to use for the list.+ */+ filterCallback: (input: string, option: NcListItemType, index: Number) => boolean+}+/*** Props interface for the List component*/@@ -816,6 +828,42 @@ interface NcListProps {* Whether to stop propagation on item click*/stopPropagationOnItemClick?: boolean++ /**+ * @Info - This will be used only if search result not found based on default search method.+ *+ * - With the help of search basis we can search list items based on different fields properties which are not visible for user.+ * - Also we will show this info to user in tooltip.+ *+ * @example+ * ```ts+ * const searchBasisOptions: NcListSearchBasisOptionType[] = [+ * {+ * searchBasisInfo: t('msg.info.searchResultBasedOnButtonLabel'),+ * filterCallback: (query, option) => {+ * if (!option) return false+ *+ * const column = option as ColumnType+ *+ * return isButton(column) && searchCompare([(column.colOptions as ButtonType)?.label], query)+ * },+ * },+ * {+ * searchBasisInfo: t('msg.info.searchResultBasedOnFieldDescription'),+ * filterCallback: (query, option) => {+ * if (!option) return false+ *+ * const column = option as ColumnType+ *+ * if (!column.description) return false+ *+ * return searchCompare([column.description], query)+ * },+ * }+ * ]+ * ```+ */+ searchBasisOptions?: NcListSearchBasisOptionType[]}// NcList type ends here@@ -890,6 +938,7 @@ export type {PermissionSelectorUser,NcListProps,NcListItemType,+ NcListSearchBasisOptionType,MultiSelectRawValueType,RawValueType,NcDropdownPlacement,