diff --git a/src/containers/ElementPage.js b/src/containers/ElementPage.js index 0ed15e5..29e23bf 100644 --- a/src/containers/ElementPage.js +++ b/src/containers/ElementPage.js @@ -5,6 +5,7 @@ import { deleteElementModelClass, discardChanges, revertToSource } from '../acti import { clearPicker } from '../actions/interface' const mapStateToProps = (state, ownProps) => { + console.log('h') let element = {} let success = false if (state.odd.customization && state.odd.localsource) { diff --git a/src/reducers/classes.js b/src/reducers/classes.js index 29da26e..7809c7f 100644 --- a/src/reducers/classes.js +++ b/src/reducers/classes.js @@ -8,6 +8,10 @@ import { DISCARD_CLASS_CHANGES, REVERT_CLASS_TO_SOURCE } from '../actions/classes' +import { ODDCache } from './odd/utils' +import safeSelect from '../utils/safeSelect' + +const oddCache = new ODDCache() // TODO: this function can be shared with elements.js function markChange(member, whatChanged) { @@ -229,7 +233,19 @@ export function oddClasses(state, action) { if (isMember) { customClass = allCustomClasses.filter(c => (c.ident === localClass.ident))[0] if (customClass) { - addClass(customClass, action.className, type) + // Check the ODD: if the class is explicitly removed by the customization, do not restore it. + oddCache.setup(state.customization.xml) + const classSpec = safeSelect(oddCache.odd.querySelectorAll(`schemaSpec > classSpec[ident='${customClass.ident}'][mode='change'], specGrp > classSpec[ident='${customClass.ident}'][mode='change']`))[0] + if (classSpec) { + const memberOf = classSpec.querySelector(`classes > memberOf[key='${action.className}']`) + if (memberOf) { + // Only restore class if the class from customization ODD is a member. + addClass(customClass, action.className, type) + } + } else { + // If the customization ODD doesn't have a classSpec for this class, we're good to go. + addClass(customClass, action.className, type) + } } } } diff --git a/src/reducers/modules.js b/src/reducers/modules.js index 534382b..aefdfc4 100644 --- a/src/reducers/modules.js +++ b/src/reducers/modules.js @@ -2,34 +2,7 @@ import { INCLUDE_MODULES, EXCLUDE_MODULES, INCLUDE_ELEMENTS, EXCLUDE_ELEMENTS, INCLUDE_CLASSES, EXCLUDE_CLASSES, INCLUDE_DATATYPES, EXCLUDE_DATATYPES } from '../actions/modules' import { clone } from '../utils/clone' -import { isMemberExplicitlyDeleted } from './odd/utils' - -class ODDCache { - // A Cache for a parsed ODD document that gets instanced if any of these reducers need to - // look at the ODD XML specifically. - setParser() { - this.parser = new DOMParser() - } - - parseODD(odd) { - this.stringOdd = odd - this.odd = this.parser.parseFromString(odd, 'text/xml') - if (global.uselocaldom) { - // switch from browser to local DOM - this.odd = global.uselocaldom(this.odd) - } - } - - setup(odd) { - // parse odd if necessary - if (!this.odd || this.stringOdd !== odd) { - if (!this.parser) { - this.setParser() - } - this.parseODD(odd) - } - } -} +import { isMemberExplicitlyDeleted, ODDCache } from './odd/utils' const oddCache = new ODDCache() @@ -178,16 +151,16 @@ export function oddModules(state, action) { } return Object.assign(state, {customization: customizationObj}) case INCLUDE_CLASSES: - console.log(localsource) for (const cl of action.classes) { const localCl = getClassByIdent(localsource, cl, action.classType) const newCl = clone(localCl) newCl._changed = ['included'] + // Add class to customization as long as it's not already there if (!getClassByIdent(customization, cl, action.classType)) { newCl.cloned = true customization.classes[action.classType].push(newCl) } - // Make sure only references to classes that are not explicitly removed + // Make sure the newly included class is only member of classes that are not explicitly removed // Need to look at XML ODD because some classes may have been orphaned // and ZAPped (dropped) during ODD compilation. if (newCl.classes) { diff --git a/src/reducers/odd/utils.js b/src/reducers/odd/utils.js index 5eca124..a8f59ff 100644 --- a/src/reducers/odd/utils.js +++ b/src/reducers/odd/utils.js @@ -70,3 +70,30 @@ export function isMemberExplicitlyDeleted(odd, ident, type, module) { // at this point we assume that if there's no moduleRef, that counts as being explicitly excluded. return true } + +export class ODDCache { + // A Cache for a parsed ODD document that gets instanced if any of these reducers need to + // look at the ODD XML specifically. + setParser() { + this.parser = new DOMParser() + } + + parseODD(odd) { + this.stringOdd = odd + this.odd = this.parser.parseFromString(odd, 'text/xml') + if (global.uselocaldom) { + // switch from browser to local DOM + this.odd = global.uselocaldom(this.odd) + } + } + + setup(odd) { + // parse odd if necessary + if (!this.odd || this.stringOdd !== odd) { + if (!this.parser) { + this.setParser() + } + this.parseODD(odd) + } + } +}