-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend] Graph is now working (#34)
- Loading branch information
Samuel Hassine
committed
Oct 21, 2019
1 parent
62c0786
commit a2eb2b4
Showing
18 changed files
with
479 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
opencti-platform/opencti-front/src/components/graph_node/SimpleLabelFactory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import * as SRD from 'storm-react-diagrams'; | ||
import SimpleLabelWidget from './SimpleLabelWidget'; | ||
import SimpleLabelModel from './SimpleLabelModel'; | ||
|
||
export default class SimpleLabelFactory extends SRD.AbstractLabelFactory { | ||
constructor() { | ||
super('simple'); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
generateReactWidget(diagramEngine, label) { | ||
return <SimpleLabelWidget model={label} />; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
getNewInstance() { | ||
return new SimpleLabelModel(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
opencti-platform/opencti-front/src/components/graph_node/SimpleLabelModel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { LabelModel } from 'storm-react-diagrams'; | ||
import { mergeRight } from 'ramda'; | ||
|
||
export default class SimpleLabelModel extends LabelModel { | ||
constructor() { | ||
super('simple'); | ||
this.offsetY = -23; | ||
this.selected = false; | ||
this.extras = null; | ||
} | ||
|
||
setLabel(label) { | ||
this.label = label; | ||
} | ||
|
||
setExtras(extras) { | ||
this.extras = extras; | ||
} | ||
|
||
deSerialize(ob, engine) { | ||
super.deSerialize(ob, engine); | ||
this.extras = ob.extras; | ||
} | ||
|
||
serialize() { | ||
return mergeRight(super.serialize(), { | ||
label: this.label, | ||
extras: this.extras, | ||
}); | ||
} | ||
|
||
isSelected() { | ||
return this.selected; | ||
} | ||
|
||
setSelected(selected) { | ||
this.selected = selected; | ||
this.props.model.parent.iterateListeners((listener, event) => { | ||
if (listener.selectionChanged) { | ||
listener.selectionChanged({ | ||
...event, | ||
openEdit: true, | ||
inferred: this.props.model.parent.inferred, | ||
isSelected: selected, | ||
}); | ||
} | ||
}); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
opencti-platform/opencti-front/src/components/graph_node/SimpleLabelWidget.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { Component } from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
import { compose, head } from 'ramda'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import inject18n from '../i18n'; | ||
|
||
const styles = () => ({ | ||
item: { | ||
textAlign: 'center', | ||
padding: '5px 8px 5px 8px', | ||
backgroundColor: '#14262c', | ||
color: '#ffffff', | ||
pointerEvents: 'auto', | ||
cursor: 'pointer', | ||
fontSize: 12, | ||
'&:hover': { | ||
background: '#1e3f49', | ||
}, | ||
position: 'relative', | ||
zIndex: 1500, | ||
}, | ||
}); | ||
|
||
class SimpleLabelWidget extends Component { | ||
render() { | ||
const { | ||
t, | ||
nsd, | ||
classes, | ||
model, | ||
model: { extras }, | ||
} = this.props; | ||
const label = head(extras); | ||
if (extras.length === 1) { | ||
return ( | ||
<div | ||
className={classes.item} | ||
onClick={model.setSelected.bind(this, true)} | ||
> | ||
<strong>{t(`relation_${label.relationship_type}`)}</strong> | ||
{label.inferred === true ? ( | ||
<span> | ||
<br /> | ||
<em>{t('Inferred')}</em> | ||
</span> | ||
) : ( | ||
'' | ||
)} | ||
{label.first_seen ? ( | ||
<span> | ||
<br /> | ||
{nsd(label.first_seen)} | ||
<br /> | ||
{nsd(label.last_seen)} | ||
</span> | ||
) : ( | ||
'' | ||
)} | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div className={classes.item}> | ||
<strong>{t(`relation_${label.relationship_type}`)}</strong> | ||
<span> | ||
<br /> | ||
<em> | ||
{extras.length} {t('relations')} | ||
</em> | ||
</span> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
SimpleLabelWidget.propTypes = { | ||
model: PropTypes.object, | ||
classes: PropTypes.object, | ||
t: PropTypes.func, | ||
nsd: PropTypes.func, | ||
}; | ||
|
||
export default compose( | ||
inject18n, | ||
withStyles(styles), | ||
)(SimpleLabelWidget); |
37 changes: 37 additions & 0 deletions
37
opencti-platform/opencti-front/src/components/graph_node/SimpleLinkFactory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import * as SRD from 'storm-react-diagrams'; | ||
import SimpleLinkModel from './SimpleLinkModel'; | ||
|
||
export default class SimpleLinkFactory extends SRD.AbstractLinkFactory { | ||
constructor() { | ||
super('simple'); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
generateReactWidget(diagramEngine, link) { | ||
return React.createElement(SRD.DefaultLinkWidget, { | ||
link, | ||
diagramEngine, | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
getNewInstance() { | ||
return new SimpleLinkModel(); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
generateLinkSegment(model, widget, selected, path) { | ||
const classNameNotInferred = selected ? widget.bem('--path-selected') : ''; | ||
return ( | ||
<path | ||
className={ | ||
model.inferred ? widget.bem('--path-inferred') : classNameNotInferred | ||
} | ||
strokeWidth={model.width} | ||
stroke={model.color} | ||
d={path} | ||
/> | ||
); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
opencti-platform/opencti-front/src/components/graph_node/SimpleLinkModel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { LinkModel } from 'storm-react-diagrams'; | ||
import { mergeRight } from 'ramda'; | ||
import SimpleLabelModel from './SimpleLabelModel'; | ||
|
||
export default class SimpleLinkModel extends LinkModel { | ||
constructor(type = 'simple') { | ||
super(type); | ||
this.color = '#00bcd4'; | ||
this.width = 3; | ||
this.curvyness = 50; | ||
this.inferred = false; | ||
} | ||
|
||
serialize() { | ||
return mergeRight(super.serialize(), { | ||
width: this.width, | ||
color: this.color, | ||
curvyness: this.curvyness, | ||
inferred: this.inferred, | ||
}); | ||
} | ||
|
||
deSerialize(ob, engine) { | ||
super.deSerialize(ob, engine); | ||
this.color = ob.color; | ||
this.width = ob.width; | ||
this.curvyness = ob.curvyness; | ||
this.inferred = ob.inferred; | ||
} | ||
|
||
addLabel(label) { | ||
if (label instanceof SimpleLabelModel) { | ||
return super.addLabel(label); | ||
} | ||
const labelOb = new SimpleLabelModel(); | ||
labelOb.setLabel(label); | ||
return super.addLabel(labelOb); | ||
} | ||
|
||
setWidth(width) { | ||
this.width = width; | ||
this.iterateListeners((listener, event) => { | ||
if (listener.widthChanged) { | ||
listener.widthChanged({ ...event, width }); | ||
} | ||
}); | ||
} | ||
|
||
setColor(color) { | ||
this.color = color; | ||
this.iterateListeners((listener, event) => { | ||
if (listener.colorChanged) { | ||
listener.colorChanged({ ...event, color }); | ||
} | ||
}); | ||
} | ||
|
||
setExtras(extras) { | ||
this.extras = extras; | ||
} | ||
|
||
setLabel(label) { | ||
this.labels = []; | ||
if (label instanceof SimpleLabelModel) { | ||
return super.addLabel(label); | ||
} | ||
const labelOb = new SimpleLabelModel(); | ||
labelOb.setLabel(label); | ||
return super.addLabel(labelOb); | ||
} | ||
|
||
setInferred(inferred) { | ||
this.inferred = inferred; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.