mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 13:48: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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user