Skip to content

Commit 7625096

Browse files
committed
Add resolving labels to enum select editor
1 parent 70acf75 commit 7625096

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/components/ShaclForm/Editor/EnumSelectEditor.vue

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
- select -
99
</option>
1010
<option
11-
v-for="option in createOptions()"
12-
:key="option.key"
13-
:value="option.key"
11+
v-for="key in keys"
12+
:key="key"
13+
:value="key"
1414
>
15-
{{ option.value }}
15+
{{ values[key] }}
1616
</option>
1717
</select>
1818
</template>
@@ -21,6 +21,8 @@ import * as $rdf from 'rdflib'
2121
import _ from 'lodash'
2222
import { Component, Prop, Vue } from 'vue-property-decorator'
2323
import rdfUtils from '@/rdf/utils'
24+
import api from '@/api'
25+
import { SHACL } from '@/rdf/namespaces'
2426
2527
@Component({})
2628
export default class EnumSelectEditor extends Vue {
@@ -30,11 +32,30 @@ export default class EnumSelectEditor extends Vue {
3032
@Prop({ required: true })
3133
readonly value: any
3234
33-
createOptions() {
34-
return _.get(this.field, 'in', []).map((val) => ({
35-
key: val,
36-
value: rdfUtils.pathTerm(val),
37-
}))
35+
keys : any
36+
37+
values : any
38+
39+
created(): void {
40+
this.keys = []
41+
this.values = {}
42+
43+
_.get(this.field, 'in', []).forEach((key) => {
44+
this.keys.push(key)
45+
this.values[key] = rdfUtils.pathTerm(key)
46+
47+
if (this.field.nodeKind === SHACL('IRI').value) {
48+
this.resolveValue(key)
49+
}
50+
})
51+
}
52+
53+
async resolveValue(key: string): Promise<void> {
54+
try {
55+
this.values[key] = await api.label.getLabel(key)
56+
} catch {
57+
// nothing could be fetched, keep default label
58+
}
3859
}
3960
4061
onInput(e) {

0 commit comments

Comments
 (0)