Skip to content

Commit e01d9ba

Browse files
committed
Validate recharts data
1 parent b75aa26 commit e01d9ba

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

client/src/views/CommonCharts/DonutChart/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { isNotDefined } from '@togglecorp/fujs';
34

45
import {
56
PieChart,
@@ -15,7 +16,7 @@ const CustomTooltip = ({ active, payload }) => {
1516
if (!active) {
1617
return null;
1718
}
18-
if (payload.length <= 0) {
19+
if (isNotDefined(payload) || payload.length <= 0) {
1920
return null;
2021
}
2122

@@ -47,7 +48,8 @@ export default function DonutChart(props) {
4748
donutChartWidth,
4849
} = props;
4950

50-
if (data.length <= 0) {
51+
52+
if (isNotDefined(data) || data.length <= 0) {
5153
return (
5254
<div>
5355
Nothings to show.

client/src/views/Dashboard/GroupedBarChart/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { isNotDefined } from '@togglecorp/fujs';
34

45
import {
56
BarChart,
@@ -9,7 +10,6 @@ import {
910
Tooltip,
1011
Legend,
1112
ResponsiveContainer,
12-
LabelList,
1313
} from 'recharts';
1414

1515
function CustomizedLabel(props) {
@@ -20,7 +20,7 @@ function CustomizedLabel(props) {
2020
x={x + width / 2.75}
2121
y={y}
2222
dy={-8}
23-
fontSize="12"
23+
fontSize={12}
2424
>
2525
{value}
2626
</text>
@@ -32,7 +32,7 @@ export default function GroupedBarChart(props) {
3232
data,
3333
} = props;
3434

35-
if (data.values.length <= 0) {
35+
if (isNotDefined(data) || isNotDefined(data.values) || data.values.length <= 0) {
3636
return (
3737
<div>Nothing to show</div>
3838
);

client/src/views/Report/GroupedBarChart.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { isNotDefined } from '@togglecorp/fujs';
34

45
import {
56
BarChart,
@@ -18,7 +19,7 @@ export default function GroupedBarChart(props) {
1819
} = props;
1920

2021

21-
if (data.values.length <= 0) {
22+
if (isNotDefined(data) || isNotDefined(data.values) || data.values.length <= 0) {
2223
return (
2324
<div>Nothing to show</div>
2425
);

client/src/views/Report/HorizontalBar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { isNotDefined } from '@togglecorp/fujs';
34

45
import {
56
BarChart,
@@ -18,7 +19,7 @@ export default function HorizontalBar(props) {
1819
colorScheme,
1920
} = props;
2021

21-
if (data.length <= 0) {
22+
if (isNotDefined(data) || data.length <= 0) {
2223
return (
2324
<div>
2425
Nothings to show.

0 commit comments

Comments
 (0)