Skip to content

Commit 14badbb

Browse files
committed
added error handling for ScreenIdentifiers
1 parent 127ee72 commit 14badbb

6 files changed

Lines changed: 91 additions & 16 deletions

File tree

src/components/IdentifierCardEditing.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
import { IdentifierTypeType } from '../types'
9292
import { computed, defineComponent, onMounted, PropType, ref } from 'vue'
9393
import SchemaGuideLink from 'src/components/SchemaGuideLink.vue'
94+
import { byError, identifierValueQueries } from 'src/error-filtering'
95+
import { useValidation } from 'src/store/validation'
9496
9597
export default defineComponent({
9698
name: 'IdentifierCardEditing',
@@ -120,6 +122,7 @@ export default defineComponent({
120122
SchemaGuideLink
121123
},
122124
setup (props) {
125+
const { errors } = useValidation()
123126
const linkInfo = {
124127
doi: { label: 'DOI', anchor: '#definitionsdoi' },
125128
url: { label: 'URL', anchor: '#definitionsurl' },
@@ -134,8 +137,9 @@ export default defineComponent({
134137
valueRef.value?.focus()
135138
})
136139
const identifierValueErrors = computed(() => {
137-
console.log(props.type)
138-
return ['asdasd']
140+
return identifierValueQueries(props.index, ['doi', 'url', 'swh', 'other'].indexOf(props.type))
141+
.filter(byError(errors.value))
142+
.map(query => query.replace.message)
139143
})
140144
return {
141145
valueRef,

src/components/IdentifierCardViewing.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<q-card
33
bordered
4-
v-bind:class="['bg-formcard', false ? 'red-border' : '']"
4+
v-bind:class="['bg-formcard', identifierValueErrors.length > 0 ? 'red-border has-error' : '']"
55
flat
66
style="display: flex; flex-direction: row"
77
>
@@ -42,8 +42,10 @@
4242
</template>
4343

4444
<script lang="ts">
45-
import { defineComponent, PropType } from 'vue'
45+
import { computed, defineComponent, PropType } from 'vue'
4646
import { IdentifierType } from 'src/types'
47+
import { useValidation } from 'src/store/validation'
48+
import { byError, identifierValueQueries } from 'src/error-filtering'
4749
4850
export default defineComponent({
4951
name: 'IdentifierCardViewing',
@@ -61,6 +63,17 @@ export default defineComponent({
6163
default: 0
6264
}
6365
},
66+
setup (props) {
67+
const { errors } = useValidation()
68+
const identifierValueErrors = computed(() => {
69+
return identifierValueQueries(props.index, ['doi', 'url', 'swh', 'other'].indexOf(props.identifier.type))
70+
.filter(byError(errors.value))
71+
.map(query => query.replace.message)
72+
})
73+
return {
74+
identifierValueErrors
75+
}
76+
},
6477
emits: ['editPressed', 'moveDown', 'moveUp']
6578
})
6679
</script>

src/components/ScreenFinishAdvanced.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export default defineComponent({
7171
const { reset: resetCffData } = useCff()
7272
const { reset: resetStepperErrorState } = useStepperErrors()
7373
const { errors } = useValidation()
74-
console.log(errors.value)
7574
return {
7675
isValidCFF: computed(() => errors.value.length === 0),
7776
createAnother: async () => {

src/components/ScreenFinishMinimum.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export default defineComponent({
6767
setup () {
6868
const { setShowAdvanced, navigatePrevious, setStepName } = useApp()
6969
const { errors } = useValidation()
70-
console.log(errors.value)
7170
return {
7271
isValidCFF: computed(() => errors.value.length === 0),
7372
setShowAdvanced,

src/components/ScreenIdentifiers.vue

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
</q-btn>
5858

5959
<q-banner
60-
v-if="false"
61-
class="bg-warning text-negative"
60+
v-if="identifiersErrors.length > 0"
61+
v-bind:class="['bg-warning', 'text-negative', identifiersErrors.length > 0 ? 'has-error' : '']"
6262
>
6363
<div
6464
v-bind:key="index"
65-
v-for="(screenMessage, index) in []"
65+
v-for="(screenMessage, index) in identifiersErrors"
6666
>
6767
{{ screenMessage }}
6868
</div>
@@ -76,7 +76,7 @@
7676
</template>
7777

7878
<script lang="ts">
79-
import { defineComponent, nextTick, onUpdated, ref } from 'vue'
79+
import { computed, defineComponent, nextTick, onUpdated, ref } from 'vue'
8080
import SchemaGuideLink from 'components/SchemaGuideLink.vue'
8181
import Stepper from 'components/Stepper.vue'
8282
import StepperActions from 'components/StepperActions.vue'
@@ -86,6 +86,8 @@ import { IdentifierType, IdentifierTypeType } from 'src/types'
8686
import { useCff } from 'src/store/cff'
8787
import { scrollToBottom } from '../scroll-to-bottom'
8888
import { moveDown, moveUp } from '../updown'
89+
import { useValidation } from 'src/store/validation'
90+
import { byError, identifiersQueries } from 'src/error-filtering'
8991
import { useStepperErrors } from 'src/store/stepper-errors'
9092
9193
export default defineComponent({
@@ -103,6 +105,7 @@ export default defineComponent({
103105
setErrorStateScreenIdentifiers(document.getElementsByClassName('has-error').length > 0)
104106
})
105107
const { identifiers, setIdentifiers } = useCff()
108+
const { errors } = useValidation()
106109
const editingId = ref(-1)
107110
const addIdentifier = async () => {
108111
let newIdentifiers:IdentifierType[]
@@ -175,11 +178,16 @@ export default defineComponent({
175178
editingId.value = editingId.value - 1
176179
}
177180
}
178-
181+
const identifiersErrors = computed(() => {
182+
return identifiersQueries
183+
.filter(byError(errors.value))
184+
.map(query => query.replace.message)
185+
})
179186
return {
180187
addIdentifier,
181188
editingId,
182189
identifiers,
190+
identifiersErrors,
183191
moveIdentifierUp,
184192
moveIdentifierDown,
185193
removeIdentifier,

src/error-filtering.ts

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { ErrorObject } from 'ajv'
22

33
type ErrorQueryFind = {
44
[key: string]: string | undefined
5-
instancePath: string
5+
instancePath?: string | undefined
66
message?: string | undefined
7-
schemaPath: string
7+
schemaPath?: string | undefined
88
}
99
type ErrorQueryReplace = {
1010
message: string
@@ -17,13 +17,14 @@ export type ErrorQuery = {
1717
export const byError = (errors: ErrorObject[]) => {
1818
return (query: ErrorQuery) => {
1919
const matches = (error: ErrorObject) => {
20-
if (query.find.instancePath !== error.instancePath) {
20+
const keys = Object.keys(query.find)
21+
if (keys.includes('instancePath') && query.find.instancePath !== error.instancePath) {
2122
return false
2223
}
23-
if (query.find.schemaPath !== error.schemaPath) {
24+
if (keys.includes('schemaPath') && query.find.schemaPath !== error.schemaPath) {
2425
return false
2526
}
26-
if (Object.keys(query.find).includes('message') && query.find.message !== error.message) {
27+
if (keys.includes('message') && query.find.message !== error.message) {
2728
return false
2829
}
2930
return true
@@ -73,6 +74,57 @@ export const emailQueries = (index: number) => {
7374
}] as ErrorQuery[]
7475
}
7576

77+
export const identifierValueQueries = (index: number, typeIndex: number) => {
78+
return [[
79+
{
80+
find: {
81+
instancePath: `/identifiers/${index}/value`,
82+
schemaPath: '#/definitions/doi/pattern'
83+
},
84+
replace: {
85+
message: 'e.g. \'10.5281/zenodo.1003149\' or \'10.7717/peerj-cs.86\'. Does not include the resolver URL.'
86+
}
87+
},
88+
{
89+
find: {
90+
instancePath: `/identifiers/${index}/value`,
91+
schemaPath: '#/definitions/url/pattern'
92+
},
93+
replace: {
94+
message: 'e.g. \'https://www.example.com\' (http, ftp, sftp hyperlinks are also supported)'
95+
}
96+
},
97+
{
98+
find: {
99+
instancePath: `/identifiers/${index}/value`,
100+
schemaPath: '#/definitions/swh-identifier/pattern'
101+
},
102+
replace: {
103+
message: 'e.g. \'swh:1:rev:309cf2674ee7a0749978cf8265ab91a60aea0f7d\'. Besides \'rev\', other allowed values are: \'snp\', \'rel\', \'dir\', and \'cnt\'.'
104+
}
105+
},
106+
{
107+
find: {
108+
instancePath: `/identifiers/${index}/value`,
109+
schemaPath: '#/anyOf/3/properties/value/minLength'
110+
},
111+
replace: {
112+
message: 'Zero-length identifier values are not allowed. Please type an identifier value or remove the identifier entirely.'
113+
}
114+
}
115+
][typeIndex]] as ErrorQuery[]
116+
}
117+
118+
export const identifiersQueries: ErrorQuery[] = [{
119+
find: {
120+
instancePath: '/identifiers',
121+
schemaPath: '#/properties/identifiers/uniqueItems'
122+
},
123+
replace: {
124+
message: 'There are duplicate identifiers.'
125+
}
126+
}]
127+
76128
export const keywordQueries = (index: number) => {
77129
return [{
78130
find: {

0 commit comments

Comments
 (0)