mirror of
https://github.com/nasa/openmct.git
synced 2025-06-10 11:21:41 +00:00
[Notebook] Do not persist notebook objects in notebook Local Storage (#3295)
* [Notebook] Do not persist domain objects on notebooks or snapshots #3291 Co-authored-by: Deep Tailor <deep.j.tailor@nasa.gov>
This commit is contained in:
parent
b0fa955914
commit
23aba14dfe
@ -225,14 +225,12 @@ export default {
|
|||||||
},
|
},
|
||||||
createNotebookStorageObject() {
|
createNotebookStorageObject() {
|
||||||
const notebookMeta = {
|
const notebookMeta = {
|
||||||
name: this.internalDomainObject.name,
|
|
||||||
identifier: this.internalDomainObject.identifier
|
identifier: this.internalDomainObject.identifier
|
||||||
};
|
};
|
||||||
const page = this.getSelectedPage();
|
const page = this.getSelectedPage();
|
||||||
const section = this.getSelectedSection();
|
const section = this.getSelectedSection();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
domainObject: this.internalDomainObject,
|
|
||||||
notebookMeta,
|
notebookMeta,
|
||||||
section,
|
section,
|
||||||
page
|
page
|
||||||
@ -442,10 +440,10 @@ export default {
|
|||||||
async updateDefaultNotebook(notebookStorage) {
|
async updateDefaultNotebook(notebookStorage) {
|
||||||
const defaultNotebookObject = await this.getDefaultNotebookObject();
|
const defaultNotebookObject = await this.getDefaultNotebookObject();
|
||||||
if (!defaultNotebookObject) {
|
if (!defaultNotebookObject) {
|
||||||
setDefaultNotebook(this.openmct, notebookStorage);
|
setDefaultNotebook(this.openmct, notebookStorage, this.internalDomainObject);
|
||||||
} else if (objectUtils.makeKeyString(defaultNotebookObject.identifier) !== objectUtils.makeKeyString(notebookStorage.notebookMeta.identifier)) {
|
} else if (objectUtils.makeKeyString(defaultNotebookObject.identifier) !== objectUtils.makeKeyString(notebookStorage.notebookMeta.identifier)) {
|
||||||
this.removeDefaultClass(defaultNotebookObject);
|
this.removeDefaultClass(defaultNotebookObject);
|
||||||
setDefaultNotebook(this.openmct, notebookStorage);
|
setDefaultNotebook(this.openmct, notebookStorage, this.internalDomainObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.defaultSectionId && this.defaultSectionId.length === 0 || this.defaultSectionId !== notebookStorage.section.id) {
|
if (this.defaultSectionId && this.defaultSectionId.length === 0 || this.defaultSectionId !== notebookStorage.section.id) {
|
||||||
|
@ -44,38 +44,46 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
notebookSnapshot: null,
|
notebookSnapshot: undefined,
|
||||||
notebookTypes: []
|
notebookTypes: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
validateNotebookStorageObject();
|
validateNotebookStorageObject();
|
||||||
|
this.getDefaultNotebookObject();
|
||||||
|
|
||||||
this.notebookSnapshot = new Snapshot(this.openmct);
|
this.notebookSnapshot = new Snapshot(this.openmct);
|
||||||
this.setDefaultNotebookStatus();
|
this.setDefaultNotebookStatus();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
showMenu(event) {
|
async getDefaultNotebookObject() {
|
||||||
const notebookTypes = [];
|
|
||||||
const defaultNotebook = getDefaultNotebook();
|
const defaultNotebook = getDefaultNotebook();
|
||||||
|
const defaultNotebookObject = defaultNotebook && await this.openmct.objects.get(defaultNotebook.notebookMeta.identifier);
|
||||||
|
|
||||||
|
return defaultNotebookObject;
|
||||||
|
},
|
||||||
|
async showMenu(event) {
|
||||||
|
const notebookTypes = [];
|
||||||
const elementBoundingClientRect = this.$el.getBoundingClientRect();
|
const elementBoundingClientRect = this.$el.getBoundingClientRect();
|
||||||
const x = elementBoundingClientRect.x;
|
const x = elementBoundingClientRect.x;
|
||||||
const y = elementBoundingClientRect.y + elementBoundingClientRect.height;
|
const y = elementBoundingClientRect.y + elementBoundingClientRect.height;
|
||||||
|
|
||||||
if (defaultNotebook) {
|
const defaultNotebookObject = await this.getDefaultNotebookObject();
|
||||||
const domainObject = defaultNotebook.domainObject;
|
if (defaultNotebookObject) {
|
||||||
|
const name = defaultNotebookObject.name;
|
||||||
|
|
||||||
if (domainObject.location) {
|
const defaultNotebook = getDefaultNotebook();
|
||||||
const defaultPath = `${domainObject.name} - ${defaultNotebook.section.name} - ${defaultNotebook.page.name}`;
|
const sectionName = defaultNotebook.section.name;
|
||||||
|
const pageName = defaultNotebook.page.name;
|
||||||
|
const defaultPath = `${name} - ${sectionName} - ${pageName}`;
|
||||||
|
|
||||||
notebookTypes.push({
|
notebookTypes.push({
|
||||||
cssClass: 'icon-notebook',
|
cssClass: 'icon-notebook',
|
||||||
name: `Save to Notebook ${defaultPath}`,
|
name: `Save to Notebook ${defaultPath}`,
|
||||||
callBack: () => {
|
callBack: () => {
|
||||||
return this.snapshot(NOTEBOOK_DEFAULT);
|
return this.snapshot(NOTEBOOK_DEFAULT);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notebookTypes.push({
|
notebookTypes.push({
|
||||||
|
@ -23,13 +23,6 @@ import * as NotebookEntries from './notebook-entries';
|
|||||||
import { createOpenMct, resetApplicationState } from 'utils/testing';
|
import { createOpenMct, resetApplicationState } from 'utils/testing';
|
||||||
|
|
||||||
const notebookStorage = {
|
const notebookStorage = {
|
||||||
domainObject: {
|
|
||||||
name: 'notebook',
|
|
||||||
identifier: {
|
|
||||||
namespace: '',
|
|
||||||
key: 'test-notebook'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
notebookMeta: {
|
notebookMeta: {
|
||||||
name: 'notebook',
|
name: 'notebook',
|
||||||
identifier: {
|
identifier: {
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
|
import objectUtils from 'objectUtils';
|
||||||
|
|
||||||
const NOTEBOOK_LOCAL_STORAGE = 'notebook-storage';
|
const NOTEBOOK_LOCAL_STORAGE = 'notebook-storage';
|
||||||
let currentNotebookObject = null;
|
let currentNotebookObjectIdentifier = null;
|
||||||
let unlisten = null;
|
let unlisten = null;
|
||||||
|
|
||||||
function defaultNotebookObjectChanged(newDomainObject) {
|
function defaultNotebookObjectChanged(newDomainObject) {
|
||||||
if (newDomainObject.location !== null) {
|
if (newDomainObject.location !== null) {
|
||||||
currentNotebookObject = newDomainObject;
|
currentNotebookObjectIdentifier = newDomainObject.identifier;
|
||||||
const notebookStorage = getDefaultNotebook();
|
|
||||||
notebookStorage.domainObject = newDomainObject;
|
|
||||||
saveDefaultNotebook(notebookStorage);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -20,10 +19,9 @@ function defaultNotebookObjectChanged(newDomainObject) {
|
|||||||
clearDefaultNotebook();
|
clearDefaultNotebook();
|
||||||
}
|
}
|
||||||
|
|
||||||
function observeDefaultNotebookObject(openmct, notebookStorage) {
|
function observeDefaultNotebookObject(openmct, notebookMeta, domainObject) {
|
||||||
const domainObject = notebookStorage.domainObject;
|
if (currentNotebookObjectIdentifier
|
||||||
if (currentNotebookObject
|
&& objectUtils.makeKeyString(currentNotebookObjectIdentifier) === objectUtils.makeKeyString(notebookMeta.identifier)) {
|
||||||
&& currentNotebookObject.identifier.key === domainObject.identifier.key) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +30,7 @@ function observeDefaultNotebookObject(openmct, notebookStorage) {
|
|||||||
unlisten = null;
|
unlisten = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlisten = openmct.objects.observe(notebookStorage.domainObject, '*', defaultNotebookObjectChanged);
|
unlisten = openmct.objects.observe(domainObject, '*', defaultNotebookObjectChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveDefaultNotebook(notebookStorage) {
|
function saveDefaultNotebook(notebookStorage) {
|
||||||
@ -40,7 +38,7 @@ function saveDefaultNotebook(notebookStorage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function clearDefaultNotebook() {
|
export function clearDefaultNotebook() {
|
||||||
currentNotebookObject = null;
|
currentNotebookObjectIdentifier = null;
|
||||||
window.localStorage.setItem(NOTEBOOK_LOCAL_STORAGE, null);
|
window.localStorage.setItem(NOTEBOOK_LOCAL_STORAGE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +48,8 @@ export function getDefaultNotebook() {
|
|||||||
return JSON.parse(notebookStorage);
|
return JSON.parse(notebookStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setDefaultNotebook(openmct, notebookStorage) {
|
export function setDefaultNotebook(openmct, notebookStorage, domainObject) {
|
||||||
observeDefaultNotebookObject(openmct, notebookStorage);
|
observeDefaultNotebookObject(openmct, notebookStorage.notebookMeta, domainObject);
|
||||||
saveDefaultNotebook(notebookStorage);
|
saveDefaultNotebook(notebookStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,14 +23,15 @@
|
|||||||
import * as NotebookStorage from './notebook-storage';
|
import * as NotebookStorage from './notebook-storage';
|
||||||
import { createOpenMct, resetApplicationState } from 'utils/testing';
|
import { createOpenMct, resetApplicationState } from 'utils/testing';
|
||||||
|
|
||||||
|
const domainObject = {
|
||||||
|
name: 'notebook',
|
||||||
|
identifier: {
|
||||||
|
namespace: '',
|
||||||
|
key: 'test-notebook'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const notebookStorage = {
|
const notebookStorage = {
|
||||||
domainObject: {
|
|
||||||
name: 'notebook',
|
|
||||||
identifier: {
|
|
||||||
namespace: '',
|
|
||||||
key: 'test-notebook'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
notebookMeta: {
|
notebookMeta: {
|
||||||
name: 'notebook',
|
name: 'notebook',
|
||||||
identifier: {
|
identifier: {
|
||||||
@ -82,7 +83,7 @@ describe('Notebook Storage:', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has correct notebookstorage on setDefaultNotebook', () => {
|
it('has correct notebookstorage on setDefaultNotebook', () => {
|
||||||
NotebookStorage.setDefaultNotebook(openmct, notebookStorage);
|
NotebookStorage.setDefaultNotebook(openmct, notebookStorage, domainObject);
|
||||||
const defaultNotebook = NotebookStorage.getDefaultNotebook();
|
const defaultNotebook = NotebookStorage.getDefaultNotebook();
|
||||||
|
|
||||||
expect(JSON.stringify(defaultNotebook)).toBe(JSON.stringify(notebookStorage));
|
expect(JSON.stringify(defaultNotebook)).toBe(JSON.stringify(notebookStorage));
|
||||||
@ -98,7 +99,7 @@ describe('Notebook Storage:', () => {
|
|||||||
sectionTitle: 'Section'
|
sectionTitle: 'Section'
|
||||||
};
|
};
|
||||||
|
|
||||||
NotebookStorage.setDefaultNotebook(openmct, notebookStorage);
|
NotebookStorage.setDefaultNotebook(openmct, notebookStorage, domainObject);
|
||||||
NotebookStorage.setDefaultNotebookSection(section);
|
NotebookStorage.setDefaultNotebookSection(section);
|
||||||
|
|
||||||
const defaultNotebook = NotebookStorage.getDefaultNotebook();
|
const defaultNotebook = NotebookStorage.getDefaultNotebook();
|
||||||
@ -115,7 +116,7 @@ describe('Notebook Storage:', () => {
|
|||||||
pageTitle: 'Page'
|
pageTitle: 'Page'
|
||||||
};
|
};
|
||||||
|
|
||||||
NotebookStorage.setDefaultNotebook(openmct, notebookStorage);
|
NotebookStorage.setDefaultNotebook(openmct, notebookStorage, domainObject);
|
||||||
NotebookStorage.setDefaultNotebookPage(page);
|
NotebookStorage.setDefaultNotebookPage(page);
|
||||||
|
|
||||||
const defaultNotebook = NotebookStorage.getDefaultNotebook();
|
const defaultNotebook = NotebookStorage.getDefaultNotebook();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user