Skip to content

Commit

Permalink
Merge pull request #198 from Minnowo/master
Browse files Browse the repository at this point in the history
Fix crash from reduce of empty array
  • Loading branch information
jmattheis authored Jan 2, 2025
2 parents a189202 + 8a41247 commit 05c5807
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 46 deletions.
54 changes: 10 additions & 44 deletions ui/src/dashboard/Entry/DashboardEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,63 +67,29 @@ const SpecificDashboardEntry: React.FC<{entry: Dashboards_dashboards_items; rang
</Center>
);
}
const firstEntries: Stats_stats_entries[] =
(stats.data && stats.data.stats && stats.data.stats[0] && stats.data.stats[0].entries) || [];
if (firstEntries.length === 0) {
return (
<Center>
<Typography>no data</Typography>
</Center>
);
}

const entries = (stats.data && stats.data.stats) || [];
switch (entry.entryType) {
case EntryType.PieChart:
const data: Stats_stats_entries[] = (stats.data && stats.data.stats && stats.data.stats[0].entries) || [];
if (data.length === 0) {
return (
<Center>
<Typography>no data</Typography>
</Center>
);
}
return <DashboardPieChart entries={data} />;
return <DashboardPieChart entries={firstEntries} />;
case EntryType.BarChart:
if (entries.length === 0) {
return (
<Center>
<Typography>no data</Typography>
</Center>
);
}
return <DashboardBarChart entries={entries} interval={interval} type="normal" total={entry.total} />;
case EntryType.StackedBarChart:
if (entries.length === 0) {
return (
<Center>
<Typography>no data</Typography>
</Center>
);
}
return <DashboardBarChart entries={entries} interval={interval} type="stacked" total={entry.total} />;
case EntryType.LineChart:
if (entries.length === 0) {
return (
<Center>
<Typography>no data</Typography>
</Center>
);
}
return <DashboardLineChart entries={entries} interval={interval} total={entry.total} />;
case EntryType.VerticalTable:
if (entries.length === 0) {
return (
<Center>
<Typography>no data</Typography>
</Center>
);
}
return <DashboardTable mode="vertical" entries={entries} interval={interval} total={entry.total} />;
case EntryType.HorizontalTable:
if (entries.length === 0) {
return (
<Center>
<Typography>no data</Typography>
</Center>
);
}
return <DashboardTable mode="horizontal" entries={entries} interval={interval} total={entry.total} />;
default:
return expectNever(entry.entryType);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/dashboard/Entry/DashboardPieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const CustomTooltip = ({active, payload, total}: CustomTooltipProps) => {
<Paper style={{padding: 10}} elevation={4}>
<Typography>
{first.payload.key}:{first.payload.value}: {prettyMs(first.payload.timeSpendInSeconds * 1000)} (
{((first.payload.timeSpendInSeconds / total) * 100).toFixed(2)}%)
{total > 0 ? ((first.payload.timeSpendInSeconds / total) * 100).toFixed(2) : '0.00'}%)
</Typography>
</Paper>
);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/dashboard/Entry/DashboardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const DashboardTable: React.FC<DashboardTableProps> = ({entries, interval
}, {}),
};
if (total) {
result.data['Total'] = Object.values(result.data).reduce((acc, value) => acc + value);
result.data['Total'] = Object.values(result.data).reduce((acc, value) => acc + value, 0);
}
return result;
})
Expand Down

0 comments on commit 05c5807

Please sign in to comment.