Skip to content

Commit 7fc6f63

Browse files
committed
author fix
1 parent 17430c9 commit 7fc6f63

10 files changed

Lines changed: 29 additions & 16 deletions

File tree

src/GraphArea.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MyGraph from './graph-builder';
44
import { actionType as T } from './reducer';
55

66
function Graph({
7-
el, superState, dispatcher, graphID, serverID, graphML, projectName, graphContainerRef, active,
7+
el, superState, dispatcher, graphID, serverID, graphML, projectName, graphContainerRef, active, authorName,
88
}) {
99
const [instance, setInstance] = useState(null);
1010
const ref = useRef();
@@ -18,7 +18,7 @@ function Graph({
1818

1919
const initialiseNewGraph = () => {
2020
const myGraph = new MyGraph(
21-
graphID, ref.current, dispatcher, superState, projectName, nodeValidator, edgeValidator,
21+
graphID, ref.current, dispatcher, superState, projectName, nodeValidator, edgeValidator, authorName,
2222
);
2323
if (graphID) myGraph.loadGraphFromLocalStorage();
2424
if (serverID) {

src/GraphWorkspace.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const GraphComp = (props) => {
7474
projectName={el.projectName}
7575
fileHandle={el.fileHandle}
7676
fileName={el.fileName}
77+
authorName={el.authorName}
7778
/>
7879
))}
7980
<ZoomComp dispatcher={dispatcher} superState={superState} />

src/graph-builder/graph-core/1-core.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ class CoreGraph {
1717

1818
projectName;
1919

20+
authorName;
21+
2022
cy;
2123

2224
bendNode;
2325

24-
constructor(id, element, dispatcher, superState, projectName) {
26+
constructor(id, element, dispatcher, superState, projectName, nodeValidator, edgeValidator, authorName) {
2527
if (dispatcher) this.dispatcher = dispatcher;
2628
if (superState) this.superState = superState;
2729
if (typeof cytoscape('core', 'edgehandles') !== 'function') {
@@ -37,6 +39,7 @@ class CoreGraph {
3739
this.cy = cytoscape({ ...cyOptions, container: element });
3840
this.id = id;
3941
this.projectName = projectName;
42+
this.authorName = authorName;
4043
this.cy.emit('graph-modified');
4144
this.bendNode = this.cy.add(
4245
{ group: 'nodes', data: { type: 'bend' }, classes: ['hidden'] },

src/graph-builder/graph-core/5-load-save.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class GraphLoadSave extends GraphUndoRedo {
5959
serverID: this.serverID,
6060
fileName: null,
6161
fileHandle: null,
62+
authorName: this.authorName,
6263
};
6364
this.cy.nodes().forEach((node) => {
6465
if (this.shouldNodeBeSaved(node.id())) {
@@ -86,10 +87,9 @@ class GraphLoadSave extends GraphUndoRedo {
8687
}
8788
});
8889
graph.actionHistory = this.actionArr.map(({
89-
tid, inverse, equivalent, authorName, hash,
90+
tid, inverse, equivalent, hash,
9091
}) => ({
9192
tid,
92-
authorName,
9393
inverse: GraphLoadSave.stringifyAction(inverse),
9494
equivalent: GraphLoadSave.stringifyAction(equivalent),
9595
hash,
@@ -185,6 +185,7 @@ class GraphLoadSave extends GraphUndoRedo {
185185

186186
setGraphML(graphML) {
187187
graphMLParser(graphML).then((graphObject) => {
188+
console.log(graphObject);
188189
localStorageManager.save(this.id, graphObject);
189190
this.loadGraphFromLocalStorage();
190191
});

src/graph-builder/graphml/builder/graphML.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const graphML = ({
2-
nodes, edges, id, projectName, actionHistory, serverID, fileHandle, fileName,
2+
nodes, edges, id, projectName, authorName, actionHistory, serverID, fileHandle, fileName,
33
}) => ({
44
graphml: {
55
$: {
@@ -33,6 +33,7 @@ const graphML = ({
3333
serverID,
3434
fileHandle,
3535
fileName,
36+
authorName,
3637
},
3738
node: nodes,
3839
edge: edges,

src/graph-builder/graphml/builder/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const builder = (G) => {
3030
serverID: G.serverID,
3131
fileHandle: G.fileHandle,
3232
fileName: G.fileName,
33+
authorName: G.authorName,
3334
});
3435
const xml = new xml2js.Builder().buildObject(X);
3536
return xml;

src/graph-builder/graphml/parser/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ const parser = (graphMlCnt) => new Promise((resolve) => {
99
const grahML = new PropFromArr(grahMLObj);
1010
const nodes = grahML.parseProps('graphml.graph.node', 1).map(parseNode);
1111
const edges = grahML.parseProps('graphml.graph.edge', 1).map(parseEdge);
12-
const { id, projectName, serverID } = parseDetails(grahML);
12+
const {
13+
id, projectName, serverID, authorName,
14+
} = parseDetails(grahML);
1315
const actionHistory = parseActionHistory(grahML);
1416
resolve({
15-
id, projectName, edges, nodes, actionHistory, serverID,
17+
id, projectName, edges, nodes, actionHistory, serverID, authorName,
1618
});
1719
});
1820
});

src/graph-builder/graphml/parser/parseProperties.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ const parseActionML = (({ actionName, parameters }) => ({ actionName: actionName
4646

4747
const parseActionHistory = (grahML) => grahML.parseProps('graphml.graph.actionHistory', 1)
4848
.map(({
49-
authorName, equivalent, inverse, tid,
49+
equivalent, inverse, tid,
5050
}) => ({
51-
authorName: authorName[0],
51+
5252
equivalent: parseActionML(equivalent[0]),
5353
inverse: parseActionML(inverse[0]),
5454
tid: tid[0],

src/reducer/reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const reducer = (state, action) => {
9797
graphML: action.payload.graphML,
9898
fileHandle: action.payload.fileHandle || null,
9999
fileName: action.payload.fileName,
100-
authorName: action.payload.authorName,
100+
authorName: action.payload.authorName || '',
101101
},
102102
],
103103
};

src/toolbarActions/toolbarFunctions.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import parser from '../graph-builder/graphml/parser';
2+
import { parseDetails } from '../graph-builder/graphml/parser/parseProperties';
13
import { actionType as T } from '../reducer';
24

35
const getGraphFun = (superState) => superState.curGraphInstance;
@@ -108,11 +110,13 @@ const readFile = async (state, setState, file, fileHandle) => {
108110
const projectName = file.name;
109111
if (file.name.split('.').pop() === 'graphml') {
110112
fr.onload = (x) => {
111-
setState({
112-
type: T.ADD_GRAPH,
113-
payload: {
114-
projectName, graphML: x.target.result, fileHandle, fileName: file.name,
115-
},
113+
parser(x.target.result).then(({ authorName }) => {
114+
setState({
115+
type: T.ADD_GRAPH,
116+
payload: {
117+
projectName, graphML: x.target.result, fileHandle, fileName: file.name, authorName,
118+
},
119+
});
116120
});
117121
};
118122
if (fileHandle) fr.readAsText(await fileHandle.getFile());

0 commit comments

Comments
 (0)