Skip to content

Commit e8d47cd

Browse files
fix: load layout of partial graph in current view: resolve #460, also improve format mismatch error message
1 parent 06f6687 commit e8d47cd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

js/browser/load.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export async function loadSessionFromJsonFile(event: Event): Promise<void> {
9696
*/
9797
function checkVersion(type: ViewJsonType, json: any): boolean {
9898
let ok: boolean = true;
99+
let ts = (t) => `type ${t} (${ViewJsonType[t]})`;
99100
if (
100101
json.version !== VERSION &&
101102
!confirm(`Your file was saved in version ${json.version}, but SNIK Graph has version ${VERSION}, so it may not work properly. Continue anyway?`)
@@ -105,7 +106,7 @@ function checkVersion(type: ViewJsonType, json: any): boolean {
105106
alert(`Unknown file format, aborting.`);
106107
ok = false;
107108
} else if (json.type !== type) {
108-
alert(`Your file was saved as ${json.type}, but you are trying to load a ${type}, aborting.`);
109+
alert(`Your file was saved as ${ts(json.type)}, but you are trying to load ${ts(type)}, aborting.`);
109110
ok = false;
110111
}
111112
return ok;
@@ -190,11 +191,10 @@ export function loadLayoutFromJsonObject(json: LayoutJson, graph: Graph) {
190191
export function loadLayout(event: Event): void {
191192
console.groupCollapsed("Loading JSON Layout file into View.");
192193
uploadJson(event, (json: LayoutJson) => {
193-
const view: View = new View(true, json.title);
194-
loadLayoutFromJsonObject(json, view.state.graph);
194+
loadLayoutFromJsonObject(json, View.activeState().graph);
195+
console.info("Finished loading layout from file.");
196+
console.groupEnd();
195197
});
196-
console.info("Finished loading layout from file.");
197-
console.groupEnd();
198198
}
199199

200200
/**

0 commit comments

Comments
 (0)