fix(#6391): refresh object composition before expanding a tree item (#6437)

* fix(#6391): refresh composition on treeItem open

- On treeItem open, gets the latest composition from persistence

- Composition was being refreshed, but only within the same instance (mutables)

* test: regression tests for localStorage and couch

---------

Co-authored-by: Scott Bell <scott@traclabs.com>
This commit is contained in:
Jesse Mazzella 2023-03-15 10:17:48 -07:00 committed by GitHub
parent 817d8da3e4
commit 006fa0bcc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 7 deletions

View File

@ -53,6 +53,52 @@ test.describe('Main Tree', () => {
});
test('Creating a child object on one tab and expanding its parent on the other shows the correct composition @2p', async ({ page, openmctConfig }) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/nasa/openmct/issues/6391'
});
const { myItemsFolderName } = openmctConfig;
const page2 = await page.context().newPage();
// Both pages: Go to baseURL
await Promise.all([
page.goto('./', { waitUntil: 'networkidle' }),
page2.goto('./', { waitUntil: 'networkidle' })
]);
const page1Folder = await createDomainObjectWithDefaults(page, {
type: 'Folder'
});
await expandTreePaneItemByName(page2, myItemsFolderName);
await assertTreeItemIsVisible(page2, page1Folder.name);
});
test('Creating a child object on one tab and expanding its parent on the other shows the correct composition @couchdb @2p', async ({ page, openmctConfig }) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/nasa/openmct/issues/6391'
});
const { myItemsFolderName } = openmctConfig;
const page2 = await page.context().newPage();
// Both pages: Go to baseURL
await Promise.all([
page.goto('./', { waitUntil: 'networkidle' }),
page2.goto('./', { waitUntil: 'networkidle' })
]);
const page1Folder = await createDomainObjectWithDefaults(page, {
type: 'Folder'
});
await expandTreePaneItemByName(page2, myItemsFolderName);
await assertTreeItemIsVisible(page2, page1Folder.name);
});
test('Renaming an object reorders the tree @unstable', async ({ page, openmctConfig }) => {
const { myItemsFolderName } = openmctConfig;

View File

@ -304,8 +304,7 @@ export default {
}
// will need to listen for root composition changes as well
this.treeItems = await this.loadAndBuildTreeItemsFor(root, []);
this.treeItems = await this.loadAndBuildTreeItemsFor(root.identifier, []);
},
treeItemAction(parentItem, type) {
if (type === 'close') {
@ -322,12 +321,12 @@ export default {
this.$emit('tree-item-selection', item);
},
async openTreeItem(parentItem) {
let parentPath = parentItem.navigationPath;
const parentPath = parentItem.navigationPath;
this.startItemLoad(parentPath);
// pass in abort signal when functional
let childrenItems = await this.loadAndBuildTreeItemsFor(parentItem.object, parentItem.objectPath);
let parentIndex = this.treeItems.indexOf(parentItem);
const childrenItems = await this.loadAndBuildTreeItemsFor(parentItem.object.identifier, parentItem.objectPath);
const parentIndex = this.treeItems.indexOf(parentItem);
// if it's not loading, it was aborted
if (!this.isItemLoading(parentPath) || parentIndex === -1) {
@ -558,8 +557,10 @@ export default {
// determine if any part of the parent's path includes a key value of mine; aka My Items
return Boolean(parentObjectPath.find(path => path.identifier.key === 'mine'));
},
async loadAndBuildTreeItemsFor(domainObject, parentObjectPath, abortSignal) {
let collection = this.openmct.composition.get(domainObject);
async loadAndBuildTreeItemsFor(identifier, parentObjectPath, abortSignal) {
const domainObject = await this.openmct.objects.get(identifier);
const collection = this.openmct.composition.get(domainObject);
let composition = await collection.load(abortSignal);
if (SORT_MY_ITEMS_ALPH_ASC && this.isSortable(parentObjectPath)) {