Skip to content

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

fix(nc-gui): show invalid field search query tooltip

Ramesh Maneca51429f86b2
diff --git a/packages/nc-gui/components/n/RecordPicker/index.vue b/packages/nc-gui/components/n/RecordPicker/index.vue
index 70cde03c5a..8154146f28 100644
--- a/packages/nc-gui/components/n/RecordPicker/index.vue
+++ b/packages/nc-gui/components/n/RecordPicker/index.vue
@@ -208,8 +208,8 @@ whenever(isOpen, () => {
<GeneralIcon icon="search" class="nc-search-icon mr-2 h-4 w-4 text-gray-500" />
</template>
<template v-if="!isValidSearchQuery" #suffix>
- <NcTooltip title="Invalid search query for visible fields">
- <GeneralIcon icon="ncInfo" class="h-4 w-4 text-nc-content-red-medium" />
+ <NcTooltip :title="$t('msg.error.invalidSearchQueryForVisibleFields')" class="flex">
+ <GeneralIcon icon="ncInfo" class="flex-noneh-4 w-4 text-nc-content-red-medium" />
</NcTooltip>
</template>
</a-input>
diff --git a/packages/nc-gui/components/smartsheet/toolbar/SearchData.vue b/packages/nc-gui/components/smartsheet/toolbar/SearchData.vue
index 819f250ddc..2a4c342d5a 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/SearchData.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/SearchData.vue
@@ -34,6 +34,10 @@ const isSearchButtonVisible = computed(() => {
return !search.value.query && !showSearchBox.value
})
+const isValidSearchQuery = computed(() => {
+ return search.value.query?.trim() && search.value.isValidFieldQuery
+})
+
const isSearchResultVisible = computed(() => {
return (
!isDropdownOpen.value &&
@@ -194,7 +198,7 @@ watch(
'border-primary shadow-selected': isMobileMode && search.query.length !== 0,
}"
>
- <div class="flex flex-row h-8">
+ <div class="flex flex-row h-8 relative">
<NcDropdown
v-model:visible="isDropdownOpen"
:trigger="['click']"
@@ -239,6 +243,9 @@ watch(
name="globalSearchQuery"
size="small"
class="!text-bodyDefaultSm !w-40 h-full nc-view-search-data !pl-0"
+ :class="{
+ '!pr-7': !isValidSearchQuery,
+ }"
:placeholder="`${$t('general.searchIn')} ${displayColumnLabel ?? ''}`"
:bordered="false"
autocomplete="off"
@@ -247,6 +254,14 @@ watch(
>
</a-input>
</form>
+ <NcTooltip
+ v-if="!isValidSearchQuery"
+ :title="$t('msg.error.invalidSearchQuery')"
+ class="absolute right-1 top-[50%] transform -translate-y-[50%] flex items-center pr-1"
+ placement="topRight"
+ >
+ <GeneralIcon icon="ncInfo" class="flex-none h-3.5 w-3.5 text-nc-content-red-medium" />
+ </NcTooltip>
</div>
<div v-if="isSearchResultVisible" class="border-t-1 border-nc-border-gray-medium py-1 px-3 flex gap-3">
<div class="text-nc-content-gray text-bodySmBold">
diff --git a/packages/nc-gui/composables/useFieldQuery.ts b/packages/nc-gui/composables/useFieldQuery.ts
index 1e7938e721..1dcad63281 100644
--- a/packages/nc-gui/composables/useFieldQuery.ts
+++ b/packages/nc-gui/composables/useFieldQuery.ts
@@ -1,5 +1,11 @@
import { ColumnHelper, type ColumnType, FormulaDataTypes, type TableType, UITypes, isNumericCol, isVirtualCol } from 'nocodb-sdk'
+export interface FieldQueryType {
+ field: string
+ query: string
+ isValidFieldQuery?: boolean
+}
+
export function useFieldQuery() {
const baseStore = useBase()
@@ -13,13 +19,16 @@ export function useFieldQuery() {
const emptyFieldQueryObj = {
field: '',
query: '',
+ isValidFieldQuery: true,
}
// mapping view id (key) to corresponding emptyFieldQueryObj (value)
- const searchMap = useState<Record<string, { field: string; query: string }>>('field-query-search-map', () => ({}))
+ const searchMap = useState<Record<string, FieldQueryType>>('field-query-search-map', () => ({}))
// the fieldQueryObj under the current view
- const search = useState<{ field: string; query: string }>('field-query-search', () => ({ ...emptyFieldQueryObj }))
+ const search = useState<FieldQueryType>('field-query-search', () => ({
+ ...emptyFieldQueryObj,
+ }))
// retrieve the fieldQueryObj of the given view id
// if it is not found in `searchMap`, init with emptyFieldQueryObj
@@ -30,7 +39,7 @@ export function useFieldQuery() {
searchMap.value[id] = { ...emptyFieldQueryObj }
}
- search.value = searchMap.value[id]
+ search.value = searchMap.value[id]!
}
/**
diff --git a/packages/nc-gui/composables/useKanbanViewStore.ts b/packages/nc-gui/composables/useKanbanViewStore.ts
index 9c95944eb5..9fa84645c6 100644
--- a/packages/nc-gui/composables/useKanbanViewStore.ts
+++ b/packages/nc-gui/composables/useKanbanViewStore.ts
@@ -21,7 +21,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
const { api } = useApi()
- const { base, sqlUis } = storeToRefs(useBase())
+ const { base } = storeToRefs(useBase())
const { $e, $api } = useNuxtApp()
@@ -35,7 +35,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
const password = ref<string | null>(null)
- const { search } = useFieldQuery()
+ const { search, getValidSearchQueryForColumn } = useFieldQuery()
const { addUndo, clone, defineViewScope } = useUndoRedo()
@@ -44,24 +44,30 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
// save history of stack changes for undo/redo
const moveHistory = ref<{ op: 'added' | 'removed'; pk: string; stack: string; index: number }[]>([])
- const sqlUi = ref(
- (meta.value as TableType)?.source_id ? sqlUis.value[(meta.value as TableType).source_id!] : Object.values(sqlUis.value)[0],
- )
-
const xWhere = computed(() => {
let where
const col =
(meta.value as TableType)?.columns?.find(({ id }) => id === search.value.field) ||
(meta.value as TableType)?.columns?.find((v) => v.pv)
- if (!col) return
- if (!search.value.query.trim()) return
- if (sqlUi.value && ['text', 'string'].includes(sqlUi.value.getAbstractType(col)) && col.dt !== 'bigint') {
- where = `(${col.title},like,%${search.value.query.trim()}%)`
- } else {
- where = `(${col.title},eq,${search.value.query.trim()})`
+ const searchQuery = search.value.query.trim()
+
+ if (!col || !searchQuery) {
+ search.value.isValidFieldQuery = true
+
+ return where
}
- return where
+
+ const colWhereQuery = getValidSearchQueryForColumn(col, searchQuery, meta.value as TableType, true)
+
+ if (!colWhereQuery) {
+ search.value.isValidFieldQuery = false
+ return where
+ }
+
+ search.value.isValidFieldQuery = true
+
+ return colWhereQuery
})
provide(SharedViewPasswordInj, password)
diff --git a/packages/nc-gui/composables/useSmartsheetStore.ts b/packages/nc-gui/composables/useSmartsheetStore.ts
index 2ee374328e..a6eb2af59e 100644
--- a/packages/nc-gui/composables/useSmartsheetStore.ts
+++ b/packages/nc-gui/composables/useSmartsheetStore.ts
@@ -107,15 +107,23 @@ const [useProvideSmartsheetStore, useSmartsheetStore] = useInjectionState(
const col =
(meta.value as TableType)?.columns?.find(({ id }) => id === search.value.field) ||
(meta.value as TableType)?.columns?.find((v) => v.pv)
- if (!col) return where
-
- if (!search.value.query.trim()) return where
const searchQuery = search.value.query.trim()
+ if (!col || !searchQuery) {
+ search.value.isValidFieldQuery = true
+
+ return where
+ }
+
const colWhereQuery = getValidSearchQueryForColumn(col, searchQuery, meta.value as TableType, true)
- if (!colWhereQuery) return where
+ if (!colWhereQuery) {
+ search.value.isValidFieldQuery = false
+ return where
+ }
+
+ search.value.isValidFieldQuery = true
return `${where ? `${where}~and` : ''}${colWhereQuery}`
})
diff --git a/packages/nc-gui/lang/en.json b/packages/nc-gui/lang/en.json
index 28b1737393..588af8ce9a 100644
--- a/packages/nc-gui/lang/en.json
+++ b/packages/nc-gui/lang/en.json
@@ -2376,7 +2376,9 @@
"anErrorOccuredWhileAirtableBaseImport": "An error occurred while importing base from airtable",
"paymentFailed": "Payment Failed",
"paymentFailedSubtitle": "Something went wrong while processing your payment. Please try again or contact support.",
- "failedToCreateLookupFields": "Failed to create lookup fields"
+ "failedToCreateLookupFields": "Failed to create lookup fields",
+ "invalidSearchQuery": "Invalid search query",
+ "invalidSearchQueryForVisibleFields": "Invalid search query for visible fields"
},
"toast": {
"exportMetadata": "Base metadata exported successfully",