Skip to content

Commit 9a421f8

Browse files
committed
fix: check tag while renaming
Signed-off-by: Roberto Guido <info@madbob.org>
1 parent a240cdf commit 9a421f8

2 files changed

Lines changed: 17 additions & 51 deletions

File tree

src/components/TagItem.vue

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@
6363
</template>
6464

6565
<script>
66-
import { showInfo } from '@nextcloud/dialogs'
66+
import { showError, showInfo } from '@nextcloud/dialogs'
6767
import { NcActionInput as ActionInput, NcActions as Actions, NcActionText as ActionText, NcLoadingIcon as IconLoading, NcActionButton, NcColorPicker } from '@nextcloud/vue'
6868
import { mapStores } from 'pinia'
6969
import IconEdit from 'vue-material-design-icons/PencilOutline.vue'
7070
import DeleteIcon from 'vue-material-design-icons/TrashCanOutline.vue'
7171
import logger from '../logger.js'
7272
import useMainStore from '../store/mainStore.js'
73+
import { hiddenTags } from './tags.js'
7374
import { translateTagDisplayName } from '../util/tag.js'
7475
7576
export default {
@@ -151,19 +152,29 @@ export default {
151152
},
152153
153154
async renameTag(tag, event) {
154-
this.renameTagInput = false
155-
this.showSaving = false
156155
const displayName = event.target.querySelector('input[type=text]').value
156+
if (displayName.toLowerCase() in hiddenTags) {
157+
showError(this.t('mail', 'Tag name is a hidden system tag'))
158+
return
159+
}
160+
if (this.mainStore.getTags.some((tag) => tag.displayName === displayName)) {
161+
showError(this.t('mail', 'Tag already exists'))
162+
return
163+
}
164+
if (displayName.trim() === '') {
165+
showError(this.t('mail', 'Tag name cannot be empty'))
166+
return
167+
}
168+
169+
this.showSaving = false
157170
158171
try {
159172
await this.mainStore.updateTag({
160173
tag,
161174
displayName,
162175
color: this.tag.color,
163176
})
164-
this.renameTagLabel = true
165-
this.renameTagInput = false
166-
this.showSaving = false
177+
this.closeEditTag()
167178
} catch (error) {
168179
showInfo(t('mail', 'An error occurred, unable to rename the tag.'))
169180
logger.error('could not rename tag', { error })

src/components/TagModal.vue

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ export default {
9999
tagLabel: true,
100100
tagInput: false,
101101
showSaving: false,
102-
renameTagLabel: true,
103-
renameTagInput: false,
104102
deleteTagModal: false,
105103
tagToDelete: null,
106104
color: randomColor(),
@@ -188,49 +186,6 @@ export default {
188186
}
189187
},
190188
191-
convertHex(color, opacity) {
192-
if (color.length === 4) {
193-
const r = parseInt(color.substring(1, 2), 16)
194-
const g = parseInt(color.substring(2, 3), 16)
195-
const b = parseInt(color.substring(3, 4), 16)
196-
return `rgba(${r}, ${g}, ${b}, ${opacity})`
197-
} else {
198-
const r = parseInt(color.substring(1, 3), 16)
199-
const g = parseInt(color.substring(3, 5), 16)
200-
const b = parseInt(color.substring(5, 7), 16)
201-
return `rgba(${r}, ${g}, ${b}, ${opacity})`
202-
}
203-
},
204-
205-
openEditTag() {
206-
this.renameTagLabel = false
207-
this.renameTagInput = true
208-
this.showSaving = false
209-
},
210-
211-
async renameTag(tag, event) {
212-
this.renameTagInput = false
213-
this.showSaving = false
214-
const displayName = event.target.querySelector('input[type=text]').value
215-
216-
try {
217-
await this.mainStore.updateTag({
218-
tag,
219-
displayName,
220-
color: tag.color,
221-
})
222-
this.renameTagLabel = true
223-
this.renameTagInput = false
224-
this.showSaving = false
225-
} catch (error) {
226-
showInfo(t('mail', 'An error occurred, unable to rename the tag.'))
227-
logger.error('could not rename tag', { error })
228-
this.renameTagLabel = false
229-
this.renameTagInput = false
230-
this.showSaving = true
231-
}
232-
},
233-
234189
deleteTag(tag) {
235190
this.tagToDelete = tag
236191
this.deleteTagModal = true

0 commit comments

Comments
 (0)