Browse Source

fix(gui): close options list when if not active or editable

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4957/head
Pranav C 2 years ago
parent
commit
1c3629f6e7
  1. 124
      packages/nc-gui/components/cell/MultiSelect.vue

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

@ -114,13 +114,13 @@ const selectedTitles = computed(() =>
? typeof modelValue === 'string' ? typeof modelValue === 'string'
? isMysql(column.value.base_id) ? isMysql(column.value.base_id)
? modelValue.split(',').sort((a, b) => { ? modelValue.split(',').sort((a, b) => {
const opa = options.value.find((el) => el.title === a) const opa = options.value.find((el) => el.title === a)
const opb = options.value.find((el) => el.title === b) const opb = options.value.find((el) => el.title === b)
if (opa && opb) { if (opa && opb) {
return opa.order! - opb.order! return opa.order! - opb.order!
} }
return 0 return 0
}) })
: modelValue.split(',') : modelValue.split(',')
: modelValue : modelValue
: [], : [],
@ -233,7 +233,7 @@ async function addIfMissingAndSave() {
// Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped // Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped
if (!isMysql(column.value.base_id)) { if (!isMysql(column.value.base_id)) {
updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'") updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, '\'')
} }
} }
@ -276,32 +276,33 @@ const onTagClick = (e: Event, onClose: Function) => {
</script> </script>
<template> <template>
<a-select <div class="nc-multi-select h-full w-full flex items-center"
ref="aselect" @click="isOpen = editAllowed && !isOpen" :class="{ 'read-only': readOnly }">
v-model:value="vModel" <a-select
v-model:open="isOpen" ref="aselect"
mode="multiple" v-model:value="vModel"
class="w-full overflow-hidden" mode="multiple"
:bordered="false" class="w-full overflow-hidden"
clear-icon :bordered="false"
show-search clear-icon
:show-arrow="hasEditRoles && !readOnly && (editable || (active && vModel.length === 0))" show-search
:open="isOpen && (active || editable)" :show-arrow="hasEditRoles && !readOnly && (editable || (active && vModel.length === 0))"
:disabled="readOnly" :open="isOpen && (active || editable)"
:class="{ '!ml-[-8px]': readOnly, 'caret-transparent': !hasEditRoles }" @update:open="isOpen = $event"
:dropdown-class-name="`nc-dropdown-multi-select-cell ${isOpen ? 'active' : ''}`" :disabled="readOnly"
@search="search" :class="{ '!ml-[-8px]': readOnly, 'caret-transparent': !hasEditRoles }"
@keydown.stop :dropdown-class-name="`nc-dropdown-multi-select-cell ${isOpen ? 'active' : ''}`"
@click="isOpen = editAllowed && !isOpen" @search="search"
> @keydown.stop
<a-select-option
v-for="op of options"
:key="op.id || op.title"
:value="op.title"
:data-testid="`select-option-${column.title}-${rowIndex}`"
@click.stop
> >
<a-tag class="rounded-tag" :color="op.color"> <a-select-option
v-for="op of options"
:key="op.id || op.title"
:value="op.title"
:data-testid="`select-option-${column.title}-${rowIndex}`"
@click.stop
>
<a-tag class="rounded-tag" :color="op.color">
<span <span
:style="{ :style="{
'color': tinycolor.isReadable(op.color || '#ccc', '#fff', { level: 'AA', size: 'large' }) 'color': tinycolor.isReadable(op.color || '#ccc', '#fff', { level: 'AA', size: 'large' })
@ -313,33 +314,33 @@ const onTagClick = (e: Event, onClose: Function) => {
> >
{{ op.title }} {{ op.title }}
</span> </span>
</a-tag> </a-tag>
</a-select-option> </a-select-option>
<a-select-option <a-select-option
v-if="searchVal && isOptionMissing && !isPublic && (hasRole('owner', true) || hasRole('creator', true))" v-if="searchVal && isOptionMissing && !isPublic && (hasRole('owner', true) || hasRole('creator', true))"
:key="searchVal" :key="searchVal"
:value="searchVal" :value="searchVal"
>
<div class="flex gap-2 text-gray-500 items-center h-full">
<MdiPlusThick class="min-w-4" />
<div class="text-xs whitespace-normal">
Create new option named <strong>{{ searchVal }}</strong>
</div>
</div>
</a-select-option>
<template #tagRender="{ value: val, onClose }">
<a-tag
v-if="options.find((el) => el.title === val)"
class="rounded-tag nc-selected-option"
:style="{ display: 'flex', alignItems: 'center' }"
:color="options.find((el) => el.title === val)?.color"
:closable="editAllowed && (active || editable) && (vModel.length > 1 || !column?.rqd)"
:close-icon="h(MdiCloseCircle, { class: ['ms-close-icon'] })"
@click="onTagClick($event, onClose)"
@close="onClose"
> >
<div class="flex gap-2 text-gray-500 items-center h-full">
<MdiPlusThick class="min-w-4" />
<div class="text-xs whitespace-normal">
Create new option named <strong>{{ searchVal }}</strong>
</div>
</div>
</a-select-option>
<template #tagRender="{ value: val, onClose }">
<a-tag
v-if="options.find((el) => el.title === val)"
class="rounded-tag nc-selected-option"
:style="{ display: 'flex', alignItems: 'center' }"
:color="options.find((el) => el.title === val)?.color"
:closable="editAllowed && (active || editable) && (vModel.length > 1 || !column?.rqd)"
:close-icon="h(MdiCloseCircle, { class: ['ms-close-icon'] })"
@click="onTagClick($event, onClose)"
@close="onClose"
>
<span <span
:style="{ :style="{
'color': tinycolor.isReadable(options.find((el) => el.title === val)?.color || '#ccc', '#fff', { 'color': tinycolor.isReadable(options.find((el) => el.title === val)?.color || '#ccc', '#fff', {
@ -356,9 +357,10 @@ const onTagClick = (e: Event, onClose: Function) => {
> >
{{ val }} {{ val }}
</span> </span>
</a-tag> </a-tag>
</template> </template>
</a-select> </a-select>
</div>
</template> </template>
<style scoped> <style scoped>

Loading…
Cancel
Save