Browse Source

feat(gui-v2): ux improvements for select cells

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3022/head
mertmit 2 years ago
parent
commit
a1b35baba3
  1. 10
      packages/nc-gui-v2/components/cell/MultiSelect.vue
  2. 20
      packages/nc-gui-v2/components/cell/SingleSelect.vue
  3. 7
      packages/nc-gui-v2/components/smartsheet/Cell.vue
  4. 1
      packages/nc-gui-v2/components/smartsheet/Grid.vue

10
packages/nc-gui-v2/components/cell/MultiSelect.vue

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionType } from '~~/../nocodb-sdk/build/main/index.js' import type { SelectOptionType } from '~~/../nocodb-sdk/build/main/index.js'
import { computed, inject } from '#imports' import { computed, inject } from '#imports'
import { ColumnInj } from '~/context' import { ActiveCellInj, ColumnInj, EditModeInj } from '~/context'
interface Props { interface Props {
modelValue: string | string[] | undefined modelValue: string | string[] | undefined
@ -16,6 +16,8 @@ const { isMysql } = useProject()
const column = inject(ColumnInj) const column = inject(ColumnInj)
const isForm = inject<boolean>('isForm', false) const isForm = inject<boolean>('isForm', false)
const editEnabled = inject(EditModeInj, ref(false)) const editEnabled = inject(EditModeInj, ref(false))
const active = inject(ActiveCellInj, ref(false))
const selectedIds = ref<string[]>([]) const selectedIds = ref<string[]>([])
const options = computed(() => { const options = computed(() => {
@ -31,7 +33,7 @@ const options = computed(() => {
const vModel = computed({ const vModel = computed({
get: () => selectedIds.value.map((el) => options.value.find((op: SelectOptionType) => op.id === el).title), get: () => selectedIds.value.map((el) => options.value.find((op: SelectOptionType) => op.id === el).title),
set: (val) => emit('update:modelValue', val.join(',')), set: (val) => emit('update:modelValue', val.length === 0 ? null : val.join(',')),
}) })
const selectedTitles = computed(() => const selectedTitles = computed(() =>
@ -59,7 +61,7 @@ onMounted(() => {
watch( watch(
() => modelValue, () => modelValue,
(n, _o) => { (_n, _o) => {
selectedIds.value = selectedTitles.value.map((el) => { selectedIds.value = selectedTitles.value.map((el) => {
return options.value.find((op: SelectOptionType) => op.title === el).id return options.value.find((op: SelectOptionType) => op.title === el).id
}) })
@ -87,7 +89,7 @@ watch(
v-if="options.find((el: SelectOptionType) => el.title === val)" v-if="options.find((el: SelectOptionType) => el.title === val)"
class="rounded-tag" class="rounded-tag"
:color="options.find((el: SelectOptionType) => el.title === val).color" :color="options.find((el: SelectOptionType) => el.title === val).color"
:closable="editEnabled" :closable="active && (vModel.length > 1 || !column?.rqd)"
@close="onClose" @close="onClose"
> >
<span class="text-slate-500">{{ val }}</span> <span class="text-slate-500">{{ val }}</span>

20
packages/nc-gui-v2/components/cell/SingleSelect.vue

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionType } from '~~/../nocodb-sdk/build/main/index.js' import type { SelectOptionType } from '~~/../nocodb-sdk/build/main/index.js'
import { computed, inject } from '#imports' import { computed, inject } from '#imports'
import { ColumnInj } from '~/context' import { ActiveCellInj, ColumnInj, EditModeInj } from '~/context'
interface Props { interface Props {
modelValue: string | undefined modelValue: string | undefined
@ -11,11 +11,14 @@ const { modelValue } = defineProps<Props>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const column = inject(ColumnInj)! const column = inject(ColumnInj)
const isForm = inject<boolean>('isForm', false)
const editEnabled = inject(EditModeInj, ref(false))
const active = inject(ActiveCellInj, ref(false))
const vModel = computed({ const vModel = computed({
get: () => modelValue, get: () => modelValue,
set: (val) => emit('update:modelValue', val), set: (val) => emit('update:modelValue', val || null),
}) })
const options = computed(() => { const options = computed(() => {
@ -31,7 +34,13 @@ const options = computed(() => {
</script> </script>
<template> <template>
<a-select v-model:value="vModel" class="w-full" :allow-clear="!column.rqd" placeholder="Select an option" :bordered="false"> <a-select
v-model:value="vModel"
class="w-full"
:allow-clear="!column.rqd && active"
placeholder="Select an option"
:bordered="false"
>
<a-select-option v-for="op of options" :key="op.title"> <a-select-option v-for="op of options" :key="op.title">
<a-tag class="rounded-tag" :color="op.color"> <a-tag class="rounded-tag" :color="op.color">
<span class="text-slate-500">{{ op.title }}</span> <span class="text-slate-500">{{ op.title }}</span>
@ -48,6 +57,9 @@ const options = computed(() => {
:deep(.ant-tag) { :deep(.ant-tag) {
@apply "rounded-tag"; @apply "rounded-tag";
} }
:deep(.ant-select-clear) {
opacity: 1;
}
</style> </style>
<!-- <!--
/** /**

7
packages/nc-gui-v2/components/smartsheet/Cell.vue

@ -3,7 +3,7 @@ import { UITypes } from 'nocodb-sdk'
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { provide, toRef } from 'vue' import { provide, toRef } from 'vue'
import { computed, useColumn, useDebounceFn, useVModel } from '#imports' import { computed, useColumn, useDebounceFn, useVModel } from '#imports'
import { ColumnInj, EditModeInj } from '~/context' import { ActiveCellInj, ColumnInj, EditModeInj } from '~/context'
import { NavigateDir } from '~/lib' import { NavigateDir } from '~/lib'
interface Props { interface Props {
@ -11,6 +11,7 @@ interface Props {
modelValue: any modelValue: any
editEnabled: boolean editEnabled: boolean
rowIndex: number rowIndex: number
active?: boolean
} }
const props = defineProps<Props>() const props = defineProps<Props>()
@ -19,10 +20,14 @@ const emit = defineEmits(['update:modelValue', 'save', 'navigate', 'update:editE
const column = toRef(props, 'column') const column = toRef(props, 'column')
const active = toRef(props, 'active', false)
provide(ColumnInj, column) provide(ColumnInj, column)
provide(EditModeInj, useVModel(props, 'editEnabled', emit)) provide(EditModeInj, useVModel(props, 'editEnabled', emit))
provide(ActiveCellInj, active)
let changed = $ref(false) let changed = $ref(false)
const syncValue = useDebounceFn(function () { const syncValue = useDebounceFn(function () {

1
packages/nc-gui-v2/components/smartsheet/Grid.vue

@ -350,6 +350,7 @@ const onNavigate = (dir: NavigateDir) => {
:column="columnObj" :column="columnObj"
:edit-enabled="editEnabled && selected.col === colIndex && selected.row === rowIndex" :edit-enabled="editEnabled && selected.col === colIndex && selected.row === rowIndex"
:row-index="rowIndex" :row-index="rowIndex"
:active="selected.col === colIndex && selected.row === rowIndex"
@update:edit-enabled="editEnabled = false" @update:edit-enabled="editEnabled = false"
@save="updateOrSaveRow(row, columnObj.title)" @save="updateOrSaveRow(row, columnObj.title)"
@navigate="onNavigate" @navigate="onNavigate"

Loading…
Cancel
Save