16
16
import * as React from 'react' ;
17
17
import styled from 'styled-components' ;
18
18
import mapValues from '../../container/utils/mapValues' ;
19
- import { FlowChart , IChart , IConfig , IFlowChartComponents , IOnNodeClick , IOnNodeDoubleClick , IOnLabelDoubleClick , IOnLinkClick } from '../..' ;
19
+ import { FlowChart , IChart , IConfig , IFlowChartComponents , IOnNodeClick , IOnNodeDoubleClick , IOnLabelDoubleClick , IOnLinkClick , IOnTrustBoundaryClick , IOnDragTrustBoundary } from '../..' ;
20
20
import {
21
21
onDragNode , onDragCanvas , onLinkStart , onLinkMove , onLinkComplete ,
22
22
onLinkCancel , onLinkMouseEnter , onLinkMouseLeave ,
@@ -133,6 +133,7 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
133
133
...props . initialValue ,
134
134
preNodes : Object . keys ( props . initialValue . nodes ) ,
135
135
preLinks : Object . keys ( props . initialValue . links ) ,
136
+ preTrustBoundaries : Object . keys ( props . initialValue . trustBoundaries ) ,
136
137
isModelShow : false ,
137
138
showModelName : '' ,
138
139
nodeName : '' ,
@@ -146,10 +147,17 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
146
147
securityFeatures : [ ] ,
147
148
threats : [ ] ,
148
149
nodeRoleOption : '' ,
150
+ trustBoundaryName : '' ,
151
+ trustBoundaryId : '' ,
152
+ trustBoundaryDescription : '' ,
153
+ trustBoundaryOutOfScope : false ,
154
+ trustBoundaryOutOfScopeReason : '' ,
149
155
linkLabel : '' ,
150
156
newNodeId : '' ,
151
- clickNodeId : '' ,
152
157
newLinkId : '' ,
158
+ newTrustBoundaryId : '' ,
159
+ clickNodeId : '' ,
160
+ clickTrustBoundaryId : '' ,
153
161
clickLinkId : '' ,
154
162
modelOption : 'addNode' ,
155
163
alertMessageInfo : '' ,
@@ -247,6 +255,47 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
247
255
}
248
256
} ;
249
257
258
+ onTrustBoundaryClick : IOnTrustBoundaryClick = ( { trustBoundaryId } ) => {
259
+ console . log ( 'trustBoundaryId' , trustBoundaryId ) ;
260
+ let selectedTB = this . state . trustBoundaries [ trustBoundaryId ] ;
261
+ let tbProperties = ! ! selectedTB . properties ? selectedTB . properties : this . emptyProperties ;
262
+ if ( ! selectedTB . properties ) {
263
+ this . state . trustBoundaries [ trustBoundaryId ] . properties = this . emptyProperties ;
264
+ tbProperties = this . emptyProperties ;
265
+ }
266
+ this . setState ( {
267
+ selected : {
268
+ type : 'trustBoundary' ,
269
+ id : trustBoundaryId ,
270
+ } ,
271
+ linkLabel : '' ,
272
+ nodeName : '' ,
273
+ nodeId : '' ,
274
+ nodeDescription : '' ,
275
+ nodeOutOfScope : false ,
276
+ nodeOutOfScopeReason : '' ,
277
+ clickTrustBoundaryId : trustBoundaryId ,
278
+ clickNodeId : '' ,
279
+ clickLinkId : '' ,
280
+ } ) ;
281
+ if ( this . filterStatementsCallbaack ) {
282
+ this . filterStatementsCallbaack (
283
+ '' , //filterSTRIDE
284
+ trustBoundaryId ,
285
+ 'trustBoundary' , //selectedNode.type
286
+ tbProperties . name ,
287
+ tbProperties . description ,
288
+ tbProperties . outOfScope ,
289
+ tbProperties . outOfScopeReason ,
290
+ tbProperties . tags ,
291
+ [ ] , //tbProperties.dataFeatures
292
+ [ ] , //tbProperties.techFeatures
293
+ [ ] , //tbProperties.securityFeatures
294
+ [ ] , //tbProperties.threats
295
+ ) ;
296
+ } ;
297
+ } ;
298
+
250
299
onNodeDoubleClick : IOnNodeDoubleClick = ( { nodeId } ) => {
251
300
let clickNodeProperties = this . state . nodes [ nodeId ] . properties ;
252
301
clickNodeProperties = ! ! clickNodeProperties ? clickNodeProperties : { } ;
@@ -332,6 +381,10 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
332
381
} ) ;
333
382
} ;
334
383
384
+ onDragTrustBoundary : IOnDragTrustBoundary = ( { config } ) => {
385
+ console . log ( 'onDragTrustBoundary' , config ) ;
386
+ } ;
387
+
335
388
private stateActions = mapValues ( {
336
389
onDragNode,
337
390
onDragCanvas,
@@ -350,6 +403,8 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
350
403
onCanvasDrop,
351
404
onNodeDoubleClick : this . onNodeDoubleClick ,
352
405
onLabelDoubleClick : this . onLabelDoubleClick ,
406
+ onTrustBoundaryClick : this . onTrustBoundaryClick ,
407
+ onDragTrustBoundary : this . onDragTrustBoundary ,
353
408
} , ( func : any ) => ( ...args : any ) => this . setState ( func ( ...args ) ) ) ;
354
409
355
410
hideModel = ( ) => {
@@ -411,6 +466,12 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
411
466
} ) ;
412
467
} ;
413
468
469
+ handleTrustBoundaryNameInput = ( e : any ) => {
470
+ this . setState ( {
471
+ trustBoundaryName : e . currentTarget . value ,
472
+ } ) ;
473
+ } ;
474
+
414
475
setNodeInfo = ( ) : boolean => {
415
476
let nodeKey = '' ;
416
477
for ( var key of Object . keys ( this . state . nodes ) ) {
@@ -458,6 +519,33 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
458
519
} ) ;
459
520
} ;
460
521
522
+ setTrustBoundaryInfo = ( ) : boolean => {
523
+ let trustBoundaryKey = '' ;
524
+ for ( var key of Object . keys ( this . state . trustBoundaries ) ) {
525
+ if ( trustBoundaryKey !== '' && this . state . trustBoundaries [ key ] . position === this . state . trustBoundaries [ trustBoundaryKey ] . position ) {
526
+ delete this . state . trustBoundaries [ key ] ;
527
+ }
528
+ trustBoundaryKey = key ;
529
+ }
530
+
531
+ if ( this . state . trustBoundaryName . trim ( ) === '' ) {
532
+ this . warningMessage ( 'Please input the trust boundary name!' ) ;
533
+ return false ;
534
+ }
535
+ let _trustBoundaries = this . state . trustBoundaries ;
536
+ let _trustBoundaryId = this . state . modelOption === 'addTrustBoundary' ? this . state . newTrustBoundaryId : this . state . clickTrustBoundaryId ;
537
+ _trustBoundaries [ _trustBoundaryId ] . properties = {
538
+ name : ! ! this . state . trustBoundaryName ? this . state . trustBoundaryName : '' ,
539
+ Id : this . state . trustBoundaryId ,
540
+ description : this . state . trustBoundaryDescription ,
541
+ } ;
542
+ this . setState ( {
543
+ trustBoundaries : _trustBoundaries ,
544
+ isModelShow : false ,
545
+ } ) ;
546
+ return true ;
547
+ } ;
548
+
461
549
handleNodeRoleChange = ( value : string ) : void => {
462
550
this . setState ( {
463
551
nodeRoleOption : value ,
@@ -519,6 +607,25 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
519
607
) ;
520
608
} ;
521
609
610
+ renderAddNewTrustBoundaryModel = ( ) => {
611
+ return (
612
+ < ModelBox className = { this . state . isModelShow ? '' : 'hide' } >
613
+ < ModelContent >
614
+ < div className = "InputBox" >
615
+ < InputBox >
616
+ < label > Name:</ label >
617
+ < Input onChange = { this . handleTrustBoundaryNameInput } value = { this . state . trustBoundaryName } type = "text" />
618
+ </ InputBox >
619
+ </ div >
620
+ < ButtonBox >
621
+ < Button onClick = { this . setTrustBoundaryInfo } type = "primary" > Confirm</ Button >
622
+ < Button onClick = { this . hideModel } type = "cancel" > Cancel</ Button >
623
+ </ ButtonBox >
624
+ </ ModelContent >
625
+ </ ModelBox >
626
+ ) ;
627
+ } ;
628
+
522
629
warningMessage = ( content : string ) : void => {
523
630
this . setState ( ( ) => ( {
524
631
alertMessageInfo : content ,
@@ -548,6 +655,12 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
548
655
delete node . position . node ;
549
656
}
550
657
}
658
+ for ( var key of Object . keys ( flowData . trustBoundaries ) ) {
659
+ let trustBoundary = flowData . trustBoundaries [ key ] ;
660
+ if ( trustBoundary . position && trustBoundary . position . node ) {
661
+ delete trustBoundary . position . node ;
662
+ }
663
+ }
551
664
if ( ! ! this . props . getWorkFlowChartValue ) {
552
665
this . props . getWorkFlowChartValue ( flowData ) ;
553
666
}
@@ -598,6 +711,26 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
598
711
preNodes : Object . keys ( preState . nodes ) ,
599
712
} ) ) ;
600
713
}
714
+
715
+ if ( Object . keys ( this . state . trustBoundaries ) . length > this . state . preTrustBoundaries . length ) {
716
+ let preTrustBoundaries = this . state . preTrustBoundaries ;
717
+ let currentTrustBoundaries = Object . keys ( this . state . trustBoundaries ) ;
718
+ let newTrustBoundary = currentTrustBoundaries . filter ( trustBoundary => ! preTrustBoundaries . includes ( trustBoundary ) ) ;
719
+
720
+ this . setState ( {
721
+ isModelShow : true ,
722
+ showModelName : 'newTrustBoundaryModel' ,
723
+ modelOption : 'addTrustBoundary' ,
724
+ newTrustBoundaryId : newTrustBoundary [ 0 ] ,
725
+ trustBoundaryName : '' ,
726
+ trustBoundaryId : '' ,
727
+ } ) ;
728
+ }
729
+ if ( Object . keys ( this . state . trustBoundaries ) . length != this . state . preTrustBoundaries . length ) {
730
+ this . setState ( ( preState ) => ( {
731
+ preTrustBoundaries : Object . keys ( preState . trustBoundaries ) ,
732
+ } ) ) ;
733
+ }
601
734
}
602
735
603
736
public render ( ) {
@@ -607,6 +740,7 @@ class FlowChartWithState extends React.Component<IFlowChartWithStateProps, IChar
607
740
< React . Fragment >
608
741
{ this . state . showModelName === 'newNodeModel' ? this . renderAddNewNodeModel ( ) : '' }
609
742
{ this . state . showModelName === 'newLinkModel' ? this . renderAddNewLinkModel ( ) : '' }
743
+ { this . state . showModelName === 'newTrustBoundaryModel' ? this . renderAddNewTrustBoundaryModel ( ) : '' }
610
744
{ this . renderAlertMessage ( ) }
611
745
< FlowChart
612
746
chart = { this . state }
0 commit comments