Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions QualityControl/public/object/ObjectTree.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import { StorageKeysEnum } from '../common/enums/storageKeys.enum.js';
export default class ObjectTree extends Observable {
static _indexIncrementCount = 0;

/**
* A shared storage instance for open branch states.
* @type {BrowserStorage}
*/
static _openBranchStateStorage = new BrowserStorage(StorageKeysEnum.OBJECT_TREE_OPEN_BRANCH_STATE);

/**
* Instantiate tree with a root node called `name`, empty by default
* @param {string} name - root name
Expand All @@ -32,7 +38,6 @@ export default class ObjectTree extends Observable {
super();
this._index = ObjectTree._indexIncrementCount++;
this.focusedNode = null;
this.openBranchStateStorage = new BrowserStorage(StorageKeysEnum.OBJECT_TREE_OPEN_BRANCH_STATE);
this.initTree(name, parent);
}

Expand Down Expand Up @@ -258,7 +263,7 @@ export default class ObjectTree extends Observable {
const session = sessionService.get();
const key = session.personid.toString();
// We traverse the path to reach the parent branch of this node
let branchState = this.openBranchStateStorage.getLocalItem(key) ?? {};
let branchState = ObjectTree._openBranchStateStorage.getLocalItem(key) ?? {};
for (let i = 0; i < this.path.length - 1; i++) {
branchState = branchState[this.path[i]];
if (!branchState) {
Expand Down Expand Up @@ -299,7 +304,7 @@ export default class ObjectTree extends Observable {
}
const session = sessionService.get();
const key = session.personid.toString();
const data = this.openBranchStateStorage.getLocalItem(key) ?? {};
const data = ObjectTree._openBranchStateStorage.getLocalItem(key) ?? {};
// We traverse the path to reach the parent branch of this node
let branchState = data;
for (let i = 0; i < this.path.length - 1; i++) {
Expand All @@ -317,11 +322,11 @@ export default class ObjectTree extends Observable {
}
if (this.open) {
this._markExpandedBranchesRecursive(branchState, this);
this.openBranchStateStorage.setLocalItem(key, data);
ObjectTree._openBranchStateStorage.setLocalItem(key, data);
} else if (branchState[this.name]) {
// Deleting from `branchState` directly updates the `data` object
delete branchState[this.name];
this.openBranchStateStorage.setLocalItem(key, data);
ObjectTree._openBranchStateStorage.setLocalItem(key, data);
}
}

Expand Down
Loading