Browse Source

fix(nc-gui): error on clicking custom hue option

pull/7807/head
Ramesh Mane 9 months ago
parent
commit
d68c20cf2e
  1. 10
      packages/nc-gui/components/dashboard/TreeView/ProjectNode.vue
  2. 67
      packages/nc-gui/components/general/BaseColorPicker.vue
  3. 2
      packages/nc-gui/store/bases.ts

10
packages/nc-gui/components/dashboard/TreeView/ProjectNode.vue

@ -235,7 +235,7 @@ async function addNewProjectChildEntity() {
isAddNewProjectChildEntityLoading.value = true isAddNewProjectChildEntityLoading.value = true
const isProjectPopulated = basesStore.isProjectPopulated(base.value.id!) const isProjectPopulated = basesStore.isProjectPopulated(base.value.id!)
if (!isProjectPopulated && base.value.type === NcProjectType.DB) { if (!isProjectPopulated && base.value?.type === NcProjectType.DB) {
// We do not wait for tables api, so that add new table is seamless. // We do not wait for tables api, so that add new table is seamless.
// Only con would be while saving table duplicate table name FE validation might not work // Only con would be while saving table duplicate table name FE validation might not work
// If the table list api takes time to load before the table name validation // If the table list api takes time to load before the table name validation
@ -245,7 +245,7 @@ async function addNewProjectChildEntity() {
try { try {
openTableCreateDialog() openTableCreateDialog()
if (!base.value.isExpanded && base.value.type !== NcProjectType.DB) { if (!base.value.isExpanded && base.value?.type !== NcProjectType.DB) {
base.value.isExpanded = true base.value.isExpanded = true
} }
} finally { } finally {
@ -432,11 +432,11 @@ watchEffect(() => {
:key="parseProp(base.meta).iconHue" :key="parseProp(base.meta).iconHue"
:hue="parseProp(base.meta).iconHue" :hue="parseProp(base.meta).iconHue"
size="small" size="small"
:readonly="base.type && base.type !== 'database'" :readonly="base?.type && base?.type !== 'database'"
@color-selected="setColor($event, base)" @color-selected="setColor($event, base)"
> >
<template #default> <template #default>
<GeneralProjectIcon :type="base.type" /> <GeneralProjectIcon :type="base?.type" />
</template> </template>
</LazyGeneralBaseColorPicker> </LazyGeneralBaseColorPicker>
</div> </div>
@ -739,7 +739,7 @@ watchEffect(() => {
</div> </div>
<template v-if="!isSharedBase" #overlay> <template v-if="!isSharedBase" #overlay>
<NcMenu class="!py-0 rounded text-sm"> <NcMenu class="!py-0 rounded text-sm">
<template v-if="contextMenuTarget.type === 'base' && base.type === 'database'"></template> <template v-if="contextMenuTarget.type === 'base' && base?.type === 'database'"></template>
<template v-else-if="contextMenuTarget.type === 'source'"></template> <template v-else-if="contextMenuTarget.type === 'source'"></template>

67
packages/nc-gui/components/general/BaseColorPicker.vue

@ -16,34 +16,25 @@ const emit = defineEmits(['colorSelected'])
const { hue, size = 'medium', readonly } = props const { hue, size = 'medium', readonly } = props
const defaultHueValue = { const defaultHueColor = {
h: 0, h: 0,
s: 0, s: 0,
v: 0, v: 0,
} }
const defaultHueValue = 199
const isOpen = ref(false) const isOpen = ref(false)
const isOpenHuePicker = ref(false) const isOpenHuePicker = ref(false)
const colorRef = ref( const colorRef = ref({
hue !== undefined && hue !== null ...defaultHueColor,
? { h: !(hue !== 0 && !hue) ? hue : defaultHueValue,
...defaultHueValue, })
h: hue,
}
: undefined,
)
function selectColor(value: number | null) { function selectColor(value: number) {
if (value === null) { colorRef.value.h = value
colorRef.value = undefined
} else {
colorRef.value = {
...defaultHueValue,
h: value,
}
}
emit('colorSelected', value) emit('colorSelected', value)
@ -63,13 +54,10 @@ watch(
isOpenHuePicker, isOpenHuePicker,
() => { () => {
if (!isOpenHuePicker.value && colorRef.value?.h !== hue) { if (!isOpenHuePicker.value && colorRef.value?.h !== hue) {
if (isNaN(parseFloat(`${hue}`))) { if (hue !== 0 && !hue) {
colorRef.value = undefined colorRef.value.h = defaultHueValue
} else { } else {
colorRef.value = { colorRef.value.h = hue
...defaultHueValue,
h: hue as number,
}
} }
} }
}, },
@ -91,9 +79,9 @@ watch(
'h-10 w-10 text-2xl': size === 'large', 'h-10 w-10 text-2xl': size === 'large',
'h-14 w-16 text-5xl': size === 'xlarge', 'h-14 w-16 text-5xl': size === 'xlarge',
}" }"
@click="onClick" @click.stop="onClick"
> >
<template v-if="hue === undefined || hue === null"> <template v-if="hue !== 0 && !hue">
<slot name="default" /> <slot name="default" />
</template> </template>
<template v-else> <template v-else>
@ -116,11 +104,11 @@ watch(
d="M638.951 291.265L936.342 462.949C966.129 480.145 980.256 502.958 978.723 525.482V774.266C980.256 796.789 966.129 819.602 936.342 836.798L638.951 1008.48C582.292 1041.19 490.431 1041.19 433.773 1008.48L136.381 836.798C106.595 819.602 92.4675 796.789 93.9999 774.266L93.9999 525.482C92.4675 502.957 106.595 480.145 136.381 462.949L433.773 291.265C490.431 258.556 582.292 258.556 638.951 291.265Z" d="M638.951 291.265L936.342 462.949C966.129 480.145 980.256 502.958 978.723 525.482V774.266C980.256 796.789 966.129 819.602 936.342 836.798L638.951 1008.48C582.292 1041.19 490.431 1041.19 433.773 1008.48L136.381 836.798C106.595 819.602 92.4675 796.789 93.9999 774.266L93.9999 525.482C92.4675 502.957 106.595 480.145 136.381 462.949L433.773 291.265C490.431 258.556 582.292 258.556 638.951 291.265Z"
:fill=" :fill="
tinycolor( tinycolor(
preDefinedHueData[`_${colorRef?.h}`] preDefinedHueData && preDefinedHueData[`_${colorRef?.h}`]
? `hsv(${preDefinedHueData[`_${colorRef?.h}`].shade.h},${preDefinedHueData[`_${colorRef?.h}`].shade.s}%, ${ ? `hsv(${preDefinedHueData[`_${colorRef?.h}`].shade.h},${preDefinedHueData[`_${colorRef?.h}`].shade.s}%, ${
preDefinedHueData[`_${colorRef?.h}`].shade.v preDefinedHueData[`_${colorRef?.h}`].shade.v
}%)` }%)`
: `hsv(${colorRef?.h || 'none'}, 100%, 30%)`, : `hsv(${colorRef?.h ?? defaultHueValue}, 100%, 30%)`,
).toHexString() ).toHexString()
" "
/> />
@ -130,11 +118,11 @@ watch(
d="M638.951 65.0055L936.342 236.69C966.129 253.886 980.256 276.699 978.723 299.222V548.006C980.256 570.529 966.129 593.343 936.342 610.538L638.951 782.223C582.292 814.931 490.431 814.931 433.773 782.223L136.381 610.538C106.595 593.343 92.4675 570.529 93.9999 548.006L93.9999 299.222C92.4675 276.699 106.595 253.886 136.381 236.69L433.773 65.0055C490.431 32.2968 582.292 32.2968 638.951 65.0055Z" d="M638.951 65.0055L936.342 236.69C966.129 253.886 980.256 276.699 978.723 299.222V548.006C980.256 570.529 966.129 593.343 936.342 610.538L638.951 782.223C582.292 814.931 490.431 814.931 433.773 782.223L136.381 610.538C106.595 593.343 92.4675 570.529 93.9999 548.006L93.9999 299.222C92.4675 276.699 106.595 253.886 136.381 236.69L433.773 65.0055C490.431 32.2968 582.292 32.2968 638.951 65.0055Z"
:fill=" :fill="
tinycolor( tinycolor(
preDefinedHueData[`_${colorRef?.h}`] preDefinedHueData && preDefinedHueData[`_${colorRef?.h}`]
? `hsv(${preDefinedHueData[`_${colorRef?.h}`].tint.h},${preDefinedHueData[`_${colorRef?.h}`].tint.s}%, ${ ? `hsv(${preDefinedHueData[`_${colorRef?.h}`].tint.h},${preDefinedHueData[`_${colorRef?.h}`].tint.s}%, ${
preDefinedHueData[`_${colorRef?.h}`].tint.v preDefinedHueData[`_${colorRef?.h}`].tint.v
}%)` }%)`
: `hsv(${colorRef?.h || 'none'}, 30%, 100%)`, : `hsv(${colorRef?.h ?? defaultHueValue}, 30%, 100%)`,
).toHexString() ).toHexString()
" "
/> />
@ -156,7 +144,7 @@ watch(
<div <div
class="rounded h-6 w-6" class="rounded h-6 w-6"
:class="{ :class="{
selected: preDefinedHueData[h].tint.h === hue || (h === '_199' && (hue === undefined || hue === null)), selected: preDefinedHueData[h].tint.h === hue || (h === '_199' && hue !== 0 && !hue),
}" }"
:style="{ :style="{
backgroundColor: preDefinedHueData[h].pickerColor, backgroundColor: preDefinedHueData[h].pickerColor,
@ -192,28 +180,27 @@ watch(
</div> </div>
<template #overlay> <template #overlay>
<div class="relative bg-white rounded-lg p-3 border-1 border-gray-200 shadow-lg flex flex-col space-y-4"> <div class="relative bg-white rounded-lg p-3 border-1 border-gray-200 shadow-lg flex flex-col space-y-4">
<div class="text-sm font-semibold">{{ $t('labels.customHue') }}</div> <div>{{ $t('labels.customHue') }}</div>
<Slider <Slider
:model-value="colorRef" :model-value="colorRef"
class="nc-hue-color-picker" class="nc-hue-color-picker"
:style="{ :style="{
['--nc-hue-slider-pointer-color']: tinycolor(`hsv(${colorRef?.h}, 100%, 100%)`).toHexString(), ['--nc-hue-slider-pointer-color']: tinycolor(
`hsv(${colorRef?.h ?? defaultHueValue}, 100%, 100%)`,
).toHexString(),
}" }"
:disable-fields="true"
@update:model-value=" @update:model-value="
(value) => { (value) => {
if (value?.hsv?.h === undefined) return if (!value?.hsv?.h) return
colorRef = {
...defaultHueValue, colorRef.h = value.hsv.h
h: +value.hsv.h,
}
} }
" "
/> />
<div class="flex items-center justify-end"> <div class="flex items-center justify-end">
<NcButton type="secondary" size="small" @click="selectColor(colorRef?.h || 0)"> <NcButton type="secondary" size="small" @click="selectColor(colorRef?.h ?? defaultHueValue)">
{{ $t('general.apply') }} {{ $t('general.apply') }}
</NcButton> </NcButton>
</div> </div>

2
packages/nc-gui/store/bases.ts

@ -229,7 +229,7 @@ export const useBases = defineStore('basesStore', () => {
...baseUpdatePayload, ...baseUpdatePayload,
} }
bases.value.set(baseId, base) bases.value.set(baseId, { ...base, meta: parseProp(base.meta) })
await api.base.update(baseId, baseUpdatePayload) await api.base.update(baseId, baseUpdatePayload)

Loading…
Cancel
Save