Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/graph-builder/graph-core/5-load-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ class GraphLoadSave extends GraphUndoRedo {
localStorageManager.save(this.id, graphObject);
this.loadGraphFromLocalStorage();
this.lastSavedActionIndex = this.curActionIndex;
}).catch(() => {
toast.error('Invalid GraphML file.');
});
}

Expand Down
30 changes: 19 additions & 11 deletions src/graph-builder/graphml/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ import {
parseNode, parseEdge, parseDetails, parseActionHistory,
} from './parseProperties';

const parser = (graphMlCnt) => new Promise((resolve) => {
const parser = (graphMlCnt) => new Promise((resolve, reject) => {
new xml2js.Parser().parseString(graphMlCnt, (err, grahMLObj) => {
const grahML = new PropFromArr(grahMLObj);
const nodes = grahML.parseProps('graphml.graph.node', 1).map(parseNode);
const edges = grahML.parseProps('graphml.graph.edge', 1).map(parseEdge);
const {
id, projectName, serverID, authorName,
} = parseDetails(grahML);
const actionHistory = parseActionHistory(grahML);
resolve({
id, projectName, edges, nodes, actionHistory, serverID, authorName,
});
if (err || !grahMLObj) {
reject(err || new Error('Invalid GraphML file.'));
return;
}
try {
const grahML = new PropFromArr(grahMLObj);
const nodes = grahML.parseProps('graphml.graph.node', 1).map(parseNode);
const edges = grahML.parseProps('graphml.graph.edge', 1).map(parseEdge);
const {
id, projectName, serverID, authorName,
} = parseDetails(grahML);
const actionHistory = parseActionHistory(grahML);
resolve({
id, projectName, edges, nodes, actionHistory, serverID, authorName,
});
} catch {
reject(new Error('Invalid GraphML file.'));
}
});
});
export default parser;
2 changes: 2 additions & 0 deletions src/toolbarActions/toolbarFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ const readFile = async (state, setState, file, fileHandle) => {
projectName, graphML: x.target.result, fileHandle, fileName: file.name, authorName,
},
});
}).catch(() => {
toast.error('Invalid GraphML file.');
});
};
if (fileHandle) fr.readAsText(await fileHandle.getFile());
Expand Down