Skip to content

Commit

Permalink
fix: unify no data check for dashboard entries
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Jan 2, 2025
1 parent 9dbff68 commit 8a41247
Showing 1 changed file with 10 additions and 44 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

0 comments on commit 8a41247

Please sign in to comment.