Skip to content

Commit

Permalink
Deleting a mapping should clear the is-mapped indicator (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Jun 25, 2020
1 parent 9f1509c commit 79e8e34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/mixins/cdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ export default {
this.$set(concept, "__MAPPED__", [])
}
const existing = concept.__MAPPED__.find(item => jskos.compare(item.registry, registry) && jskos.compare(item.scheme, targetScheme))
if (existing && !existing.exist) {
existing.exist = true
if (existing && !existing.exist.length) {
existing.exist.push(mapping.uri)
} else if (!existing) {
concept.__MAPPED__.push({
registry,
scheme: targetScheme,
exist: true,
exist: [mapping.uri],
})
}
}
Expand Down Expand Up @@ -812,6 +812,22 @@ export default {
// Set original to null
this.$store.commit({ type: "mapping/set" })
}
// 3. Adjust __MAPPED__ property of conceps in mapping
if (jskos.mappingRegistryIsStored(registry)) {
for (let [from, to] of [["from", "to"], ["to", "from"]]) {
const targetScheme = mapping[`${to}Scheme`]
const sourceConcepts = jskos.conceptsOfMapping(mapping, from)
if (targetScheme) {
for (let concept of sourceConcepts) {
const existing = (concept.__MAPPED__ || []).find(item => jskos.compare(item.registry, registry) && jskos.compare(item.scheme, targetScheme))
if (!existing || !existing.exist.length) {
continue
}
this.$set(existing, "exist", existing.exist.filter(uri => uri != mapping.uri))
}
}
}
}
},
canCreateMapping({ registry, mapping, user = this.user }) {
if (!mapping || !registry) {
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/mapped-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default {
concept.__MAPPED__.push({
registry,
scheme: otherScheme,
exist: false,
exist: [],
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const getters = {
* Returns the mapped status for a concept.
*/
mappedStatus: (state) => (concept, isLeft) => {
return !!_.get(concept, "__MAPPED__", []).find(item => item.exist && jskos.compare(item.registry, getters.getCurrentRegistry(state)) && jskos.compare(item.scheme, state.selected.scheme[!isLeft]))
return !!_.get(concept, "__MAPPED__", []).find(item => item.exist.length && jskos.compare(item.registry, getters.getCurrentRegistry(state)) && jskos.compare(item.scheme, state.selected.scheme[!isLeft]))
},
languages: (state) => {
const defaultLanguages = ["en", "de"]
Expand Down

0 comments on commit 79e8e34

Please sign in to comment.