Commit 1c69dcaa authored by Aron Fiechter's avatar Aron Fiechter
Browse files

Add some safety operators

parent f3a54801
......@@ -67,7 +67,7 @@ export const performQuery = (query) => async (dispatch) => {
.finally(() => dispatch(setLoading(false)));
};
export const selectQuery = (state) => state.query.result.query;
export const selectQuery = (state) => state.query.result?.query;
export const selectResult = (state) => state.query.result;
export const selectError = (state) => state.query.error;
export const selectResultsById = (state) => state.query.result?.mapById;
......
......@@ -4,7 +4,7 @@ import Container from 'react-bootstrap/Container';
import { useSelector } from 'react-redux';
export default function QueryResult(props) {
const { nResults } = useSelector(selectResult);
const nResults = useSelector(selectResult)?.nResults;
const query = useSelector(selectQuery);
const allDataText = query?.fields?.find((f) => f.key === 'allData')?.value;
const queryText = allDataText || query?.fields?.find((f) => f.value)?.value;
......
......@@ -115,7 +115,7 @@ class Voronoi extends React.Component {
P: d3.hsl('#f2a007'),
};
let colors = {};
rootData.nodes.forEach((node) => {
(rootData?.nodes || []).forEach((node) => {
if (node.level === 0) return;
let fullNode = this.props.resultsById[node.name];
......@@ -144,7 +144,7 @@ class Voronoi extends React.Component {
select(this.voronoiSvg).selectAll('g').remove();
const diagram = select(this.voronoiSvg).append('g');
const currentData = rootData.nodes.filter((node) => node.level <= 1);
const currentData = rootData?.nodes?.filter((node) => node.level <= 1) || [];
const xScale = scaleLinear().range([padding, width - padding]);
const yScale = scaleLinear().range([height - padding, padding]);
......@@ -157,9 +157,9 @@ class Voronoi extends React.Component {
const maxNesting = Math.max.apply(
Math,
rootData.nodes.map(function (o) {
rootData?.nodes?.map(function (o) {
return o.level;
}),
}) || [0],
);
const strokeScale = scaleLinear().range([7, 2]).domain([0, maxNesting]);
......@@ -511,8 +511,8 @@ class Voronoi extends React.Component {
render() {
const { width, height } = this.props;
return (
<div className='pt-sm-0 pb-sm-3'>
<Container id='voronoi-treemap'>
<div className="pt-sm-0 pb-sm-3">
<Container id="voronoi-treemap">
<Row>
<Col xs={7}>
<svg
......
......@@ -7,7 +7,7 @@ import Card from 'react-bootstrap/Card';
export default function Tooltip() {
const hoverSiteId = useSelector(selectHoverSite);
const resultsById = useSelector(selectResultsById);
const resultsById = useSelector(selectResultsById) || {};
const hoverNode = resultsById[hoverSiteId] || null;
return (
......
......@@ -22,7 +22,7 @@ export default function YearRange() {
// Create data for chart and store it in redux
useEffect(() => {
logger.debug('YearRange: creating year counts for chart');
const yearCounts = nodes
const yearCounts = (nodes || [])
.filter((n) => n.leaf)
.map((n) => resultsById[n.name])
.filter((n) => n)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment