Skip to content

Make Tabs eager loading configurable but default to false #7199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 29, 2024
2 changes: 1 addition & 1 deletion src/plugins/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ define([
plugins.FaultManagement = FaultManagementPlugin.default;
plugins.FormActions = FormActions;
plugins.FolderView = FolderView.default;
plugins.Tabs = Tabs;
plugins.Tabs = Tabs.default;
plugins.FlexibleLayout = FlexibleLayout;
plugins.LADTable = LADTable.default;
plugins.Filters = Filters;
Expand Down
72 changes: 37 additions & 35 deletions src/plugins/tabs/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,42 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

define(['./tabs'], function (Tabs) {
return function plugin() {
return function install(openmct) {
openmct.objectViews.addProvider(new Tabs.default(openmct));
import Tabs from './tabs';

openmct.types.addType('tabs', {
name: 'Tabs View',
description: 'Quickly navigate between multiple objects of any type using tabs.',
creatable: true,
cssClass: 'icon-tabs-view',
initialize(domainObject) {
domainObject.composition = [];
domainObject.keep_alive = true;
},
form: [
{
key: 'keep_alive',
name: 'Eager Load Tabs',
control: 'select',
options: [
{
name: 'True',
value: true
},
{
name: 'False',
value: false
}
],
required: true,
cssClass: 'l-input'
}
]
});
};
export default function plugin(options) {
return function install(openmct) {
const eagerLoad = options?.eagerLoad ?? false;

openmct.objectViews.addProvider(new Tabs(openmct));

openmct.types.addType('tabs', {
name: 'Tabs View',
description: 'Quickly navigate between multiple objects of any type using tabs.',
creatable: true,
cssClass: 'icon-tabs-view',
initialize(domainObject) {
domainObject.composition = [];
domainObject.keep_alive = eagerLoad;
},
form: [
{
key: 'keep_alive',
name: 'Eager Load Tabs',
control: 'toggleSwitch',
options: [
{
name: 'True',
value: true
},
{
name: 'False',
value: false
}
],
required: true,
cssClass: 'l-input'
}
]
});
};
});
}
55 changes: 48 additions & 7 deletions src/plugins/tabs/pluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe('the plugin', function () {
let element;
let child;
let openmct;
let tabsLayoutDefinition;
let tabsType;

const testViewObject = {
identifier: {
key: 'mock-tabs-object',
Expand Down Expand Up @@ -85,8 +86,7 @@ describe('the plugin', function () {

beforeEach((done) => {
openmct = createOpenMct();
openmct.install(new TabsLayout());
tabsLayoutDefinition = openmct.types.get('tabs');
tabsType = openmct.types.get('tabs');

element = document.createElement('div');
child = document.createElement('div');
Expand All @@ -100,15 +100,56 @@ describe('the plugin', function () {
});

afterEach(() => {
child = undefined;
element = undefined;

return resetApplicationState(openmct);
});

it('defines a tabs object type with the correct key', () => {
expect(tabsLayoutDefinition.definition.name).toEqual('Tabs View');
it('is installed by default and provides a tabs object', () => {
expect(tabsType.definition.name).toEqual('Tabs View');
});

it('the tabs object is creatable', () => {
expect(tabsType.definition.creatable).toEqual(true);
});

it('is creatable', () => {
expect(tabsLayoutDefinition.definition.creatable).toEqual(true);
it('sets eager load to false by default', () => {
const tabsObject = {
identifier: {
key: 'some-tab-object',
namespace: ''
},
type: 'tabs'
};

tabsType.definition.initialize(tabsObject);

expect(tabsObject.keep_alive).toBeFalse();
});

it('can be installed with eager load defaulting to true', () => {
const options = {
eagerLoad: true
};
const openmct2 = createOpenMct();
openmct2.install(new TabsLayout(options));
openmct2.startHeadless();

const tabsObject = {
identifier: {
key: 'some-tab-object',
namespace: ''
},
type: 'tabs'
};

const overriddenTabsType = openmct2.types.get('tabs');
overriddenTabsType.definition.initialize(tabsObject);

expect(tabsObject.keep_alive).toBeTrue();

return resetApplicationState(openmct2);
});

describe('the view', function () {
Expand Down