fix: Properly handle adding new tags through multiselect

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2023-11-13 15:54:20 +01:00
parent bb51988ddb
commit 488cdbcd93
3 changed files with 12 additions and 22 deletions

View File

@@ -172,13 +172,14 @@ export default {
}, },
async addLabelToBoardAndCard(name) { async addLabelToBoardAndCard(name) {
await this.$store.dispatch('addLabelToCurrentBoardAndCard', { const newLabel = await this.$store.dispatch('addLabelToCurrentBoardAndCard', {
card: this.copiedCard, card: this.copiedCard,
newLabel: { newLabel: {
title: name, title: name,
color: this.randomColor(), color: this.randomColor(),
}, },
}) })
this.copiedCard.labels.push(newLabel)
}, },
removeLabelFromCard(removedLabel) { removeLabelFromCard(removedLabel) {

View File

@@ -12,13 +12,19 @@
:taggable="true" :taggable="true"
label="title" label="title"
track-by="id" track-by="id"
tag-position="bottom"
@select="onSelect" @select="onSelect"
@remove="onRemove" @remove="onRemove"
@tag="onNewTag"> @tag="onNewTag">
<template #option="scope"> <template #option="scope">
<div :style="{ backgroundColor: '#' + scope.option.color, color: textColor(scope.option.color)}" class="tag"> <div v-if="!scope.option?.isTag" :style="{ backgroundColor: '#' + scope.option.color, color: textColor(scope.option.color)}" class="tag">
{{ scope.option.title }} {{ scope.option.title }}
</div> </div>
<div v-else>
{{ t('deck', 'Create a new tag:') }} <div class="tag">
{{ scope.option.label }}
</div>
</div>
</template> </template>
<template #tag="scope"> <template #tag="scope">
<div :style="{ backgroundColor: '#' + scope.option.color, color: textColor(scope.option.color)}" class="tag"> <div :style="{ backgroundColor: '#' + scope.option.color, color: textColor(scope.option.color)}" class="tag">
@@ -52,32 +58,15 @@ export default {
default: false, default: false,
}, },
}, },
data() {
return {
assignedLabels: null,
}
},
computed: { computed: {
labelsSorted() { labelsSorted() {
return [...this.labels].sort((a, b) => (a.title < b.title) ? -1 : 1) return [...this.labels].sort((a, b) => (a.title < b.title) ? -1 : 1)
}, },
}, assignedLabels() {
watch: { return [...this.card.labels].local((a, b) => (a.title < b.title) ? -1 : 1)
card() {
this.initialize()
}, },
}, },
mounted() {
this.initialize()
},
methods: { methods: {
async initialize() {
if (!this.card) {
return
}
this.assignedLabels = [...this.card.labels].sort((a, b) => (a.title < b.title) ? -1 : 1)
},
onSelect(newLabel) { onSelect(newLabel) {
this.$emit('select', newLabel) this.$emit('select', newLabel)
}, },

View File

@@ -25,7 +25,7 @@ import chroma from 'chroma-js'
export default { export default {
methods: { methods: {
textColor(hex) { textColor(hex) {
return chroma(hex).get('lab.l') > 50 ? '#000000' : '#ffffff' return chroma(hex ?? 'ffffff').get('lab.l') > 50 ? '#000000' : '#ffffff'
}, },
colorIsValid(hex) { colorIsValid(hex) {
const re = /[A-Fa-f0-9]{6}/ const re = /[A-Fa-f0-9]{6}/