Browse Source

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

pull/7807/head
Ramesh Mane 7 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
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.
// 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
@ -245,7 +245,7 @@ async function addNewProjectChildEntity() {
try {
openTableCreateDialog()
if (!base.value.isExpanded && base.value.type !== NcProjectType.DB) {
if (!base.value.isExpanded && base.value?.type !== NcProjectType.DB) {
base.value.isExpanded = true
}
} finally {
@ -432,11 +432,11 @@ watchEffect(() => {
:key="parseProp(base.meta).iconHue"
:hue="parseProp(base.meta).iconHue"
size="small"
:readonly="base.type && base.type !== 'database'"
:readonly="base?.type && base?.type !== 'database'"
@color-selected="setColor($event, base)"
>
<template #default>
<GeneralProjectIcon :type="base.type" />
<GeneralProjectIcon :type="base?.type" />
</template>
</LazyGeneralBaseColorPicker>
</div>
@ -739,7 +739,7 @@ watchEffect(() => {
</div>
<template v-if="!isSharedBase" #overlay>
<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>

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

@ -16,34 +16,25 @@ const emit = defineEmits(['colorSelected'])
const { hue, size = 'medium', readonly } = props
const defaultHueValue = {
const defaultHueColor = {
h: 0,
s: 0,
v: 0,
}
const defaultHueValue = 199
const isOpen = ref(false)
const isOpenHuePicker = ref(false)
const colorRef = ref(
hue !== undefined && hue !== null
? {
...defaultHueValue,
h: hue,
}
: undefined,
)
const colorRef = ref({
...defaultHueColor,
h: !(hue !== 0 && !hue) ? hue : defaultHueValue,
})
function selectColor(value: number | null) {
if (value === null) {
colorRef.value = undefined
} else {
colorRef.value = {
...defaultHueValue,
h: value,
}
}
function selectColor(value: number) {
colorRef.value.h = value
emit('colorSelected', value)
@ -63,13 +54,10 @@ watch(
isOpenHuePicker,
() => {
if (!isOpenHuePicker.value && colorRef.value?.h !== hue) {
if (isNaN(parseFloat(`${hue}`))) {
colorRef.value = undefined
if (hue !== 0 && !hue) {
colorRef.value.h = defaultHueValue
} else {
colorRef.value = {
...defaultHueValue,
h: hue as number,
}
colorRef.value.h = hue
}
}
},
@ -91,9 +79,9 @@ watch(
'h-10 w-10 text-2xl': size === 'large',
'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" />
</template>
<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"
:fill="
tinycolor(
preDefinedHueData[`_${colorRef?.h}`]
preDefinedHueData && preDefinedHueData[`_${colorRef?.h}`]
? `hsv(${preDefinedHueData[`_${colorRef?.h}`].shade.h},${preDefinedHueData[`_${colorRef?.h}`].shade.s}%, ${
preDefinedHueData[`_${colorRef?.h}`].shade.v
}%)`
: `hsv(${colorRef?.h || 'none'}, 100%, 30%)`,
: `hsv(${colorRef?.h ?? defaultHueValue}, 100%, 30%)`,
).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"
:fill="
tinycolor(
preDefinedHueData[`_${colorRef?.h}`]
preDefinedHueData && preDefinedHueData[`_${colorRef?.h}`]
? `hsv(${preDefinedHueData[`_${colorRef?.h}`].tint.h},${preDefinedHueData[`_${colorRef?.h}`].tint.s}%, ${
preDefinedHueData[`_${colorRef?.h}`].tint.v
}%)`
: `hsv(${colorRef?.h || 'none'}, 30%, 100%)`,
: `hsv(${colorRef?.h ?? defaultHueValue}, 30%, 100%)`,
).toHexString()
"
/>
@ -156,7 +144,7 @@ watch(
<div
class="rounded h-6 w-6"
: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="{
backgroundColor: preDefinedHueData[h].pickerColor,
@ -192,28 +180,27 @@ watch(
</div>
<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="text-sm font-semibold">{{ $t('labels.customHue') }}</div>
<div>{{ $t('labels.customHue') }}</div>
<Slider
:model-value="colorRef"
class="nc-hue-color-picker"
: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="
(value) => {
if (value?.hsv?.h === undefined) return
colorRef = {
...defaultHueValue,
h: +value.hsv.h,
}
if (!value?.hsv?.h) return
colorRef.h = value.hsv.h
}
"
/>
<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') }}
</NcButton>
</div>

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

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

Loading…
Cancel
Save