diff --git a/src/containers/EditAttributes.js b/src/containers/EditAttributes.js index 6de5586..a30346c 100644 --- a/src/containers/EditAttributes.js +++ b/src/containers/EditAttributes.js @@ -82,6 +82,7 @@ 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]) { @@ -89,6 +90,30 @@ const mapStateToProps = (state, ownProps) => { 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) { diff --git a/src/reducers/elements.js b/src/reducers/elements.js index 862a9d2..639718e 100644 --- a/src/reducers/elements.js +++ b/src/reducers/elements.js @@ -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') }