Browse Source

fix: type errors for select cells

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/4005/head
mertmit 2 years ago
parent
commit
c9b18ee3ac
  1. 13
      packages/nc-gui/components/cell/MultiSelect.vue
  2. 6
      packages/nc-gui/components/cell/SingleSelect.vue

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

@ -1,5 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { Select as AntSelect } from 'ant-design-vue' import type { Select as AntSelect } from 'ant-design-vue'
import { SelectOptionType } from 'nocodb-sdk'
import type { SelectOptionsType } from 'nocodb-sdk' import type { SelectOptionsType } from 'nocodb-sdk'
import { import {
ActiveCellInj, ActiveCellInj,
@ -41,13 +42,13 @@ const isOpen = ref(false)
const isKanban = inject(IsKanbanInj, ref(false)) const isKanban = inject(IsKanbanInj, ref(false))
const options = computed<SelectOptionsType[]>(() => { const options = computed<SelectOptionType[]>(() => {
if (column?.value.colOptions) { if (column?.value.colOptions) {
const opts = column.value.colOptions const opts = column.value.colOptions
? (column.value.colOptions as any).options.filter((el: any) => el.title !== '') || [] ? (column.value.colOptions as SelectOptionsType).options.filter((el: SelectOptionType) => el.title !== '') || []
: [] : []
for (const op of opts.filter((el: any) => el.order === null)) { for (const op of opts.filter((el: SelectOptionType) => el.order === null)) {
op.title = op.title.replace(/^'/, '').replace(/'$/, '') op.title = op.title?.replace(/^'/, '').replace(/'$/, '')
} }
return opts return opts
} }
@ -55,7 +56,7 @@ const options = computed<SelectOptionsType[]>(() => {
}) })
const vModel = computed({ const vModel = computed({
get: () => selectedIds.value.map((el) => options.value.find((op) => op.id === el)?.title), get: () => selectedIds.value.map((el) => options.value.find((op) => op.id === el)?.title) as string[],
set: (val) => emit('update:modelValue', val.length === 0 ? null : val.join(',')), set: (val) => emit('update:modelValue', val.length === 0 ? null : val.join(',')),
}) })
@ -153,7 +154,7 @@ watch(isOpen, (n, _o) => {
v-if="options.find((el) => el.title === val)" v-if="options.find((el) => el.title === val)"
class="rounded-tag" class="rounded-tag"
:style="{ display: 'flex', alignItems: 'center' }" :style="{ display: 'flex', alignItems: 'center' }"
:color="options.find((el) => el.title === val).color" :color="(options.find((el) => el.title === val) as SelectOptionType).color"
:closable="active && (vModel.length > 1 || !column?.rqd)" :closable="active && (vModel.length > 1 || !column?.rqd)"
:close-icon="h(MdiCloseCircle, { class: ['ms-close-icon'] })" :close-icon="h(MdiCloseCircle, { class: ['ms-close-icon'] })"
@close="onClose" @close="onClose"

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

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { Select as AntSelect } from 'ant-design-vue' import type { Select as AntSelect } from 'ant-design-vue'
import type { SelectOptionsType } from 'nocodb-sdk' import type { SelectOptionType } from 'nocodb-sdk'
import { ActiveCellInj, ColumnInj, IsKanbanInj, ReadonlyInj, computed, inject, ref, useEventListener, watch } from '#imports' import { ActiveCellInj, ColumnInj, IsKanbanInj, ReadonlyInj, computed, inject, ref, useEventListener, watch } from '#imports'
interface Props { interface Props {
@ -28,11 +28,11 @@ const vModel = computed({
set: (val) => emit('update:modelValue', val || null), set: (val) => emit('update:modelValue', val || null),
}) })
const options = computed<SelectOptionsType[]>(() => { const options = computed<SelectOptionType[]>(() => {
if (column?.value.colOptions) { if (column?.value.colOptions) {
const opts = column.value.colOptions const opts = column.value.colOptions
? // todo: fix colOptions type, options does not exist as a property ? // todo: fix colOptions type, options does not exist as a property
(column.value.colOptions as any).options.filter((el: SelectOptionsType) => el.title !== '') || [] (column.value.colOptions as any).options.filter((el: SelectOptionType) => el.title !== '') || []
: [] : []
for (const op of opts.filter((el: any) => el.order === null)) { for (const op of opts.filter((el: any) => el.order === null)) {
op.title = op.title.replace(/^'/, '').replace(/'$/, '') op.title = op.title.replace(/^'/, '').replace(/'$/, '')

Loading…
Cancel
Save