mirror of
https://github.com/nasa/openmct.git
synced 2025-02-21 09:52:04 +00:00
Rename a file tree object trigger an alphabetical reordering (#5187)
* Add observers to domain object and update tree func * Remove unused argument Co-authored-by: Michael Rogers <contact@mhrogers.com>
This commit is contained in:
parent
9568da9d5f
commit
9c8ee09960
@ -174,7 +174,8 @@ export default {
|
||||
itemOffset: 0,
|
||||
activeSearch: false,
|
||||
mainTreeTopMargin: undefined,
|
||||
selectedItem: {}
|
||||
selectedItem: {},
|
||||
observers: {}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@ -275,6 +276,8 @@ export default {
|
||||
if (this.treeResizeObserver) {
|
||||
this.treeResizeObserver.disconnect();
|
||||
}
|
||||
|
||||
this.destroyObservers(this.observers);
|
||||
},
|
||||
methods: {
|
||||
async initialize() {
|
||||
@ -549,6 +552,8 @@ export default {
|
||||
}
|
||||
|
||||
return composition.map((object) => {
|
||||
this.addTreeItemObserver(object, parentObjectPath);
|
||||
|
||||
return this.buildTreeItem(object, parentObjectPath);
|
||||
});
|
||||
},
|
||||
@ -565,6 +570,41 @@ export default {
|
||||
navigationPath
|
||||
};
|
||||
},
|
||||
addTreeItemObserver(domainObject, parentObjectPath) {
|
||||
if (this.observers[domainObject.identifier.key]) {
|
||||
this.observers[domainObject.identifier.key]();
|
||||
}
|
||||
|
||||
this.observers[domainObject.identifier.key] = this.openmct.objects.observe(
|
||||
domainObject,
|
||||
'name',
|
||||
this.updateTreeItems.bind(this, parentObjectPath)
|
||||
);
|
||||
},
|
||||
async updateTreeItems(parentObjectPath) {
|
||||
let children;
|
||||
|
||||
if (parentObjectPath.length) {
|
||||
const parentItem = this.treeItems.find(item => item.objectPath === parentObjectPath);
|
||||
const descendants = this.getChildrenInTreeFor(parentItem, true);
|
||||
const parentIndex = this.treeItems.map(e => e.object).indexOf(parentObjectPath[0]);
|
||||
|
||||
children = await this.loadAndBuildTreeItemsFor(parentItem.object, parentItem.objectPath);
|
||||
|
||||
this.treeItems.splice(parentIndex + 1, descendants.length, ...children);
|
||||
} else {
|
||||
const root = await this.openmct.objects.get('ROOT');
|
||||
children = await this.loadAndBuildTreeItemsFor(root, []);
|
||||
|
||||
this.treeItems = [...children];
|
||||
}
|
||||
|
||||
for (let item of children) {
|
||||
if (this.isTreeItemOpen(item)) {
|
||||
this.openTreeItem(item);
|
||||
}
|
||||
}
|
||||
},
|
||||
buildNavigationPath(objectPath) {
|
||||
return '/browse/' + [...objectPath].reverse()
|
||||
.map((object) => this.openmct.objects.makeKeyString(object.identifier))
|
||||
@ -577,6 +617,8 @@ export default {
|
||||
const descendants = this.getChildrenInTreeFor(parentItem, true);
|
||||
const directDescendants = this.getChildrenInTreeFor(parentItem);
|
||||
|
||||
this.addTreeItemObserver(domainObject, parentItem.objectPath);
|
||||
|
||||
if (directDescendants.length === 0) {
|
||||
this.addItemToTreeAfter(newItem, parentItem);
|
||||
|
||||
@ -611,6 +653,7 @@ export default {
|
||||
let removeItem = directDescendants.find(item => item.id === removeKeyString);
|
||||
|
||||
this.removeItemFromTree(removeItem);
|
||||
this.removeItemFromObservers(removeItem);
|
||||
};
|
||||
},
|
||||
removeCompositionListenerFor(navigationPath) {
|
||||
@ -632,6 +675,13 @@ export default {
|
||||
const removeIndex = this.getTreeItemIndex(item.navigationPath);
|
||||
this.treeItems.splice(removeIndex, 1);
|
||||
},
|
||||
removeItemFromObservers(item) {
|
||||
if (this.observers[item.id]) {
|
||||
this.observers[item.id]();
|
||||
|
||||
delete this.observers[item.id];
|
||||
}
|
||||
},
|
||||
addItemToTreeBefore(addItem, beforeItem) {
|
||||
const addIndex = this.getTreeItemIndex(beforeItem.navigationPath);
|
||||
|
||||
@ -863,6 +913,15 @@ export default {
|
||||
},
|
||||
handleTreeResize() {
|
||||
this.calculateHeights();
|
||||
},
|
||||
destroyObservers(observers) {
|
||||
Object.entries(observers).forEach(([keyString, unobserve]) => {
|
||||
if (typeof unobserve === 'function') {
|
||||
unobserve();
|
||||
}
|
||||
|
||||
delete observers[keyString];
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user