[MyItems Plugin] Migrate/remove legacy MyItems code into new plugin (#4107)

* removed legacy my items, created my items plugin, moved relevant code to new plugin
* added object api method for checking if a domainObject is a missing object

Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
Jamie V
2021-11-05 11:17:49 -07:00
committed by GitHub
parent 1680c3cc1b
commit b8fabb7e73
17 changed files with 145 additions and 318 deletions

View File

@ -23,7 +23,7 @@
export default function MissingObjectInterceptor(openmct) {
openmct.objects.addGetInterceptor({
appliesTo: (identifier, domainObject) => {
return identifier.key !== 'mine';
return true;
},
invoke: (identifier, object) => {
if (object === undefined) {

View File

@ -1,9 +1,7 @@
import missingObjectInterceptor from "./missingObjectInterceptor";
import myItemsInterceptor from "./myItemsInterceptor";
export default function plugin() {
return function install(openmct) {
myItemsInterceptor(openmct);
missingObjectInterceptor(openmct);
};
}

View File

@ -75,22 +75,5 @@ describe('the plugin', function () {
});
});
it('returns the My items object if not found', () => {
const identifier = {
namespace: TEST_NAMESPACE,
key: 'mine'
};
return openmct.objects.get(identifier).then((testObject) => {
expect(testObject).toEqual({
identifier,
"name": "My Items",
"type": "folder",
"composition": [],
"location": "ROOT"
});
});
});
});
});

View File

@ -0,0 +1,8 @@
# My Items plugin
Defines top-level folder named "My Items" to store user-created items. Enabled by default, this can be disabled in a
read-only deployment with no user-editable objects.
## Installation
```js
openmct.install(openmct.plugins.MyItems());
```

View File

@ -0,0 +1,8 @@
export const MY_ITEMS_KEY = 'mine';
export function createMyItemsIdentifier(namespace = '') {
return {
key: MY_ITEMS_KEY,
namespace
};
}

View File

@ -20,24 +20,30 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/
export default function MyItemsInterceptor(openmct) {
import { MY_ITEMS_KEY } from "./createMyItemsIdentifier";
openmct.objects.addGetInterceptor({
appliesTo: (identifier, domainObject) => {
return identifier.key === 'mine';
function myItemsInterceptor(identifierObject, openmct) {
const myItemsModel = {
identifier: identifierObject,
"name": "My Items",
"type": "folder",
"composition": [],
"location": "ROOT"
};
return {
appliesTo: (identifier) => {
return identifier.key === MY_ITEMS_KEY;
},
invoke: (identifier, object) => {
if (object === undefined) {
return {
identifier,
"name": "My Items",
"type": "folder",
"composition": [],
"location": "ROOT"
};
if (openmct.objects.isMissing(object)) {
return myItemsModel;
}
return object;
}
});
};
}
export default myItemsInterceptor;

View File

@ -0,0 +1,33 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2021, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
import { createMyItemsIdentifier } from "./createMyItemsIdentifier";
import myItemsInterceptor from "./myItemsInterceptor";
export default function MyItemsPlugin(namespace = '') {
return function install(openmct) {
const identifier = createMyItemsIdentifier(namespace);
openmct.objects.addGetInterceptor(myItemsInterceptor(identifier, openmct));
openmct.objects.addRoot(identifier);
};
}

View File

@ -0,0 +1,90 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2021, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
import {
createOpenMct,
resetApplicationState
} from 'utils/testing';
import {
createMyItemsIdentifier,
MY_ITEMS_KEY
} from './createMyItemsIdentifier';
const MISSING_NAME = `Missing: ${MY_ITEMS_KEY}`;
const myItemsIdentifier = createMyItemsIdentifier();
describe("the plugin", () => {
let openmct;
let missingObj = {
identifier: myItemsIdentifier,
type: 'unknown',
name: MISSING_NAME
};
beforeEach((done) => {
openmct = createOpenMct();
openmct.install(openmct.plugins.MyItems());
openmct.on('start', done);
openmct.startHeadless();
});
afterEach(() => {
return resetApplicationState(openmct);
});
it('when installed, adds "My Items" to the root', async () => {
const root = await openmct.objects.get('ROOT');
const rootCompostionCollection = openmct.composition.get(root);
const rootCompostion = await rootCompostionCollection.load();
let myItems = rootCompostion.filter((domainObject) => {
return openmct.objects.areIdsEqual(domainObject.identifier, myItemsIdentifier);
})[0];
expect(myItems).toBeDefined();
});
describe('adds an interceptor that returns a "My Items" model for', () => {
let myItemsMissing;
let mockMissingProvider;
let activeProvider;
beforeEach(async () => {
mockMissingProvider = {
get: () => Promise.resolve(missingObj)
};
activeProvider = mockMissingProvider;
spyOn(openmct.objects, 'getProvider').and.returnValue(activeProvider);
myItemsMissing = await openmct.objects.get(myItemsIdentifier);
});
it('missing objects', () => {
let idsMatchMissing = openmct.objects.areIdsEqual(myItemsMissing.identifier, myItemsIdentifier);
expect(myItemsMissing).toBeDefined();
expect(idsMatchMissing).toBeTrue();
});
});
});

View File

@ -26,6 +26,7 @@ define([
'./remoteClock/plugin',
'./localTimeSystem/plugin',
'./ISOTimeFormat/plugin',
'./myItems/plugin',
'../../example/generator/plugin',
'./autoflow/AutoflowTabularPlugin',
'./timeConductor/plugin',
@ -78,6 +79,7 @@ define([
RemoteClock,
LocalTimeSystem,
ISOTimeFormat,
MyItems,
GeneratorPlugin,
AutoflowPlugin,
TimeConductorPlugin,
@ -127,7 +129,6 @@ define([
) {
const bundleMap = {
LocalStorage: 'platform/persistence/local',
MyItems: 'platform/features/my-items',
Elasticsearch: 'platform/persistence/elastic'
};
@ -143,6 +144,8 @@ define([
plugins.LocalTimeSystem = LocalTimeSystem;
plugins.RemoteClock = RemoteClock.default;
plugins.MyItems = MyItems.default;
plugins.ImportExport = ImportExport;
plugins.StaticRootPlugin = StaticRootPlugin;