Browse Source

fic(nc-gui): focus search field on add new record form opens

pull/7623/head
Ramesh Mane 9 months ago
parent
commit
25f863ed5f
  1. 29
      packages/nc-gui/components/virtual-cell/components/ListChildItems.vue
  2. 14
      packages/nc-gui/components/virtual-cell/components/ListItems.vue

29
packages/nc-gui/components/virtual-cell/components/ListChildItems.vue

@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { VNodeRef } from '@vue/runtime-core'
import { type ColumnType, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk' import { type ColumnType, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'
import type { Row } from '#imports' import type { Row } from '#imports'
import InboxIcon from '~icons/nc-icons/inbox' import InboxIcon from '~icons/nc-icons/inbox'
@ -62,6 +63,15 @@ const {
const { isNew, state, removeLTARRef, addLTARRef } = useSmartsheetRowStoreOrThrow() const { isNew, state, removeLTARRef, addLTARRef } = useSmartsheetRowStoreOrThrow()
const colTitle = computed(() => injectedColumn.value?.title || '')
const isDataExist = computed<boolean>(() => {
return childrenList.value?.pageInfo?.totalRows || (isNew.value && state.value?.[colTitle.value]?.length)
})
const filterQueryFocus: VNodeRef = (el) =>
vModel.value && (isPublic.value || readOnly.value ? isDataExist.value : true) && (el as HTMLInputElement)?.focus()
watch( watch(
[vModel, isForm], [vModel, isForm],
(nextVal) => { (nextVal) => {
@ -92,8 +102,6 @@ const attachmentCol = computedInject(FieldsInj, (_fields) => {
return (relatedTableMeta.value.columns ?? []).filter((col) => isAttachment(col))[0] return (relatedTableMeta.value.columns ?? []).filter((col) => isAttachment(col))[0]
}) })
const isFocused = ref(false)
const fields = computedInject(FieldsInj, (_fields) => { const fields = computedInject(FieldsInj, (_fields) => {
return (relatedTableMeta.value.columns ?? []) return (relatedTableMeta.value.columns ?? [])
.filter((col) => !isSystemColumn(col) && !isPrimary(col) && !isLinksOrLTAR(col) && !isAttachment(col)) .filter((col) => !isSystemColumn(col) && !isPrimary(col) && !isLinksOrLTAR(col) && !isAttachment(col))
@ -104,8 +112,6 @@ const expandedFormDlg = ref(false)
const expandedFormRow = ref({}) const expandedFormRow = ref({})
const colTitle = computed(() => injectedColumn.value?.title || '')
const onClick = (row: Row) => { const onClick = (row: Row) => {
if (readOnly.value) return if (readOnly.value) return
expandedFormRow.value = row expandedFormRow.value = row
@ -160,10 +166,6 @@ const totalItemsToShow = computed(() => {
return childrenListCount.value return childrenListCount.value
}) })
const isDataExist = computed<boolean>(() => {
return childrenList.value?.pageInfo?.totalRows || (isNew.value && state.value?.[colTitle.value]?.length)
})
const linkOrUnLink = (rowRef: Record<string, string>, id: string) => { const linkOrUnLink = (rowRef: Record<string, string>, id: string) => {
if (isSharedBase.value) return if (isSharedBase.value) return
if (readOnly.value) return if (readOnly.value) return
@ -198,20 +200,15 @@ const linkOrUnLink = (rowRef: Record<string, string>, id: string) => {
:display-value="headerDisplayValue" :display-value="headerDisplayValue"
/> />
<div v-if="!isForm" class="flex mt-2 mb-2 items-center gap-2"> <div v-if="!isForm" class="flex mt-2 mb-2 items-center gap-2">
<div <div class="flex items-center border-1 p-1 rounded-md w-full border-gray-200 focus-within:!border-primary">
class="flex items-center border-1 p-1 rounded-md w-full border-gray-200" <MdiMagnify class="w-5 h-5 ml-2 text-gray-500" />
:class="{ '!border-primary': childrenListPagination.query.length !== 0 || isFocused }"
>
<MdiMagnify class="w-5 h-5 ml-2" />
<a-input <a-input
ref="filterQueryRef" :ref="filterQueryFocus"
v-model:value="childrenListPagination.query" v-model:value="childrenListPagination.query"
:placeholder="`Search in ${relatedTableMeta?.title}`" :placeholder="`Search in ${relatedTableMeta?.title}`"
class="w-full !sm:rounded-md xs:min-h-8 !xs:rounded-xl" class="w-full !sm:rounded-md xs:min-h-8 !xs:rounded-xl"
size="small" size="small"
:bordered="false" :bordered="false"
@focus="isFocused = true"
@blur="isFocused = false"
@keydown.capture.stop @keydown.capture.stop
@change="childrenListPagination.page = 1" @change="childrenListPagination.page = 1"
> >

14
packages/nc-gui/components/virtual-cell/components/ListItems.vue

@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { VNodeRef } from '@vue/runtime-core'
import { RelationTypes, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk' import { RelationTypes, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import InboxIcon from '~icons/nc-icons/inbox' import InboxIcon from '~icons/nc-icons/inbox'
@ -27,8 +28,6 @@ const injectedColumn = inject(ColumnInj)
const { isSharedBase } = storeToRefs(useBase()) const { isSharedBase } = storeToRefs(useBase())
const filterQueryRef = ref()
const { t } = useI18n() const { t } = useI18n()
const { $e } = useNuxtApp() const { $e } = useNuxtApp()
@ -64,7 +63,7 @@ const isForm = inject(IsFormInj, ref(false))
const saveRow = inject(SaveRowInj, () => {}) const saveRow = inject(SaveRowInj, () => {})
const isFocused = ref(false) const filterQueryFocus: VNodeRef = (el) => vModel.value && (el as HTMLInputElement)?.focus()
const linkRow = async (row: Record<string, any>, id: number) => { const linkRow = async (row: Record<string, any>, id: number) => {
if (isNew.value) { if (isNew.value) {
@ -240,20 +239,15 @@ const onCreatedRecord = (record: any) => {
:header="$t('activity.addNewLink')" :header="$t('activity.addNewLink')"
/> />
<div class="flex mt-2 mb-2 items-center gap-2"> <div class="flex mt-2 mb-2 items-center gap-2">
<div <div class="flex items-center border-1 p-1 rounded-md w-full border-gray-200 focus-within:!border-primary">
class="flex items-center border-1 p-1 rounded-md w-full border-gray-200"
:class="{ '!border-primary': childrenExcludedListPagination.query.length !== 0 || isFocused }"
>
<MdiMagnify class="w-5 h-5 ml-2 text-gray-500" /> <MdiMagnify class="w-5 h-5 ml-2 text-gray-500" />
<a-input <a-input
ref="filterQueryRef" :ref="filterQueryFocus"
v-model:value="childrenExcludedListPagination.query" v-model:value="childrenExcludedListPagination.query"
:placeholder="`${$t('general.searchIn')} ${relatedTableMeta?.title}`" :placeholder="`${$t('general.searchIn')} ${relatedTableMeta?.title}`"
class="w-full !rounded-md nc-excluded-search xs:min-h-8" class="w-full !rounded-md nc-excluded-search xs:min-h-8"
size="small" size="small"
:bordered="false" :bordered="false"
@focus="isFocused = true"
@blur="isFocused = false"
@keydown.capture.stop @keydown.capture.stop
@change="childrenExcludedListPagination.page = 1" @change="childrenExcludedListPagination.page = 1"
> >

Loading…
Cancel
Save