Browse Source

fix(gui-v2): pass validation cb to `RenameableMenuItem` and validate before rename event

pull/3094/head
braks 2 years ago
parent
commit
5c6fa6aacb
  1. 18
      packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue
  2. 16
      packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue

18
packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue

@ -61,12 +61,12 @@ function markItem(id: string) {
}
/** validate view title */
function validate(value?: string) {
if (!value || value.trim().length < 0) {
function validate(view: Record<string, any>) {
if (!view.title || view.title.trim().length < 0) {
return 'View name is required'
}
if (views.value.every((v1) => v1.title !== value)) {
if (views.value.some((v) => v.title === view.title && v.id !== view.id)) {
return 'View name should be unique'
}
@ -141,17 +141,6 @@ function changeView(view: { id: string; alias?: string; title?: string; type: Vi
/** Rename a view */
async function onRename(view: ViewType) {
const valid = validate(view.title)
if (valid !== true) {
notification.error({
message: valid,
duration: 2,
})
return
}
try {
await api.dbView.update(view.id!, {
title: view.title,
@ -195,6 +184,7 @@ function onDeleted() {
:id="view.id"
:key="view.id"
:view="view"
:on-validate="validate"
class="transition-all ease-in duration-300"
:class="[
isMarked === view.id ? 'bg-gray-200' : '',

16
packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue

@ -1,10 +1,12 @@
<script lang="ts" setup>
import type { ViewTypes } from 'nocodb-sdk'
import { notification } from 'ant-design-vue'
import { viewIcons } from '~/utils'
import { useDebounceFn, useNuxtApp, useVModel } from '#imports'
import { onKeyStroke, useDebounceFn, useNuxtApp, useVModel } from '#imports'
interface Props {
view: Record<string, any>
onValidate: (view: Record<string, any>) => boolean | string
}
interface Emits {
@ -99,6 +101,18 @@ async function onDelete() {
async function onRename() {
if (!isEditing) return
const isValid = props.onValidate(vModel.value)
if (isValid !== true) {
notification.error({
message: isValid,
duration: 2,
})
onCancel()
return
}
if (vModel.value.title === '' || vModel.value.title === originalTitle) {
onCancel()
return

Loading…
Cancel
Save