Skip to content

Commit

Permalink
For an existing View in a Preview, ensure we pull the same `ActionCol…
Browse files Browse the repository at this point in the history
…lection` (#7632)

* ensure action collection returned is the cached one from the same view

* add test

* use async await
  • Loading branch information
scottbell authored Mar 26, 2024
1 parent 493b31d commit 5391384
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ test.describe('Preview mode', () => {
await page.getByLabel('Overlay').getByLabel('More actions').click();
await expect(page.getByLabel('Export Table Data')).toBeVisible();
await expect(page.getByLabel('Export Marked Rows')).toBeVisible();
await expect(page.getByLabel('Export Marked Rows')).toBeDisabled();
await page.getByLabel('Pause').click();
const tableWrapper = page.getByLabel('Preview Container').locator('div.c-table-wrapper');
await expect(tableWrapper).toHaveClass(/is-paused/);
});
});
24 changes: 3 additions & 21 deletions src/ui/preview/PreviewContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
<div role="dialog" aria-label="Preview Container" class="l-preview-window js-preview-window">
<PreviewHeader
ref="previewHeader"
:current-view="currentViewProvider"
:action-collection="actionCollection"
:current-view="view"
:domain-object="domainObject"
:views="viewProviders"
/>
Expand All @@ -35,8 +34,6 @@
</template>

<script>
import { nextTick } from 'vue';

import StyleRuleManager from '@/plugins/condition/StyleRuleManager';
import { STYLE_CONSTANTS } from '@/plugins/condition/utils/constants';

Expand Down Expand Up @@ -66,10 +63,10 @@ export default {

return {
domainObject: domainObject,
viewKey: undefined,
viewKey: null,
view: null,
viewProviders: [],
currentViewProvider: {},
actionCollection: undefined,
existingViewIndex: 0
};
},
Expand All @@ -96,10 +93,6 @@ export default {
this.styleRuleManager.destroy();
delete this.styleRuleManager;
}

if (this.actionCollection) {
this.actionCollection.destroy();
}
},
unmounted() {
if (!this.existingView) {
Expand Down Expand Up @@ -157,10 +150,6 @@ export default {
}

this.initObjectStyles();

nextTick(() => {
this.getActionsCollection(this.view);
});
},
addExistingViewBackToParent() {
this.existingView.parentElement.appendChild(this.existingViewElement);
Expand All @@ -169,13 +158,6 @@ export default {
initializeViewContainer() {
this.viewContainer = this.$refs.objectView;
},
getActionsCollection(view) {
if (this.actionCollection) {
this.actionCollection.destroy();
}

this.actionCollection = this.openmct.actions.getActionsCollection(this.objectPath, view);
},
initObjectStyles() {
if (!this.styleRuleManager) {
this.styleRuleManager = new StyleRuleManager(
Expand Down
23 changes: 10 additions & 13 deletions src/ui/preview/PreviewHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
</template>

<script>
import { nextTick, toRaw } from 'vue';

import NotebookMenuSwitcher from '@/plugins/notebook/components/NotebookMenuSwitcher.vue';

import ViewSwitcher from '../layout/ViewSwitcher.vue';
Expand Down Expand Up @@ -94,12 +96,6 @@ export default {
default: () => {
return [];
}
},
actionCollection: {
type: Object,
default: () => {
return undefined;
}
}
},
emits: ['set-view'],
Expand All @@ -111,17 +107,18 @@ export default {
};
},
watch: {
actionCollection(actionCollection) {
async currentView() {
// wait for view to render with next tick
await nextTick();
if (this.actionCollection) {
this.unlistenToActionCollection();
}

this.actionCollection.on('update', this.updateActionItems);
this.updateActionItems(this.actionCollection.getActionsObject());
}
},
mounted() {
if (this.actionCollection) {
this.actionCollection = this.openmct.actions.getActionsCollection(
toRaw(this.objectPath),
toRaw(this.currentView)
);

this.actionCollection.on('update', this.updateActionItems);
this.updateActionItems(this.actionCollection.getActionsObject());
}
Expand Down

0 comments on commit 5391384

Please sign in to comment.