-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy patheditor.js
700 lines (586 loc) · 27.3 KB
/
editor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
import _ from 'lodash';
import { getTemplate } from '../templates/Templates';
import { normalizeType, cleanString } from '../utils/stringUtils';
import { CURRENT_GMF_VERSION } from './analysis'
const initialState = {
selectedStateKey: null,
selectedStateTransition: null,
selectedModuleKey: null,
loadModuleVisible: false,
downloadVisible: false,
selectedModulePanel: 'info',
modulePanelVisible: true,
modules: {},
history: [],
clipboard: null,
historyIndex: -1,
refreshCodeFlag: false
};
export default (state = initialState, action) => {
let newState = {...state}
switch (action.type) {
case 'ADD_GMF_VERSION':
newState.modules[action.data.targetModuleKey]['gmf_version'] = CURRENT_GMF_VERSION;
return newState;
case 'SELECT_NODE':
let selectedModulePanel = state.selectedModulePanel;
if(action.data.key){
if(selectedModulePanel === 'info' || state.selectedStateKey === action.data.key){ // if on info or a 'double click'
selectedModulePanel = 'state';
}
} else {
if(selectedModulePanel === 'state'){
selectedModulePanel = 'info';
}
}
newState = { ...newState, selectedModulePanel, selectedStateKey: action.data.key, selectedStateTransition: action.data.transitionIndex};
// special case where we just want to reflect the selection change in the current history
newState.history = [...newState.history]
newState.history[0] = {...newState.history[0], selectedStateKey: action.data.key, selectedStateTransition: action.data.transitionIndex};
return newState;
case 'COPY_NODE':
// let newStateName = action.data.newName;
// let newModuleState = _.cloneDeep(newModuleCopy.states[action.data.targetNode.name]);
// newModuleState.name = newStateName;
// /* fix loopback transition case */
// renameLoopbackTransition(newModuleState, newStateName, action.data.targetNode.name);
// newModuleCopy.states[newStateName] = newModuleState;
// newState.modules[action.data.targetModuleKey] = newModuleCopy
// newState.selectedStateKey = action.data.newName;
// newState.selectedStateTransition = null;
newState.clipboard = _.cloneDeep(state.modules[action.data.targetModuleKey].states[action.data.targetNode.name])
// saveHistory(newState);
return newState
case 'ADD_NODE':
newState.modules = {...newState.modules}
newState.modules[action.data.currentModuleKey].states = {...newState.modules[action.data.currentModuleKey].states, [action.data.stateKey]:action.data.state};
if(action.data.selectedState && typeof action.data.selectedStateTransition === 'number'){
// We have been instructed to insert into the middle of an existing transition
let alteredState = _.cloneDeep(newState.modules[action.data.currentModuleKey].states[action.data.selectedState]);
if(alteredState.direct_transition && action.data.selectedStateTransition === 0 ){
let oldTransitionPoint = alteredState.direct_transition;
alteredState.direct_transition = action.data.stateKey;
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].direct_transition = oldTransitionPoint;
newState.modules[action.data.currentModuleKey].states[action.data.selectedState] = alteredState;
} else if(alteredState.distributed_transition){
let oldTransitionPoint = alteredState.distributed_transition[action.data.selectedStateTransition].transition;
alteredState.distributed_transition = [...alteredState.distributed_transition]
alteredState.distributed_transition[action.data.selectedStateTransition] = {...alteredState.distributed_transition[action.data.selectedStateTransition], transition: action.data.stateKey}
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].direct_transition = oldTransitionPoint;
newState.modules[action.data.currentModuleKey].states[action.data.selectedState] = alteredState;
} else if(alteredState.lookup_table_transition){
let oldTransitionPoint = alteredState.lookup_table_transition[action.data.selectedStateTransition].transition;
alteredState.lookup_table_transition = [...alteredState.lookup_table_transition]
alteredState.lookup_table_transition[action.data.selectedStateTransition] = {...alteredState.lookup_table_transition[action.data.selectedStateTransition], transition: action.data.stateKey}
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].direct_transition = oldTransitionPoint;
newState.modules[action.data.currentModuleKey].states[action.data.selectedState] = alteredState;
} else if(alteredState.conditional_transition){
let oldTransitionPoint = alteredState.conditional_transition[action.data.selectedStateTransition].transition;
alteredState.conditional_transition = [...alteredState.conditional_transition]
alteredState.conditional_transition[action.data.selectedStateTransition] = {...alteredState.conditional_transition[action.data.selectedStateTransition], transition: action.data.stateKey}
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].direct_transition = oldTransitionPoint;
newState.modules[action.data.currentModuleKey].states[action.data.selectedState] = alteredState;
} else if(alteredState.complex_transition){
alteredState = {...alteredState, complex_transition: _.cloneDeep(alteredState.complex_transition)};
let complexTransitions = {}
let transitionIndex = 0;
let rightNode = null;
alteredState.complex_transition.forEach( (t, i) => {
if(t.transition !== undefined){
let nodes = t.transition;
if(complexTransitions[nodes] === undefined){
complexTransitions[nodes] = true;
if(transitionIndex === action.data.selectedStateTransition || nodes === rightNode){
rightNode = nodes;
let oldTransitionPoint = t.transition;
t.transition = action.data.stateKey;
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].direct_transition = oldTransitionPoint;
}
transitionIndex++;
} else if(nodes === rightNode){
let oldTransitionPoint = t.transition;
t.transition = action.data.stateKey;
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].direct_transition = oldTransitionPoint;
}
} else {
t.distributions.forEach( dist => {
let nodes = dist.transition;
if(complexTransitions[nodes] === undefined){
complexTransitions[nodes] = true;
if(transitionIndex === action.data.selectedStateTransition){
rightNode = nodes;
let oldTransitionPoint = dist.transition;
dist.transition = action.data.stateKey;
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].direct_transition = oldTransitionPoint;
}
transitionIndex++;
} else if(nodes == rightNode){
let oldTransitionPoint = dist.transition;
dist.transition = action.data.stateKey;
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].direct_transition = oldTransitionPoint;
}
})
}
})
newState.modules[action.data.currentModuleKey].states[action.data.selectedState] = alteredState;
}
newState.selectedStateTransition = 0;
} else if(action.data.selectedState){
// we have selected a state, so we will add it AFTER
let alteredState = _.cloneDeep(newState.modules[action.data.currentModuleKey].states[action.data.selectedState]);
delete newState.modules[action.data.currentModuleKey].states[action.data.stateKey]['direct_transition']
delete newState.modules[action.data.currentModuleKey].states[action.data.stateKey]['conditional_transition']
delete newState.modules[action.data.currentModuleKey].states[action.data.stateKey]['distributed_transition']
delete newState.modules[action.data.currentModuleKey].states[action.data.stateKey]['complex_transition']
delete newState.modules[action.data.currentModuleKey].states[action.data.stateKey]['lookup_table_transition']
if(alteredState.direct_transition){
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].direct_transition = alteredState.direct_transition;
} else if(alteredState.distributed_transition){
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].distributed_transition = _.cloneDeep(alteredState.distributed_transition);
delete alteredState['distributed_transition']
} else if(alteredState.lookup_table_transition){
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].lookup_table_transition = _.cloneDeep(alteredState.lookup_table_transition);
delete alteredState['lookup_table_transition']
} else if(alteredState.conditional_transition){
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].conditional_transition = _.cloneDeep(alteredState.conditional_transition);
delete alteredState['conditional_transition']
} else if(alteredState.complex_transition){
newState.modules[action.data.currentModuleKey].states[action.data.stateKey].complex_transition = _.cloneDeep(alteredState.complex_transition);
delete alteredState['complex_transition']
}
alteredState.direct_transition = action.data.stateKey;
newState.modules[action.data.currentModuleKey].states[action.data.selectedState] = alteredState;
}
newState.selectedStateKey = action.data.stateKey;
newState.selectedModulePanel= 'state';
newState.selectedStateTransition = null;
saveHistory(newState);
return newState;
case 'INSERT_NODE':
newState.modules = {...newState.modules}
newState.modules[action.data.currentModuleKey].states = {...newState.modules[action.data.currentModuleKey].states, [action.data.stateKey]:action.data.state};
newState.selectedStateKey = action.data.stateKey;
newState.selectedModulePanel= 'state';
newState.selectedStateTransition = null;
saveHistory(newState);
return {...newState};
case 'ADD_STRUCTURE':
newState.modules[action.data.currentModuleKey].states = {...newState.modules[action.data.currentModuleKey].states, ...getTemplate(`Structure.${action.data.structureName}`)};
newState.selectedStateTransition = null;
saveHistory(newState);
return {...newState}
case 'OPEN_MODULE':
let selectedModuleKey = state.selectedModuleKey;
selectedModuleKey = action.data.key
if(action.data.libraryModule){
delete newState.modules[action.data.key];
let newModule = {}
newModule[action.data.key] = _.cloneDeep(action.data.libraryModule);
newState.modules = {...newModule, ...newState.modules}
}
if(!newState.modules[action.data.key]){
selectedModuleKey = null;
}
newState.selectedModuleKey = selectedModuleKey;
newState.selectedStateKey = null;
newState.selectStateTransition = null;
newState.loadModuleVisible = false;
newState.history = [];
newState.historyIndex = 0;
newState.selectedModulePanel = 'info';
saveHistory(newState);
return { ...newState };
case 'NEW_MODULE':
let newModules = {...state.modules}
delete newModules[action.data.key]
let tempModule = {}; // put in the right order in the object for the tabs
tempModule[action.data.key] = action.data.module;
newState.history = [];
newState.historyIndex = 0;
saveHistory(newState);
return {...newState, modules: {...tempModule, ...newModules}, selectedStateKey: null, selectedStateTransition: null, selectedModuleKey: action.data.key}
case 'JSON_EDIT':
newState.modules = {...newState.modules}
newState.modules[state.selectedModuleKey] = _.cloneDeep(action.data.module);
saveHistory(newState);
return {...newState};
case 'EDIT_NODE':
let path = action.data.path.join('.');
let value = Object.values(action.data.update)[0]
if(typeof value === 'object') {
value = value.id;
}
if(value !== null && value !== undefined) {
_.set(newState.modules, path, normalizeType(value));
// FIX DEPENDENT THINGS
let splitPath = []
if(Array.isArray(path)){
splitPath = path.join('.').split('.')
} else {
splitPath = path.split('.')
}
// If change operator on attribute, clean up value if needed
if(splitPath[splitPath.length-1] === 'operator'){
const parent = _.get(newState.modules, splitPath.slice(0,-1).join('.'));
if((parent.operator === 'is nil' || parent.operator === 'is not nil')){
_.unset(newState.modules, splitPath.slice(0,-1).join('.') + '.value')
} else {
if(parent.operator.value === undefined){
_.set(newState.modules, splitPath.slice(0,-1).join('.') + '.value', 0)
}
}
}
}
else{
_.unset(newState.modules, path);
let parent = [...action.data.path].splice(0, action.data.path.length -1).join(".");
if (action.data.path[2] == 'lookup_table_transition'){
parent += '.transitions'
}
let newVal = _.get(newState.modules, parent);
if(Array.isArray(newVal)) {
_.set(newState.modules, parent, newVal.filter(x => x));
}
// check to see if it is a node deletion, in which case we need to references
let splitPath = []
if(Array.isArray(path)){
splitPath = path.join('.').split('.')
} else {
splitPath = path.split('.')
}
if(splitPath.length === 3 && splitPath[1] === 'states'){
let stateName = splitPath[2]
fixStateReferences(newState.modules[splitPath[0]], stateName, null)
if(splitPath[2] == newState.selectedStateKey){
newState.selectedStateKey = null; // deleselect
}
}
}
saveHistory(newState);
return newState
case 'ADD_TRANSITION':
let transitionMapping = {
Conditional: 'conditional_transition',
Distributed: 'distributed_transition',
Direct: 'direct_transition',
Complex: 'complex_transition',
Table: 'lookup_table_transition',
};
let transitionName = transitionMapping[action.data.transitionType];
let oldTransitionName = null;
if (action.data.nodeName.transition != null) {
oldTransitionName = transitionMapping[action.data.nodeName.transition.type];
}
let paths = Object.values(transitionMapping);
for (var pathIndex in paths) {
delete newState.modules[action.data.currentModuleKey].states[action.data.nodeName.name][paths[pathIndex]];
}
newState.modules[action.data.currentModuleKey].states[action.data.nodeName.name][transitionName] = getTemplate(`Transition.${action.data.transitionType}`);
// Get first of previous transition locations if available
let transitionTo = null;
switch(oldTransitionName) {
case 'direct_transition':
transitionTo = _.get(action, 'data.nodeName.transition.to', null);
break;
case 'distributed_transition':
case 'conditional_transition':
transitionTo = _.get(action, 'data.nodeName.transition.transition[0].to', null);
break;
case 'complex_transition':
transitionTo = _.get(action, 'data.nodeName.transition.transition[0].distributions[0].to', null);
break;
case 'lookup_table_transition':
transitionTo = _.get(action, 'data.nodeName.transition.transitions.transition[0].to', null);
break;
}
// Provide previous transition location to new if available
if (transitionTo !== null) {
switch(transitionName) {
case 'direct_transition':
newState.modules[action.data.currentModuleKey].states[action.data.nodeName.name][transitionName] = transitionTo;
break;
case 'distributed_transition':
case 'conditional_transition':
newState.modules[action.data.currentModuleKey].states[action.data.nodeName.name][transitionName][0].transition = transitionTo;
break;
case 'complex_transition':
newState.modules[action.data.currentModuleKey].states[action.data.nodeName.name][transitionName][0].distributions[0].transition = transitionTo;
break;
case 'lookup_table_transition':
newState.modules[action.data.currentModuleKey].states[action.data.nodeName.name][transitionName].transitions[0].transition = transitionTo;
break;
}
}
saveHistory(newState);
return newState
case 'RENAME_NODE':
let stateName = action.data.targetNode.name;
let newName = action.data.newName.name;
let newModule = _.cloneDeep(state.modules[action.data.targetModuleKey])
let moduleState = newModule.states[stateName]
if(moduleState === undefined){
// if we can't find it, then it might be a blank state (Unnamed state)
// Check in the blank key
moduleState = newModule.states[""]
stateName = ""
}
if(moduleState === undefined){
// If we still can't find the state, let's just hop out of here.
return newState;
}
delete newModule.states[stateName];
moduleState.name = newName
newModule.states[newName] = moduleState
fixStateReferences(newModule, stateName, newName);
newState.modules[action.data.targetModuleKey] = newModule;
newState.selectedStateKey = action.data.newName.name;
saveHistory(newState);
return newState
case 'EDIT_MODULE_NAME':
newState.modules[action.data.targetModuleKey].name = action.data.newName;
saveHistory(newState);
return newState;
case 'EDIT_MODULE_REMARKS':
newState.modules[action.data.targetModuleKey].remarks = action.data.newRemarks ? action.data.newRemarks.split("\n") : null;
if(newState.modules[action.data.targetModuleKey].remarks === null){
delete newState.modules[action.data.targetModuleKey].remarks;
}
saveHistory(newState);
return newState;
case 'CHANGE_STATE_TYPE':
let newType = action.data.newType.type.id;
// This line is weird because we need to add the new fields, overwrite any shared fields, then overwrite the type fields
// TODO figure out how to remove unused fields
newState.modules[action.data.targetModuleKey].states[action.data.targetNode.name] =
{ ...getTemplate(`State.${newType}`),
..._.pick(newState.modules[action.data.targetModuleKey].states[action.data.targetNode.name], ['direct_transition', 'conditional_transition', 'distributed_transition', 'complex_transition', 'lookup_table_transition', 'remarks']),
type: getTemplate(`State.${newType}`).type
};
saveHistory(newState);
return newState
case 'LOAD_JSON':
newState.history = []
newState.historyIndex = 0;
saveHistory(newState);
return { ...newState, selectedModuleKey: action.data.selectedModuleKey, selectedStateKey: null, selectedStateTransition: null};
case 'CLOSE_MODULE':
delete newState.modules[action.data.selectedModuleKey];
newState.history = []
newState.historyIndex = 0;
saveHistory(newState);
return { ...newState};
case 'SHOW_LOAD_MODULE':
return { ...newState, loadModuleVisible: true};
case 'HIDE_LOAD_MODULE':
return { ...newState, loadModuleVisible: false};
case 'SHOW_DOWNLOAD':
return { ...newState, downloadVisible: true};
case 'HIDE_DOWNLOAD':
return { ...newState, downloadVisible: false};
case 'CHANGE_MODULE_PANEL':
return { ...newState, selectedModulePanel: action.data.targetPanel, modulePanelVisible: action.data.targetPanel !== 'hide'};
case 'REFRESH_CODE_FLAG':
return {...newState, refreshCodeFlag: action.data.flag}
case 'UNDO':
if(newState.history.length > newState.historyIndex + 1){
newState.historyIndex++;
newState.modules = {...newState.modules}
newState.modules[newState.selectedModuleKey] = _.cloneDeep(newState.history[newState.historyIndex].module);
newState.selectedStateKey = newState.history[newState.historyIndex].selectedStateKey;
newState.selectedStateTransition = newState.history[newState.historyIndex].selectedStateTransition;
}
return {...newState}
case 'REDO':
if(newState.historyIndex > 0){
newState.historyIndex--;
newState.modules = {...newState.modules}
newState.modules[newState.selectedModuleKey] = _.cloneDeep(newState.history[newState.historyIndex].module);
newState.selectedStateKey = newState.history[newState.historyIndex].selectedStateKey;
newState.selectedStateTransition = newState.history[newState.historyIndex].selectedStateTransition;
}
return {...newState}
default:
return newState;
}
}
// updates the module in-place with fixed state refences
// if newName is null, then delete all references instead
const fixStateReferences = (module, stateName, newName) => {
Object.keys(module.states).map(s => module.states[s]).forEach( state => {
if(state.direct_transition === stateName){
if(newName === null){
delete state.direct_transition
} else {
state.direct_transition = newName
}
} else if (state.distributed_transition){
state.distributed_transition.forEach( transition => {
if(transition.transition === stateName){
if(newName === null){
delete transition.transition
} else {
transition.transition = newName
}
}
})
} else if (state.lookup_table_transition){
state.lookup_table_transition.transitions.forEach( transition => {
if(transition.transition === stateName){
if(newName === null){
delete transition.transition
} else {
transition.transition = newName
}
}
})
} else if (state.conditional_transition){
state.conditional_transition.forEach( transition => {
if(transition.transition === stateName){
if(newName === null){
delete transition.transition
} else {
transition.transition = newName
}
}
if(transition.condition){
if(transition.condition.condition_type === 'PriorState' && transition.condition.name === stateName){
if(newName === null){
delete transition.condition.name
} else {
transition.condition.name = newName
}
}
}
})
} else if (state.complex_transition){
state.complex_transition.forEach( transition => {
if(transition.transition === stateName){
if(newName === null){
delete transition.transition
} else {
transition.transition = newName
}
}
if(transition.condition){
if(transition.condition.condition_type === 'PriorState' && transition.condition.name === stateName){
if(newName === null) {
delete transition.condition.name
} else {
transition.condition.name = newName
}
}
}
if(transition.distributions){
transition.distributions.forEach( distribution => {
if(distribution.transition === stateName){
if(newName === null){
delete distribution.transition
} else {
distribution.transition = newName
}
}
})
}
})
}
if(state.reason === stateName){
if(newName === null){
delete state.reason
} else {
state.reason = newName;
}
}
if(state.target_encounter === stateName){
if(newName === null){
state.target_encounter = "" // this is a requried field
} else {
state.target_encounter = newName;
}
}
if(state.condition_onset === stateName){
if(newName === null){
delete state.condition_onset
} else {
state.condition_onset = newName;
}
}
if(state.allergy_onset === stateName){
if(newName === null){
delete state.allergy_onset
} else {
state.allergy_onset = newName;
}
}
if(state.medication_order === stateName){
if(newName === null){
delete state.medication_order
} else {
state.medication_order = newName;
}
}
if(state.careplan === stateName){
if(newName === null){
delete state.careplan;
} else {
state.careplan = newName;
}
}
if(state.allow && state.allow.condition_type === 'PriorState' && state.allow.name === stateName){
if(newName === null){
delete state.allow.name
} else {
state.allow.name = newName;
}
}
});
}
const saveHistory = (state) => {
let selectedStateKey = state.selectedStateKey;
let selectedStateTransition = state.selectedStateTransition;
if(state.historyIndex > 0){
while(state.historyIndex > 0 && state.history.length > 0){
state.historyIndex--;
state.history.shift()
}
state.historyIndex = 0; // should always be 0 anyhow
}
state.history = [{selectedStateKey, selectedStateTransition, module: _.cloneDeep(state.modules[state.selectedModuleKey])}].concat(state.history);
state.history.splice(20) // only save the last 20 changes
}
// When nodes are cloned, loopback transitions point to node being cloned, instead of new copy
const renameLoopbackTransition = (state, newStateName, oldStateName) => {
if(state.direct_transition === oldStateName){
state.direct_transition = newStateName;
} else if (state.distributed_transition){
state.distributed_transition.forEach( transition => {
if(transition.transition === oldStateName){
transition.transition = newStateName
}
})
} else if (state.lookup_table_transition){
state.lookup_table_transition.forEach( transition => {
if(transition.transition === oldStateName){
transition.transition = newStateName
}
})
} else if (state.conditional_transition){
state.conditional_transition.forEach( transition => {
if(transition.transition === oldStateName){
transition.transition = newStateName
}
})
} else if (state.complex_transition){
state.complex_transition.forEach( transition => {
if(transition.transition === oldStateName){
transition.transition = newStateName
}
if(transition.distributions){
transition.distributions.forEach( distribution => {
if(distribution.transition === oldStateName){
distribution.transition = newStateName
}
})
}
})
}
}