fix(dashboard): error when fetching stats (#193)

Handles an edge case where stats.data is a 1 length array since there's no before data
This commit is contained in:
Jonathan 2022-10-16 16:44:46 -04:00 committed by GitHub
parent 3cb08c73d3
commit 402987baba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,7 @@ export function StatCards() {
icon: ( icon: (
<FileIcon /> <FileIcon />
), ),
diff: stats.isSuccess ? percentChange(before.data.count, latest.data.count) : undefined, diff: stats.isSuccess && before?.data ? percentChange(before.data.count, latest.data.count) : undefined,
}}/> }}/>
<StatCard stat={{ <StatCard stat={{
@ -35,7 +35,7 @@ export function StatCards() {
icon: ( icon: (
<Database size={15} /> <Database size={15} />
), ),
diff: stats.isSuccess ? percentChange(before.data.size_num, latest.data.size_num) : undefined, diff: stats.isSuccess && before?.data ? percentChange(before.data.size_num, latest.data.size_num) : undefined,
}}/> }}/>
<StatCard stat={{ <StatCard stat={{
@ -45,7 +45,7 @@ export function StatCards() {
icon: ( icon: (
<Eye size={15} /> <Eye size={15} />
), ),
diff: stats.isSuccess ? percentChange(before.data.views_count, latest.data.views_count) : undefined, diff: stats.isSuccess && before?.data ? percentChange(before.data.views_count, latest.data.views_count) : undefined,
}}/> }}/>
<StatCard stat={{ <StatCard stat={{