Skip to content

Commit d29975f

Browse files
committed
added error message for when there are duplicate keywords
1 parent 0c19ad6 commit d29975f

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/components/ScreenKeywords.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
</q-btn>
4343

4444
<q-banner
45-
v-if="false"
46-
class="bg-warning text-negative"
45+
v-if="keywordsErrors.length > 0"
46+
v-bind:class="['bg-warning', 'text-negative', keywordsErrors.length > 0 ? 'has-error' : '']"
4747
>
4848
<div
4949
v-bind:key="index"
50-
v-for="(screenMessage, index) in []"
50+
v-for="(screenMessage, index) in keywordsErrors"
5151
>
5252
{{ screenMessage }}
5353
</div>
@@ -65,11 +65,13 @@ import SchemaGuideLink from 'components/SchemaGuideLink.vue'
6565
import Stepper from 'components/Stepper.vue'
6666
import StepperActions from 'components/StepperActions.vue'
6767
import Keyword from 'components/Keyword.vue'
68-
import { defineComponent, nextTick, onUpdated } from 'vue'
68+
import { computed, defineComponent, nextTick, onUpdated } from 'vue'
6969
import { moveDown, moveUp } from '../updown'
7070
import { useCff } from '../store/cff'
7171
import { scrollToBottom } from '../scroll-to-bottom'
7272
import { useStepperErrors } from 'src/store/stepper-errors'
73+
import { useValidation } from 'src/store/validation'
74+
import { byError, keywordsQueries } from 'src/error-filtering'
7375
7476
export default defineComponent({
7577
name: 'ScreenKeywords',
@@ -85,6 +87,7 @@ export default defineComponent({
8587
setErrorStateScreenKeywords(document.getElementsByClassName('has-error').length > 0)
8688
})
8789
const { keywords, setKeywords } = useCff()
90+
const { errors } = useValidation()
8891
const addKeyword = async () => {
8992
let newKeywords:string[]
9093
const newKeyword = ''
@@ -115,9 +118,15 @@ export default defineComponent({
115118
setKeywords(newKeywords)
116119
}
117120
}
121+
const keywordsErrors = computed(() => {
122+
return keywordsQueries
123+
.filter(byError(errors.value))
124+
.map(query => query.replace.message)
125+
})
118126
return {
119127
addKeyword,
120128
keywords,
129+
keywordsErrors,
121130
moveDown,
122131
moveUp,
123132
removeKeyword,

src/error-filtering.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ export const keywordQueries = (index: number) => {
137137
}] as ErrorQuery[]
138138
}
139139

140+
export const keywordsQueries: ErrorQuery[] = [{
141+
find: {
142+
instancePath: '/keywords',
143+
schemaPath: '#/properties/keywords/uniqueItems'
144+
},
145+
replace: {
146+
message: 'There are duplicate keywords.'
147+
}
148+
}]
149+
140150
export const messageQueries: ErrorQuery[] = [{
141151
find: {
142152
instancePath: '',

0 commit comments

Comments
 (0)