Skip to content

Commit

Permalink
#311 fix using of parent and children in SGroupAddToHierarchy, revert…
Browse files Browse the repository at this point in the history
… unnecessary changes in sgforest
  • Loading branch information
tomas-light committed Feb 17, 2021
1 parent 75d9332 commit aef8c61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 2 additions & 6 deletions packages/ketcher-react/src/script/chem/struct/sgforest.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ class SGroupForest {
const childIndex = childs.indexOf(childId)
childs.splice(childIndex, 1)
this.parent.set(childId, id)

if (!this.children.has(id)) {
this.children.set(id, [])
}
this.children.get(id).push(childId)
}

remove(id) {
Expand All @@ -142,7 +137,8 @@ class SGroupForest {
const parentId = this.parent.get(id)
const childs = this.children.get(parentId)
this.children.get(id).forEach(childId => {
this.resetParentLink(childId, parentId)
this.parent.set(childId, parentId)
this.children.get(parentId).push(childId)
})

const i = childs.indexOf(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,27 @@ type Data = {
}

class SGroupAddToHierarchy extends BaseOperation {
private readonly parent?: any
private readonly children?: any
data: Data

constructor(sgroupId?: any, parent?: any, children?: any) {
super(OperationType.S_GROUP_ADD_TO_HIERACHY)
this.data = { sgid: sgroupId, parent, children }
this.parent = parent
this.children = children
}

execute(restruct: Restruct) {
const { sgid, children, parent } = this.data
const { sgid } = this.data

const struct = restruct.molecule
const sgroup = struct.sgroups.get(sgid)
const relations = struct.sGroupForest.insert(sgroup, parent, children)
const relations = struct.sGroupForest.insert(
sgroup,
this.parent,
this.children
)

this.data.parent = relations.parent
this.data.children = relations.children
Expand Down

0 comments on commit aef8c61

Please sign in to comment.