Browse Source

Merge pull request #4917 from nocodb/fix/4916-filter-value-key-events-issue

Fix: Grid view - keydown event handler issues
pull/4922/head
Raju Udava 2 years ago committed by GitHub
parent
commit
917c15713e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      packages/nc-gui/components/account/License.vue
  2. 24
      packages/nc-gui/components/smartsheet/Grid.vue
  3. 11
      packages/nc-gui/composables/useGlobal/actions.ts
  4. 1
      packages/nc-gui/composables/useGlobal/types.ts
  5. 7
      packages/nc-gui/composables/useMultiSelect/index.ts
  6. 2
      packages/nc-gui/pages/account/index.vue

7
packages/nc-gui/components/account/License.vue

@ -1,11 +1,13 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { extractSdkResponseErrorMsg, useApi } from '#imports' import { extractSdkResponseErrorMsg, useApi,useGlobal } from '#imports'
const { api, isLoading } = useApi() const { api, isLoading } = useApi()
const {$e} = useNuxtApp() const { $e } = useNuxtApp()
const { loadAppInfo } = useGlobal()
let key = $ref('') let key = $ref('')
@ -22,6 +24,7 @@ const setLicense = async () => {
try { try {
await api.orgLicense.set({ key: key }) await api.orgLicense.set({ key: key })
message.success('License key updated') message.success('License key updated')
await loadAppInfo();
} catch (e) { } catch (e) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))
} }

24
packages/nc-gui/components/smartsheet/Grid.vue

@ -173,8 +173,16 @@ const getContainerScrollForElement = (
return scroll return scroll
} }
const { isCellSelected, activeCell, handleMouseDown, handleMouseOver, handleCellClick, clearSelectedRange, copyValue } = const {
useMultiSelect( isCellSelected,
activeCell,
handleMouseDown,
handleMouseOver,
handleCellClick,
clearSelectedRange,
copyValue,
isCellActive,
} = useMultiSelect(
meta, meta,
fields, fields,
data, data,
@ -202,7 +210,7 @@ const { isCellSelected, activeCell, handleMouseDown, handleMouseOver, handleCell
const cmdOrCtrl = isMac() ? e.metaKey : e.ctrlKey const cmdOrCtrl = isMac() ? e.metaKey : e.ctrlKey
const altOrOptionKey = e.altKey const altOrOptionKey = e.altKey
if (e.key === ' ') { if (e.key === ' ') {
if (activeCell.row != null && !editEnabled && hasEditPermission) { if (isCellActive.value && !editEnabled && hasEditPermission) {
e.preventDefault() e.preventDefault()
clearSelectedRange() clearSelectedRange()
const row = data.value[activeCell.row] const row = data.value[activeCell.row]
@ -226,6 +234,8 @@ const { isCellSelected, activeCell, handleMouseDown, handleMouseOver, handleCell
} }
if (cmdOrCtrl) { if (cmdOrCtrl) {
if (!isCellActive.value) return
switch (e.key) { switch (e.key) {
case 'ArrowUp': case 'ArrowUp':
e.preventDefault() e.preventDefault()
@ -294,7 +304,7 @@ const { isCellSelected, activeCell, handleMouseDown, handleMouseOver, handleCell
// update/save cell value // update/save cell value
await updateOrSaveRow(rowObj, ctx.updatedColumnTitle || columnObj.title) await updateOrSaveRow(rowObj, ctx.updatedColumnTitle || columnObj.title)
}, },
) )
function scrollToCell(row?: number | null, col?: number | null) { function scrollToCell(row?: number | null, col?: number | null) {
row = row ?? activeCell.row row = row ?? activeCell.row
@ -674,8 +684,7 @@ const closeAddColumnDropdown = () => {
<thead ref="tableHead"> <thead ref="tableHead">
<tr class="nc-grid-header border-1 bg-gray-100 sticky top[-1px]"> <tr class="nc-grid-header border-1 bg-gray-100 sticky top[-1px]">
<th data-testid="grid-id-column"> <th data-testid="grid-id-column">
<div class="w-full h-full bg-gray-100 flex min-w-[70px] pl-5 pr-1 items-center" <div class="w-full h-full bg-gray-100 flex min-w-[70px] pl-5 pr-1 items-center" data-testid="nc-check-all">
data-testid="nc-check-all">
<template v-if="!readOnly"> <template v-if="!readOnly">
<div class="nc-no-label text-gray-500" :class="{ hidden: selectedAllRecords }">#</div> <div class="nc-no-label text-gray-500" :class="{ hidden: selectedAllRecords }">#</div>
<div <div
@ -897,8 +906,7 @@ const closeAddColumnDropdown = () => {
</div> </div>
</a-menu-item> </a-menu-item>
<a-menu-item v-if="contextMenuTarget" data-testid="context-menu-item-copy" <a-menu-item v-if="contextMenuTarget" data-testid="context-menu-item-copy" @click="copyValue(contextMenuTarget)">
@click="copyValue(contextMenuTarget)">
<div v-e="['a:row:copy']" class="nc-project-menu-item"> <div v-e="['a:row:copy']" class="nc-project-menu-item">
<!-- Copy --> <!-- Copy -->
{{ $t('general.copy') }} {{ $t('general.copy') }}

11
packages/nc-gui/composables/useGlobal/actions.ts

@ -43,5 +43,14 @@ export function useGlobalActions(state: State): Actions {
}) })
} }
return { signIn, signOut, refreshToken } const loadAppInfo = async () => {
try {
const nuxtApp = useNuxtApp()
state.appInfo.value = await nuxtApp.$api.utils.appInfo()
} catch (e) {
console.error(e)
}
}
return { signIn, signOut, refreshToken, loadAppInfo }
} }

1
packages/nc-gui/composables/useGlobal/types.ts

@ -61,6 +61,7 @@ export interface Actions {
signOut: () => void signOut: () => void
signIn: (token: string) => void signIn: (token: string) => void
refreshToken: () => void refreshToken: () => void
loadAppInfo: () => void
} }
export type ReadonlyState = Readonly<Pick<State, 'token' | 'user'>> & Omit<State, 'token' | 'user'> export type ReadonlyState = Readonly<Pick<State, 'token' | 'user'>> & Omit<State, 'token' | 'user'>

7
packages/nc-gui/composables/useMultiSelect/index.ts

@ -61,6 +61,10 @@ export function useMultiSelect(
const columnLength = $computed(() => unref(fields)?.length) const columnLength = $computed(() => unref(fields)?.length)
const isCellActive = computed(
() => !(activeCell.row === null || activeCell.col === null || isNaN(activeCell.row) || isNaN(activeCell.col)),
)
function makeActive(row: number, col: number) { function makeActive(row: number, col: number) {
if (activeCell.row === row && activeCell.col === col) { if (activeCell.row === row && activeCell.col === col) {
return return
@ -171,7 +175,7 @@ export function useMultiSelect(
return true return true
} }
if (activeCell.row === null || activeCell.col === null) { if (!isCellActive.value) {
return return
} }
@ -367,6 +371,7 @@ export function useMultiSelect(
useEventListener(document, 'mouseup', handleMouseUp) useEventListener(document, 'mouseup', handleMouseUp)
return { return {
isCellActive,
handleMouseDown, handleMouseDown,
handleMouseOver, handleMouseOver,
clearSelectedRange, clearSelectedRange,

2
packages/nc-gui/pages/account/index.vue

@ -81,7 +81,7 @@ const openKeys = ref([/^\/account\/users/.test($route.fullPath) && 'users'])
</a-menu-item> </a-menu-item>
<a-menu-item <a-menu-item
v-if="isUIAllowed('license')" v-if="isUIAllowed('license')"
key="apps" key="license"
class="group active:(!ring-0) hover:(!bg-primary !bg-opacity-25)" class="group active:(!ring-0) hover:(!bg-primary !bg-opacity-25)"
@click="navigateTo('/account/license')" @click="navigateTo('/account/license')"
> >

Loading…
Cancel
Save