Browse Source

refactor(gui): reload table meta after adding new option

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4406/head
Pranav C 2 years ago
parent
commit
064436d550
  1. 3
      packages/nc-gui/components/cell/MultiSelect.vue
  2. 10
      packages/nc-gui/components/cell/SingleSelect.vue
  3. 1
      packages/nc-gui/composables/useMultiSelect/index.ts

3
packages/nc-gui/components/cell/MultiSelect.vue

@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { message } from 'ant-design-vue'
import tinycolor from 'tinycolor2' import tinycolor from 'tinycolor2'
import type { Select as AntSelect } from 'ant-design-vue' import type { Select as AntSelect } from 'ant-design-vue'
import type { SelectOptionType, SelectOptionsType } from 'nocodb-sdk' import type { SelectOptionType, SelectOptionsType } from 'nocodb-sdk'
@ -20,6 +21,7 @@ import {
useSelectedCellKeyupListener, useSelectedCellKeyupListener,
watch, watch,
} from '#imports' } from '#imports'
import { extractSdkResponseErrorMsg } from '~/utils'
import MdiCloseCircle from '~icons/mdi/close-circle' import MdiCloseCircle from '~icons/mdi/close-circle'
interface Props { interface Props {
@ -210,6 +212,7 @@ async function addIfMissingAndSave() {
// todo: handle error // todo: handle error
console.log(e) console.log(e)
activeOptCreateInProgress.value-- activeOptCreateInProgress.value--
message.error(await extractSdkResponseErrorMsg(e))
} }
} }

10
packages/nc-gui/components/cell/SingleSelect.vue

@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { message } from 'ant-design-vue'
import tinycolor from 'tinycolor2' import tinycolor from 'tinycolor2'
import type { Select as AntSelect } from 'ant-design-vue' import type { Select as AntSelect } from 'ant-design-vue'
import type { SelectOptionType } from 'nocodb-sdk' import type { SelectOptionType } from 'nocodb-sdk'
@ -15,6 +16,7 @@ import {
ref, ref,
watch, watch,
} from '#imports' } from '#imports'
import { extractSdkResponseErrorMsg } from '~/utils'
interface Props { interface Props {
modelValue?: string | undefined modelValue?: string | undefined
@ -45,6 +47,8 @@ const { $api } = useNuxtApp()
const searchVal = ref() const searchVal = ref()
const { getMeta } = useMetas()
// a variable to keep newly created option value // a variable to keep newly created option value
// temporary until it's add the option to column meta // temporary until it's add the option to column meta
const tempSelectedOptState = ref<string>() const tempSelectedOptState = ref<string>()
@ -108,6 +112,7 @@ async function addIfMissingAndSave() {
searchVal.value = '' searchVal.value = ''
if (newOptValue && !options.value.some((o) => o.title === newOptValue)) { if (newOptValue && !options.value.some((o) => o.title === newOptValue)) {
try {
options.value.push({ options.value.push({
title: newOptValue, title: newOptValue,
value: newOptValue, value: newOptValue,
@ -119,6 +124,11 @@ async function addIfMissingAndSave() {
...column.value, ...column.value,
}) })
vModel.value = newOptValue vModel.value = newOptValue
await getMeta(column.value.fk_model_id!, true)
} catch (e) {
console.log(e)
message.error(await extractSdkResponseErrorMsg(e))
}
} }
} }

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

@ -131,7 +131,6 @@ export function useMultiSelect(
}) })
const onKeyDown = async (e: KeyboardEvent) => { const onKeyDown = async (e: KeyboardEvent) => {
// invoke the keyEventHandler if provided and return if it returns true // invoke the keyEventHandler if provided and return if it returns true
if (await keyEventHandler?.(e)) { if (await keyEventHandler?.(e)) {
return true return true

Loading…
Cancel
Save