fix frontend crash when node missing

This commit is contained in:
Tao Bror Bojlén 2019-11-21 19:44:27 +00:00
parent 30c5154d16
commit 3725a22c1c
No known key found for this signature in database
GPG key ID: C6EC7AAB905F9E6F
3 changed files with 14 additions and 3 deletions

View file

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
### Fixed
- Fixed frontend crash when instance node missing
### Security

View file

@ -57,8 +57,8 @@ config :backend, Backend.Repo,
pool_size: 10
config :backend, :crawler,
status_age_limit_days: 28,
status_count_limit: 1000,
status_age_limit_days: 14,
status_count_limit: 500,
personal_instance_threshold: 5,
crawl_interval_mins: 60,
crawl_workers: 10,

View file

@ -40,7 +40,7 @@ class Cytoscape extends React.PureComponent<ICytoscapeProps> {
this.cy = cytoscape({
autoungrabify: true,
container: container as any,
elements: this.props.elements,
elements: this.cleanElements(this.props.elements),
hideEdgesOnViewport: true,
hideLabelsOnViewport: true,
layout: {
@ -341,6 +341,16 @@ class Cytoscape extends React.PureComponent<ICytoscapeProps> {
}
this.cy.edges().addClass("hidden");
};
/* Helper function to remove edges if source or target node is missing */
private cleanElements = (elements: cytoscape.ElementsDefinition): cytoscape.ElementsDefinition => {
const domains = new Set(elements.nodes.map(n => n.data.id));
const edges = elements.edges.filter(e => domains.has(e.data.source) && domains.has(e.data.target));
return {
edges,
nodes: elements.nodes
};
};
}
export default Cytoscape;