mirror of
https://github.com/nasa/openmct.git
synced 2025-06-14 21:28:12 +00:00
[Notebook] new entries on brand new notebook not rendered (#3496)
* [Notebook] new entries on brand new notebook not rendered #3488 * Refactored code to 'mutateObject' from one place only, add page to newly created section immediately, update entries copy then call mutate to update it inside domainObject. Co-authored-by: Jamie V <jamie.j.vigliotta@nasa.gov> Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import objectLink from '../../../ui/mixins/object-link';
|
||||
|
||||
export const DEFAULT_CLASS = 'is-notebook-default';
|
||||
const TIME_BOUNDS = {
|
||||
START_BOUND: 'tc.startBound',
|
||||
@ -8,6 +7,29 @@ const TIME_BOUNDS = {
|
||||
END_DELTA: 'tc.endDelta'
|
||||
};
|
||||
|
||||
export function addEntryIntoPage(notebookStorage, entries, entry) {
|
||||
const defaultSection = notebookStorage.section;
|
||||
const defaultPage = notebookStorage.page;
|
||||
if (!defaultSection || !defaultPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newEntries = JSON.parse(JSON.stringify(entries));
|
||||
let section = newEntries[defaultSection.id];
|
||||
if (!section) {
|
||||
newEntries[defaultSection.id] = {};
|
||||
}
|
||||
|
||||
let page = newEntries[defaultSection.id][defaultPage.id];
|
||||
if (!page) {
|
||||
newEntries[defaultSection.id][defaultPage.id] = [];
|
||||
}
|
||||
|
||||
newEntries[defaultSection.id][defaultPage.id].push(entry);
|
||||
|
||||
return newEntries;
|
||||
}
|
||||
|
||||
export function getHistoricLinkInFixedMode(openmct, bounds, historicLink) {
|
||||
if (historicLink.includes('tc.mode=fixed')) {
|
||||
return historicLink;
|
||||
@ -38,35 +60,6 @@ export function getHistoricLinkInFixedMode(openmct, bounds, historicLink) {
|
||||
return params.join('&');
|
||||
}
|
||||
|
||||
export function getNotebookDefaultEntries(notebookStorage, domainObject) {
|
||||
if (!notebookStorage || !domainObject) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const defaultSection = notebookStorage.section;
|
||||
const defaultPage = notebookStorage.page;
|
||||
if (!defaultSection || !defaultPage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const configuration = domainObject.configuration;
|
||||
const entries = configuration.entries || {};
|
||||
|
||||
let section = entries[defaultSection.id];
|
||||
if (!section) {
|
||||
section = {};
|
||||
entries[defaultSection.id] = section;
|
||||
}
|
||||
|
||||
let page = entries[defaultSection.id][defaultPage.id];
|
||||
if (!page) {
|
||||
page = [];
|
||||
entries[defaultSection.id][defaultPage.id] = [];
|
||||
}
|
||||
|
||||
return entries[defaultSection.id][defaultPage.id];
|
||||
}
|
||||
|
||||
export function createNewEmbed(snapshotMeta, snapshot = '') {
|
||||
const {
|
||||
bounds,
|
||||
@ -120,24 +113,25 @@ export function addNotebookEntry(openmct, domainObject, notebookStorage, embed =
|
||||
? [embed]
|
||||
: [];
|
||||
|
||||
const defaultEntries = getNotebookDefaultEntries(notebookStorage, domainObject);
|
||||
const id = `entry-${date}`;
|
||||
defaultEntries.push({
|
||||
const entry = {
|
||||
id,
|
||||
createdOn: date,
|
||||
text: '',
|
||||
embeds
|
||||
});
|
||||
};
|
||||
|
||||
const newEntries = addEntryIntoPage(notebookStorage, entries, entry);
|
||||
|
||||
addDefaultClass(domainObject);
|
||||
openmct.objects.mutate(domainObject, 'configuration.entries', entries);
|
||||
mutateObject(openmct, domainObject, 'configuration.entries', newEntries);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
export function getNotebookEntries(domainObject, selectedSection, selectedPage) {
|
||||
if (!domainObject || !selectedSection || !selectedPage) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
const configuration = domainObject.configuration;
|
||||
@ -145,12 +139,12 @@ export function getNotebookEntries(domainObject, selectedSection, selectedPage)
|
||||
|
||||
let section = entries[selectedSection.id];
|
||||
if (!section) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
let page = entries[selectedSection.id][selectedPage.id];
|
||||
if (!page) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
return entries[selectedSection.id][selectedPage.id];
|
||||
@ -196,7 +190,11 @@ export function deleteNotebookEntries(openmct, domainObject, selectedSection, se
|
||||
|
||||
delete entries[selectedSection.id][selectedPage.id];
|
||||
|
||||
openmct.objects.mutate(domainObject, 'configuration.entries', entries);
|
||||
mutateObject(openmct, domainObject, 'configuration.entries', entries);
|
||||
}
|
||||
|
||||
export function mutateObject(openmct, object, key, value) {
|
||||
openmct.objects.mutate(object, key, value);
|
||||
}
|
||||
|
||||
function addDefaultClass(domainObject) {
|
||||
@ -206,4 +204,6 @@ function addDefaultClass(domainObject) {
|
||||
}
|
||||
|
||||
classList.push(DEFAULT_CLASS);
|
||||
|
||||
domainObject.classList = classList;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
import * as NotebookEntries from './notebook-entries';
|
||||
import { createOpenMct, spyOnBuiltins, resetApplicationState } from 'utils/testing';
|
||||
import { createOpenMct, resetApplicationState } from 'utils/testing';
|
||||
|
||||
const notebookStorage = {
|
||||
domainObject: {
|
||||
@ -121,7 +121,6 @@ describe('Notebook Entries:', () => {
|
||||
beforeEach(done => {
|
||||
openmct = createOpenMct();
|
||||
window.localStorage.setItem('notebook-storage', null);
|
||||
spyOnBuiltins(['mutate'], openmct.objects);
|
||||
|
||||
done();
|
||||
});
|
||||
@ -137,24 +136,16 @@ describe('Notebook Entries:', () => {
|
||||
expect(entries.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('addNotebookEntry mutates object', () => {
|
||||
it('addNotebookEntry adds entry', (done) => {
|
||||
const unlisten = openmct.objects.observe(notebookDomainObject, '*', (object) => {
|
||||
const entries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
expect(entries.length).toEqual(1);
|
||||
done();
|
||||
unlisten();
|
||||
});
|
||||
|
||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
|
||||
expect(openmct.objects.mutate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('addNotebookEntry adds entry', () => {
|
||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
const entries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
expect(entries.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('getEntryPosById returns valid position', () => {
|
||||
const entryId = NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
const position = NotebookEntries.getEntryPosById(entryId, notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
expect(position).toEqual(0);
|
||||
});
|
||||
|
||||
it('getEntryPosById returns valid position', () => {
|
||||
@ -174,22 +165,13 @@ describe('Notebook Entries:', () => {
|
||||
expect(success).toBe(true);
|
||||
});
|
||||
|
||||
it('deleteNotebookEntries mutates object', () => {
|
||||
openmct.objects.mutate.calls.reset();
|
||||
|
||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
NotebookEntries.deleteNotebookEntries(openmct, notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
expect(openmct.objects.mutate).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('deleteNotebookEntries deletes correct entry', () => {
|
||||
it('deleteNotebookEntries deletes correct page entries', () => {
|
||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
|
||||
NotebookEntries.deleteNotebookEntries(openmct, notebookDomainObject, selectedSection, selectedPage);
|
||||
const afterEntries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
expect(afterEntries).toEqual(null);
|
||||
expect(afterEntries).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user