1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-27 12:20:05 +02:00
copilot/legacy/spikes/graphs-topology/d3/client/topology.js
Sérgio Ramos 8295bd6882 chore: initial lerna setup
this shall be a progressive process
2017-05-25 10:56:50 +01:00

89 lines
1.9 KiB
JavaScript

const React = require('react');
const Styled = require('styled-components');
const TopologyGraph = require('./graph/topology-graph');
const data = require('./data');
const {
default: styled
} = Styled;
const StyledForm = styled.form`
margin: 20px;
`;
class Topology extends React.Component {
constructor(props) {
super(props)
//nasty
this.state = {
data: {
nodes: [
...data.nodes
],
links: [
...data.links
]
}
}
}
render() {
const {
} = this.props;
const nodeSize = {
width: 180,
height: 156
};
const onSubmit = (evt) => {
evt.preventDefault();
console.log('submit ', evt.target.service.value);
console.log('submit ', evt.target.link.value);
const service = evt.target.service.value;
const target = evt.target.link.value;
const data = this.state.data;
this.setState({
data: {
nodes: [
...data.nodes,
{
id: evt.target.service.value
}
],
links: [
...data.links,
{
source: service,
target: target
}
]
}
})
};
const options = data.nodes.map((n, index) => (
<option key={index} value={n.id}>{n.id}</option>
));
return (
<div>
<StyledForm onSubmit={onSubmit}>
<label>New service name</label>
<input name='service' type='text' placeholder='Service name' />
<label>Service to link to</label>
<select name='link'>
{ options }
</select>
<input type='submit' value='submit' />
</StyledForm>
<TopologyGraph data={this.state.data} nodeSize={nodeSize} />
</div>
);
}
};
module.exports = Topology;