Skip to content

Commit

Permalink
Fixed UI that showed explicitly deleted class membership when the cla…
Browse files Browse the repository at this point in the history
…ss is restored to the module (but not to the clas). Refs #174
  • Loading branch information
raffazizzi committed Dec 10, 2024
1 parent 1f4377a commit f12026c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/containers/ElementPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 17 additions & 1 deletion src/reducers/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down
33 changes: 3 additions & 30 deletions src/reducers/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions src/reducers/odd/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit f12026c

Please sign in to comment.