Skip to content

Commit

Permalink
inherited ZAPped classes can noe be explicity deleted from newly rest…
Browse files Browse the repository at this point in the history
…ored elements. Fixes #113
  • Loading branch information
raffazizzi committed Nov 16, 2020
1 parent f621893 commit b04fded
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/containers/EditAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,38 @@ const mapStateToProps = (state, ownProps) => {
deletedAttributesFromClasses = new Set([...deletedAttributesFromClasses, ...curClass.deletedAttributes])
return tempAcc
} else {
// TODO: code is repeated from above. Needs optimization.
// The class requested doesn't appear to be in the customization,
// but if its module is selected, it may have been zapped. So include it.
if (state.odd.localsource.json.modules.filter(m => m.ident === localClass.module)[0]) {
let tempAcc = Array.from(acc)
const curClass = clone(localClass)
curClass.sub = sub
curClass.from = from
curClass.deletedAttributes = new Set()

// Check if a definition in the element overrides or deletes an inherited attribute
for (const att of curClass.attributes) {
const redefinedAtt = element.attributes.filter((a) => (a.ident === att.ident))[0]
if (redefinedAtt) {
att.overridden = false
att.deleted = false
att.mode = redefinedAtt.mode
if (redefinedAtt.mode === 'delete') {
att.deleted = true
curClass.deletedAttributes.add(att.ident)
} else if (redefinedAtt.mode === 'change' || redefinedAtt.mode === 'add') {
curClass.deletedAttributes.delete(att.ident)
if (redefinedAtt._changed === undefined || redefinedAtt._changed.length > 0) {
att.overridden = true
}
}
}
}
if (curClass.deletedAttributes.size >= curClass.attributes.length) {
curClass.inactive = true
}

tempAcc.push(curClass)
// Get inherited classes
if (curClass.classes) {
Expand Down
12 changes: 11 additions & 1 deletion src/reducers/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,17 @@ export function oddElements(state, action) {
deleteAttribute(m, clAtt)
}
} else {
throw new ReducerException(`Could not locate class ${action.className}.`)
// The class must be inherited, but currently not present in the customization
// This may happen the a module has recently been added by the user,
// or via adding an element from a previously unselected module.
const lClass = localsource.classes.attributes.filter(c => (c.ident === action.className))[0]
if (lClass) {
for (const clAtt of lClass.attributes) {
deleteAttribute(m, clAtt)
}
} else {
throw new ReducerException(`Could not locate class ${action.className}.`)
}
}
markChange(m, 'attributes')
}
Expand Down

0 comments on commit b04fded

Please sign in to comment.