mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 22:17:49 +00:00
[My Items] Make folder name customizable (#4627)
* making my items folder name customizable Co-authored-by: Nikhil <nikhil.k.mandlik@nasa.gov> Co-authored-by: John Hill <john.c.hill@nasa.gov>
This commit is contained in:
parent
6a8f4b5d9c
commit
23ead2ceaa
@ -22,14 +22,14 @@
|
|||||||
|
|
||||||
import { MY_ITEMS_KEY } from "./createMyItemsIdentifier";
|
import { MY_ITEMS_KEY } from "./createMyItemsIdentifier";
|
||||||
|
|
||||||
function myItemsInterceptor(identifierObject, openmct) {
|
function myItemsInterceptor(openmct, identifierObject, name) {
|
||||||
|
|
||||||
const myItemsModel = {
|
const myItemsModel = {
|
||||||
identifier: identifierObject,
|
identifier: identifierObject,
|
||||||
"name": "My Items",
|
name,
|
||||||
"type": "folder",
|
type: "folder",
|
||||||
"composition": [],
|
composition: [],
|
||||||
"location": "ROOT"
|
location: "ROOT"
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -23,11 +23,13 @@
|
|||||||
import { createMyItemsIdentifier } from "./createMyItemsIdentifier";
|
import { createMyItemsIdentifier } from "./createMyItemsIdentifier";
|
||||||
import myItemsInterceptor from "./myItemsInterceptor";
|
import myItemsInterceptor from "./myItemsInterceptor";
|
||||||
|
|
||||||
export default function MyItemsPlugin(namespace = '') {
|
const MY_ITEMS_DEFAULT_NAME = 'My Items';
|
||||||
|
|
||||||
|
export default function MyItemsPlugin(name = MY_ITEMS_DEFAULT_NAME, namespace = '') {
|
||||||
return function install(openmct) {
|
return function install(openmct) {
|
||||||
const identifier = createMyItemsIdentifier(namespace);
|
const identifier = createMyItemsIdentifier(namespace);
|
||||||
|
|
||||||
openmct.objects.addGetInterceptor(myItemsInterceptor(identifier, openmct));
|
openmct.objects.addGetInterceptor(myItemsInterceptor(openmct, identifier, name));
|
||||||
openmct.objects.addRoot(identifier);
|
openmct.objects.addRoot(identifier);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ import {
|
|||||||
} from './createMyItemsIdentifier';
|
} from './createMyItemsIdentifier';
|
||||||
|
|
||||||
const MISSING_NAME = `Missing: ${MY_ITEMS_KEY}`;
|
const MISSING_NAME = `Missing: ${MY_ITEMS_KEY}`;
|
||||||
|
const DEFAULT_NAME = 'My Items';
|
||||||
|
const FANCY_NAME = 'Fancy Items';
|
||||||
const myItemsIdentifier = createMyItemsIdentifier();
|
const myItemsIdentifier = createMyItemsIdentifier();
|
||||||
|
|
||||||
describe("the plugin", () => {
|
describe("the plugin", () => {
|
||||||
@ -40,9 +42,10 @@ describe("the plugin", () => {
|
|||||||
name: MISSING_NAME
|
name: MISSING_NAME
|
||||||
};
|
};
|
||||||
|
|
||||||
|
describe('with no arguments passed in', () => {
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach((done) => {
|
||||||
openmct = createOpenMct();
|
openmct = createOpenMct();
|
||||||
|
|
||||||
openmct.install(openmct.plugins.MyItems());
|
openmct.install(openmct.plugins.MyItems());
|
||||||
|
|
||||||
openmct.on('start', done);
|
openmct.on('start', done);
|
||||||
@ -61,6 +64,7 @@ describe("the plugin", () => {
|
|||||||
return openmct.objects.areIdsEqual(domainObject.identifier, myItemsIdentifier);
|
return openmct.objects.areIdsEqual(domainObject.identifier, myItemsIdentifier);
|
||||||
})[0];
|
})[0];
|
||||||
|
|
||||||
|
expect(myItems.name).toBe(DEFAULT_NAME);
|
||||||
expect(myItems).toBeDefined();
|
expect(myItems).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -90,3 +94,30 @@ describe("the plugin", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with a name argument passed in', () => {
|
||||||
|
|
||||||
|
beforeEach((done) => {
|
||||||
|
openmct = createOpenMct();
|
||||||
|
openmct.install(openmct.plugins.MyItems(FANCY_NAME));
|
||||||
|
|
||||||
|
spyOn(openmct.objects, 'isMissing').and.returnValue(true);
|
||||||
|
|
||||||
|
openmct.on('start', done);
|
||||||
|
openmct.startHeadless();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
return resetApplicationState(openmct);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('when installed, uses the passed in name', async () => {
|
||||||
|
let myItems = await openmct.objects.get(myItemsIdentifier);
|
||||||
|
|
||||||
|
expect(myItems.name).toBe(FANCY_NAME);
|
||||||
|
expect(myItems).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user