mirror of
https://github.com/nasa/openmct.git
synced 2025-05-07 19:18:36 +00:00
Fix notebook sync (#4738)
* Do not keep fetching default notebook * Fixes issue where notebooks would stop listening for remote changes. * Fix issue with notebook merge conflicts
This commit is contained in:
parent
556f762d20
commit
91e909bb4a
@ -465,23 +465,6 @@ ObjectAPI.prototype.mutate = function (domainObject, path, value) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates a domain object based on its latest persisted state. Note that this will mutate the provided object.
|
|
||||||
* @param {module:openmct.DomainObject} domainObject an object to refresh from its persistence store
|
|
||||||
* @returns {Promise} the provided object, updated to reflect the latest persisted state of the object.
|
|
||||||
*/
|
|
||||||
ObjectAPI.prototype.refresh = async function (domainObject) {
|
|
||||||
const refreshedObject = await this.get(domainObject.identifier);
|
|
||||||
|
|
||||||
if (domainObject.isMutable) {
|
|
||||||
domainObject.$refresh(refreshedObject);
|
|
||||||
} else {
|
|
||||||
utils.refresh(domainObject, refreshedObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
return domainObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
@ -322,7 +322,7 @@ export default {
|
|||||||
cleanupDefaultNotebook() {
|
cleanupDefaultNotebook() {
|
||||||
this.defaultPageId = undefined;
|
this.defaultPageId = undefined;
|
||||||
this.defaultSectionId = undefined;
|
this.defaultSectionId = undefined;
|
||||||
this.removeDefaultClass(this.domainObject);
|
this.removeDefaultClass(this.domainObject.identifier);
|
||||||
clearDefaultNotebook();
|
clearDefaultNotebook();
|
||||||
},
|
},
|
||||||
setSectionAndPageFromUrl() {
|
setSectionAndPageFromUrl() {
|
||||||
@ -619,12 +619,8 @@ export default {
|
|||||||
|
|
||||||
this.sectionsChanged({ sections });
|
this.sectionsChanged({ sections });
|
||||||
},
|
},
|
||||||
removeDefaultClass(defaultNotebookIdentifier) {
|
removeDefaultClass(identifier) {
|
||||||
if (!defaultNotebookIdentifier) {
|
this.openmct.status.delete(identifier);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.openmct.status.delete(defaultNotebookIdentifier);
|
|
||||||
},
|
},
|
||||||
resetSearch() {
|
resetSearch() {
|
||||||
this.search = '';
|
this.search = '';
|
||||||
@ -633,27 +629,24 @@ export default {
|
|||||||
toggleNav() {
|
toggleNav() {
|
||||||
this.showNav = !this.showNav;
|
this.showNav = !this.showNav;
|
||||||
},
|
},
|
||||||
updateDefaultNotebook(notebookStorage) {
|
updateDefaultNotebook(updatedNotebookStorageObject) {
|
||||||
const defaultNotebook = getDefaultNotebook();
|
if (!this.isDefaultNotebook()) {
|
||||||
const defaultNotebookIdentifier = defaultNotebook && defaultNotebook.identifier;
|
const persistedNotebookStorageObject = getDefaultNotebook();
|
||||||
const isSameNotebook = defaultNotebookIdentifier
|
if (persistedNotebookStorageObject.identifier !== undefined) {
|
||||||
&& this.openmct.objects.areIdsEqual(defaultNotebookIdentifier, notebookStorage.identifier);
|
this.removeDefaultClass(persistedNotebookStorageObject.identifier);
|
||||||
if (!isSameNotebook) {
|
}
|
||||||
this.removeDefaultClass(defaultNotebookIdentifier);
|
|
||||||
|
setDefaultNotebook(this.openmct, updatedNotebookStorageObject, this.domainObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defaultNotebookIdentifier || !isSameNotebook) {
|
if (this.defaultSectionId !== updatedNotebookStorageObject.defaultSectionId) {
|
||||||
setDefaultNotebook(this.openmct, notebookStorage, this.domainObject);
|
setDefaultNotebookSectionId(updatedNotebookStorageObject.defaultSectionId);
|
||||||
|
this.defaultSectionId = updatedNotebookStorageObject.defaultSectionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.defaultSectionId !== notebookStorage.defaultSectionId) {
|
if (this.defaultPageId !== updatedNotebookStorageObject.defaultPageId) {
|
||||||
setDefaultNotebookSectionId(notebookStorage.defaultSectionId);
|
setDefaultNotebookPageId(updatedNotebookStorageObject.defaultPageId);
|
||||||
this.defaultSectionId = notebookStorage.defaultSectionId;
|
this.defaultPageId = updatedNotebookStorageObject.defaultPageId;
|
||||||
}
|
|
||||||
|
|
||||||
if (this.defaultPageId !== notebookStorage.defaultPageId) {
|
|
||||||
setDefaultNotebookPageId(notebookStorage.defaultPageId);
|
|
||||||
this.defaultPageId = notebookStorage.defaultPageId;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateDefaultNotebookSection(sections, id) {
|
updateDefaultNotebookSection(sections, id) {
|
||||||
@ -671,7 +664,7 @@ export default {
|
|||||||
if (defaultNotebookSectionId === id) {
|
if (defaultNotebookSectionId === id) {
|
||||||
const section = sections.find(s => s.id === id);
|
const section = sections.find(s => s.id === id);
|
||||||
if (!section) {
|
if (!section) {
|
||||||
this.removeDefaultClass(this.domainObject);
|
this.removeDefaultClass(this.domainObject.identifier);
|
||||||
clearDefaultNotebook();
|
clearDefaultNotebook();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -8,6 +8,7 @@ export default function (openmct) {
|
|||||||
return apiSave(domainObject);
|
return apiSave(domainObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isNewMutable = !domainObject.isMutable;
|
||||||
const localMutable = openmct.objects._toMutable(domainObject);
|
const localMutable = openmct.objects._toMutable(domainObject);
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
@ -20,7 +21,9 @@ export default function (openmct) {
|
|||||||
result = Promise.reject(error);
|
result = Promise.reject(error);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
openmct.objects.destroyMutable(localMutable);
|
if (isNewMutable) {
|
||||||
|
openmct.objects.destroyMutable(localMutable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -28,10 +31,10 @@ export default function (openmct) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resolveConflicts(localMutable, openmct) {
|
function resolveConflicts(localMutable, openmct) {
|
||||||
|
const localEntries = JSON.parse(JSON.stringify(localMutable.configuration.entries));
|
||||||
|
|
||||||
return openmct.objects.getMutable(localMutable.identifier).then((remoteMutable) => {
|
return openmct.objects.getMutable(localMutable.identifier).then((remoteMutable) => {
|
||||||
const localEntries = localMutable.configuration.entries;
|
applyLocalEntries(remoteMutable, localEntries, openmct);
|
||||||
remoteMutable.$refresh(remoteMutable);
|
|
||||||
applyLocalEntries(remoteMutable, localEntries);
|
|
||||||
|
|
||||||
openmct.objects.destroyMutable(remoteMutable);
|
openmct.objects.destroyMutable(remoteMutable);
|
||||||
|
|
||||||
@ -39,7 +42,7 @@ function resolveConflicts(localMutable, openmct) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyLocalEntries(mutable, entries) {
|
function applyLocalEntries(mutable, entries, openmct) {
|
||||||
Object.entries(entries).forEach(([sectionKey, pagesInSection]) => {
|
Object.entries(entries).forEach(([sectionKey, pagesInSection]) => {
|
||||||
Object.entries(pagesInSection).forEach(([pageKey, localEntries]) => {
|
Object.entries(pagesInSection).forEach(([pageKey, localEntries]) => {
|
||||||
const remoteEntries = mutable.configuration.entries[sectionKey][pageKey];
|
const remoteEntries = mutable.configuration.entries[sectionKey][pageKey];
|
||||||
@ -58,14 +61,15 @@ function applyLocalEntries(mutable, entries) {
|
|||||||
|
|
||||||
locallyModifiedEntries.forEach((locallyModifiedEntry) => {
|
locallyModifiedEntries.forEach((locallyModifiedEntry) => {
|
||||||
let mergedEntry = mergedEntries.find(entry => entry.id === locallyModifiedEntry.id);
|
let mergedEntry = mergedEntries.find(entry => entry.id === locallyModifiedEntry.id);
|
||||||
if (mergedEntry !== undefined) {
|
if (mergedEntry !== undefined
|
||||||
|
&& locallyModifiedEntry.text.match(/\S/)) {
|
||||||
mergedEntry.text = locallyModifiedEntry.text;
|
mergedEntry.text = locallyModifiedEntry.text;
|
||||||
shouldMutate = true;
|
shouldMutate = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (shouldMutate) {
|
if (shouldMutate) {
|
||||||
mutable.$set(`configuration.entries.${sectionKey}.${pageKey}`, mergedEntries);
|
openmct.objects.mutate(mutable, `configuration.entries.${sectionKey}.${pageKey}`, mergedEntries);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -120,7 +120,6 @@ export function addNotebookEntry(openmct, domainObject, notebookStorage, embed =
|
|||||||
const newEntries = addEntryIntoPage(notebookStorage, entries, entry);
|
const newEntries = addEntryIntoPage(notebookStorage, entries, entry);
|
||||||
|
|
||||||
addDefaultClass(domainObject, openmct);
|
addDefaultClass(domainObject, openmct);
|
||||||
|
|
||||||
mutateObject(openmct, domainObject, 'configuration.entries', newEntries);
|
mutateObject(openmct, domainObject, 'configuration.entries', newEntries);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user