Browse Source

feat(gui-v2): single/multi select cells

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3022/head
mertmit 2 years ago
parent
commit
58b6b9aedc
  1. 1
      packages/nc-gui-v2/components.d.ts
  2. 131
      packages/nc-gui-v2/components/cell/MultiSelect.vue
  3. 74
      packages/nc-gui-v2/components/cell/SingleSelect.vue
  4. 8
      packages/nocodb-sdk/src/lib/Api.ts
  5. 39
      scripts/sdk/swagger.json

1
packages/nc-gui-v2/components.d.ts vendored

@ -57,6 +57,7 @@ declare module '@vue/runtime-core' {
ATableColumn: typeof import('ant-design-vue/es')['TableColumn'] ATableColumn: typeof import('ant-design-vue/es')['TableColumn']
ATabPane: typeof import('ant-design-vue/es')['TabPane'] ATabPane: typeof import('ant-design-vue/es')['TabPane']
ATabs: typeof import('ant-design-vue/es')['Tabs'] ATabs: typeof import('ant-design-vue/es')['Tabs']
ATag: typeof import('ant-design-vue/es')['Tag']
ATextarea: typeof import('ant-design-vue/es')['Textarea'] ATextarea: typeof import('ant-design-vue/es')['Textarea']
ATimePicker: typeof import('ant-design-vue/es')['TimePicker'] ATimePicker: typeof import('ant-design-vue/es')['TimePicker']
ATooltip: typeof import('ant-design-vue/es')['Tooltip'] ATooltip: typeof import('ant-design-vue/es')['Tooltip']

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

@ -1,76 +1,97 @@
<script lang="ts" setup> <script lang="ts" setup>
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 { ColumnInj } from '~/context'
interface Props { interface Props {
modelValue: string | null modelValue: string | string[] | undefined
} }
const { modelValue } = defineProps<Props>() const { modelValue } = defineProps<Props>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const { isMysql } = useProject()
const column = inject(ColumnInj) const column = inject(ColumnInj)
const options = computed(() => column?.value?.dtxp?.split(',').map((v) => v.replace(/\\'/g, "'").replace(/^'|'$/g, '')) || []) const options = computed(() => {
if (column?.colOptions) {
const opts = column.colOptions ? column.colOptions.options.filter((el: SelectOptionType) => el.title !== '') || [] : []
for (const op of opts.filter((el: SelectOptionType) => el.order === null)) {
op.title = op.title.replace(/^'/, '').replace(/'$/, '')
}
return opts
}
return []
})
const localState = computed({ const vModel = computed({
get() { get: () =>
return modelValue?.match(/(?:[^',]|\\')+(?='?(?:,|$))/g)?.map((v: string) => v.replace(/\\'/g, "'")) modelValue
}, ? typeof modelValue === 'string'
set(val?: string[]) { ? isMysql
emit('update:modelValue', val?.filter((v) => options.value.includes(v)).join(',')) ? modelValue.split(',').sort((a, b) => {
}, const opa = options.value.find((el: SelectOptionType) => el.title === a)
const opb = options.value.find((el: SelectOptionType) => el.title === b)
return opa.order - opb.order
})
: modelValue.split(',')
: modelValue
: [],
set: (val) => emit('update:modelValue', val.join(',')),
}) })
</script> </script>
<template> <template>
<!-- <a-select
<v-select v-model:value="vModel"
v-model="localState" mode="multiple"
:items="options" class="w-full"
hide-details placeholder="Select an option"
:clearable="!column.rqd" :bordered="false"
variation="outlined" show-arrow
multiple :show-search="false"
/>
-->
<v-combobox
v-model="localState"
:items="options"
multiple
chips
flat
dense
solo
hide-details
deletable-chips
class="text-center mt-0"
> >
<!-- <template #selection="data"> --> <a-select-option v-for="op of options" :key="op.title" style="cursor: pointer">
<!-- <v-chip --> <a-tag :color="op.color">
<!-- :key="data.item" --> <span class="text-slate-500">{{ op.title }}</span>
<!-- small --> </a-tag>
<!-- class="ma-1 " --> </a-select-option>
<!-- :color="colors[setValues.indexOf(data.item) % colors.length]" --> <template #tagRender="{ value: val, label, onClose }">
<!-- @click:close="data.parent.selectItem(data.item)" --> <a-tag :color="label[0].props.color" :closable="true" @close="onClose">
<!-- > --> <span class="text-slate-500">{{ val }}</span>
<!-- {{ data.item }} --> </a-tag>
<!-- </v-chip> --> </template>
<!-- </template> --> </a-select>
<!-- <template #item="{item}"> -->
<!-- <v-chip small :color="colors[setValues.indexOf(item) % colors.length]"> -->
<!-- {{ item }} -->
<!-- </v-chip> -->
<!-- </template> -->
<!-- <template #append> -->
<!-- <v-icon small class="mt-2"> -->
<!-- mdi-menu-down -->
<!-- </v-icon> -->
<!-- </template> -->
</v-combobox>
</template> </template>
<style scoped></style> <style scoped>
:deep(.ant-tag-close-icon) {
@apply "text-slate-500";
}
</style>
<!--
/**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
*
* @author Naveen MR <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-->

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

@ -1,9 +1,10 @@
<script lang="ts" setup> <script lang="ts" setup>
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 { ColumnInj } from '~/context'
interface Props { interface Props {
modelValue: string | null modelValue: string | undefined
} }
const { modelValue } = defineProps<Props>() const { modelValue } = defineProps<Props>()
@ -13,60 +14,39 @@ const emit = defineEmits(['update:modelValue'])
const column = inject(ColumnInj)! const column = inject(ColumnInj)!
const vModel = computed({ const vModel = computed({
get: () => modelValue?.replace(/\\'/g, "'").replace(/^'|'$/g, ''), get: () => modelValue,
set: (val) => emit('update:modelValue', val), set: (val) => emit('update:modelValue', val),
}) })
const options = computed(() => column.value.dtxp?.split(',').map((v) => v.replace(/\\'/g, "'").replace(/^'|'$/g, '')) || []) const options = computed(() => {
if (column?.colOptions) {
const opts = column.colOptions ? column.colOptions.options.filter((el: SelectOptionType) => el.title !== '') || [] : []
for (const op of opts.filter((el: SelectOptionType) => el.order === null)) {
op.title = op.title.replace(/^'/, '').replace(/'$/, '')
}
return opts
}
return []
})
</script> </script>
<template> <template>
<v-select v-model="vModel" :items="options" hide-details :clearable="!column.rqd" variation="outlined"> <a-select
<!-- v-on="parentListeners" v-model:value="vModel"
<template #selection="{ item }"> class="w-full fill"
<div :allow-clear="!column.rqd"
class="d-100" placeholder="Select an option"
:class="{ :bordered="false"
'text-center': !isForm, >
}" <a-select-option v-for="op of options" :key="op.title">
> <a-tag :color="op.color">
<v-chip small :color="enumColor.light[options.indexOf(item) % enumColor.light.length]" class="ma-1"> <span class="text-slate-500">{{ op.title }}</span>
{{ item.text }} </a-tag>
</v-chip> </a-select-option>
</div> </a-select>
</template>
<template #item="{ item }">
<v-chip small :color="enumColor.light[options.indexOf(item) % enumColor.light.length]">
{{ item }}
</v-chip>
</template>
<template #append>
<v-icon small class="mt-1"> mdi-menu-down</v-icon>
</template> -->
</v-select>
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss"></style>
/*:deep {
.v-select {
min-width: 150px;
}
.v-input__slot {
padding-right: 0 !important;
padding-left: 35px !important;
}
.v-input__icon.v-input__icon--clear {
width: 15px !important;
min-width: 13px !important;
.v-icon {
font-size: 13px !important;
}
}
}*/
</style>
<!-- <!--
/** /**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd * @copyright Copyright (c) 2021, Xgene Cloud Ltd

8
packages/nocodb-sdk/src/lib/Api.ts

@ -242,7 +242,7 @@ export interface ColumnType {
| FormulaType | FormulaType
| RollupType | RollupType
| LookupType | LookupType
| SelectOptionsType[] | SelectOptionsType
| object; | object;
} }
@ -303,9 +303,11 @@ export interface FormulaType {
} }
export interface SelectOptionsType { export interface SelectOptionsType {
options: SelectOptionType;
}
export interface SelectOptionType {
id?: string; id?: string;
type?: string;
virtual?: boolean;
fk_column_id?: string; fk_column_id?: string;
title?: string; title?: string;
color?: string; color?: string;

39
scripts/sdk/swagger.json

@ -6605,10 +6605,7 @@
"$ref": "#/components/schemas/Lookup" "$ref": "#/components/schemas/Lookup"
}, },
{ {
"type": "array", "$ref": "#/components/schemas/SelectOptions"
"items": {
"$ref": "#/components/schemas/SelectOptions"
}
}, },
{ {
"type": "object" "type": "object"
@ -6821,16 +6818,34 @@
"SelectOptions": { "SelectOptions": {
"title": "SelectOptions", "title": "SelectOptions",
"type": "object", "type": "object",
"properties": {
"options": {
"type": "array",
"required": true,
"$ref": "#/components/schemas/SelectOption"
}
},
"examples": [
{
"options": [
{
"id": "string",
"fk_column_id": "string",
"title": "string",
"color": "string",
"order": 1
}
]
}
]
},
"SelectOption": {
"title": "SelectOption",
"type": "object",
"properties": { "properties": {
"id": { "id": {
"type": "string" "type": "string"
}, },
"type": {
"type": "string"
},
"virtual": {
"type": "boolean"
},
"fk_column_id": { "fk_column_id": {
"type": "string" "type": "string"
}, },
@ -6847,12 +6862,10 @@
"examples": [ "examples": [
{ {
"id": "string", "id": "string",
"type": "string",
"virtual": true,
"fk_column_id": "string", "fk_column_id": "string",
"title": "string", "title": "string",
"color": "string", "color": "string",
"order": 0 "order": 1
} }
] ]
}, },

Loading…
Cancel
Save