Browse Source

Merge pull request #7624 from nocodb/nc-linked-records

fix(nc-gui): linked record keyboard navigation
pull/7636/head
Raju Udava 8 months ago committed by GitHub
parent
commit
bf4421200a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 40
      packages/nc-gui/components/virtual-cell/components/ListChildItems.vue
  2. 3
      packages/nc-gui/components/virtual-cell/components/ListItem.vue
  3. 37
      packages/nc-gui/components/virtual-cell/components/ListItems.vue

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

@ -1,22 +1,20 @@
<script lang="ts" setup> <script lang="ts" setup>
import { type ColumnType, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk' import { type ColumnType, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'
import type { Row } from '#imports'
import InboxIcon from '~icons/nc-icons/inbox'
import { import {
ColumnInj, ColumnInj,
IsFormInj, IsFormInj,
IsPublicInj, IsPublicInj,
ReadonlyInj, ReadonlyInj,
type Row,
computed, computed,
inject, inject,
isPrimary, isPrimary,
onKeyStroke,
ref, ref,
useLTARStoreOrThrow, useLTARStoreOrThrow,
useSmartsheetRowStoreOrThrow, useSmartsheetRowStoreOrThrow,
useVModel, useVModel,
} from '#imports' } from '#imports'
import InboxIcon from '~icons/nc-icons/inbox'
interface Prop { interface Prop {
modelValue?: boolean modelValue?: boolean
@ -129,10 +127,6 @@ watch(expandedFormDlg, () => {
} }
}) })
onKeyStroke('Escape', () => {
vModel.value = false
})
/* /*
to render same number of skeleton as the number of cards to render same number of skeleton as the number of cards
displayed displayed
@ -181,6 +175,34 @@ watch([filterQueryRef, isDataExist], () => {
filterQueryRef.value?.focus() filterQueryRef.value?.focus()
} }
}) })
const linkedShortcuts = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
vModel.value = false
} else if (e.key === 'ArrowDown') {
e.preventDefault()
try {
e.target?.nextElementSibling?.focus()
} catch (e) {}
} else if (e.key === 'ArrowUp') {
e.preventDefault()
try {
e.target?.previousElementSibling?.focus()
} catch (e) {}
} else if (e.key !== 'Tab' && e.key !== 'Shift' && e.key !== 'Enter' && e.key !== ' ') {
try {
filterQueryRef.value?.focus()
} catch (e) {}
}
}
onMounted(() => {
window.addEventListener('keydown', linkedShortcuts)
})
onUnmounted(() => {
window.removeEventListener('keydown', linkedShortcuts)
})
</script> </script>
<template> <template>
@ -271,6 +293,8 @@ watch([filterQueryRef, isDataExist], () => {
:is-linked="childrenList?.list ? isChildrenListLinked[Number.parseInt(id)] : true" :is-linked="childrenList?.list ? isChildrenListLinked[Number.parseInt(id)] : true"
:is-loading="isChildrenListLoading[Number.parseInt(id)]" :is-loading="isChildrenListLoading[Number.parseInt(id)]"
@expand="onClick(refRow)" @expand="onClick(refRow)"
@keydown.space.prevent="linkOrUnLink(refRow, id)"
@keydown.enter.prevent="() => onClick(refRow, id)"
@click="linkOrUnLink(refRow, id)" @click="linkOrUnLink(refRow, id)"
/> />
</template> </template>

3
packages/nc-gui/components/virtual-cell/components/ListItem.vue

@ -89,7 +89,8 @@ const displayValue = computed(() => {
<template> <template>
<a-card <a-card
class="nc-list-item !border-1 group transition-all !rounded-xl relative !mb-2 !border-gray-200 hover:bg-gray-50" tabindex="0"
class="nc-list-item !outline-brand-500 !border-1 group transition-all !rounded-xl relative !mb-2 !border-gray-200 hover:bg-gray-50"
:class="{ :class="{
'!bg-white': isLoading, '!bg-white': isLoading,
'!border-1': isLinked && !isLoading, '!border-1': isLinked && !isLoading,

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

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { RelationTypes, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { RelationTypes, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'
import InboxIcon from '~icons/nc-icons/inbox' import InboxIcon from '~icons/nc-icons/inbox'
import { import {
ColumnInj, ColumnInj,
@ -8,7 +8,6 @@ import {
SaveRowInj, SaveRowInj,
computed, computed,
inject, inject,
onKeyStroke,
ref, ref,
useLTARStoreOrThrow, useLTARStoreOrThrow,
useSmartsheetRowStoreOrThrow, useSmartsheetRowStoreOrThrow,
@ -173,10 +172,6 @@ watch(filterQueryRef, () => {
filterQueryRef.value?.focus() filterQueryRef.value?.focus()
}) })
onKeyStroke('Escape', () => {
vModel.value = false
})
const onClick = (refRow: any, id: string) => { const onClick = (refRow: any, id: string) => {
if (isSharedBase.value) return if (isSharedBase.value) return
if (isChildrenExcludedListLinked.value[Number.parseInt(id)]) { if (isChildrenExcludedListLinked.value[Number.parseInt(id)]) {
@ -221,6 +216,34 @@ const onCreatedRecord = (record: any) => {
message.success(msgVNode) message.success(msgVNode)
} }
const linkedShortcuts = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
vModel.value = false
} else if (e.key === 'ArrowDown') {
e.preventDefault()
try {
e.target?.nextElementSibling?.focus()
} catch (e) {}
} else if (e.key === 'ArrowUp') {
e.preventDefault()
try {
e.target?.previousElementSibling?.focus()
} catch (e) {}
} else if (e.key !== 'Tab' && e.key !== 'Shift' && e.key !== 'Enter' && e.key !== ' ') {
try {
filterQueryRef.value?.focus()
} catch (e) {}
}
}
onMounted(() => {
window.addEventListener('keydown', linkedShortcuts)
})
onUnmounted(() => {
window.removeEventListener('keydown', linkedShortcuts)
})
</script> </script>
<template> <template>
@ -328,6 +351,8 @@ const onCreatedRecord = (record: any) => {
expandedFormDlg = true expandedFormDlg = true
} }
" "
@keydown.space.prevent="() => onClick(refRow, id)"
@keydown.enter.prevent="() => onClick(refRow, id)"
@click="() => onClick(refRow, id)" @click="() => onClick(refRow, id)"
/> />
</template> </template>

Loading…
Cancel
Save