From 006fa0bcc7399e039bf067f7f738cdca25299cb6 Mon Sep 17 00:00:00 2001 From: Jesse Mazzella Date: Wed, 15 Mar 2023 10:17:48 -0700 Subject: [PATCH] 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 --- e2e/tests/functional/tree.e2e.spec.js | 46 +++++++++++++++++++++++++++ src/ui/layout/mct-tree.vue | 15 +++++---- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/e2e/tests/functional/tree.e2e.spec.js b/e2e/tests/functional/tree.e2e.spec.js index b4e7ce13e9..d1020f9512 100644 --- a/e2e/tests/functional/tree.e2e.spec.js +++ b/e2e/tests/functional/tree.e2e.spec.js @@ -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; diff --git a/src/ui/layout/mct-tree.vue b/src/ui/layout/mct-tree.vue index 2ecb689c33..2314f68337 100644 --- a/src/ui/layout/mct-tree.vue +++ b/src/ui/layout/mct-tree.vue @@ -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)) {