Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hostd metrics data add decimals #512

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cold-fireants-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'hostd': minor
---

Siacoin metric cards now show the dynamic units with two decimal places. Closes https://github.com/SiaFoundation/hostd/issues/217

4 changes: 2 additions & 2 deletions apps/hostd/components/Home/HomeBandwidth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function HomeBandwidth() {
value={bandwidth.stats['ingress']}
defaultMode="total"
isLoading={bandwidth.isLoading}
format={humanBytes}
valueFormat={humanBytes}
/>
<DatumCardConfigurable
category="bandwidth"
Expand All @@ -30,7 +30,7 @@ export function HomeBandwidth() {
value={bandwidth.stats['egress']}
defaultMode="total"
isLoading={bandwidth.isLoading}
format={humanBytes}
valueFormat={humanBytes}
/>
</DatumScrollArea>
<ChartXY
Expand Down
6 changes: 3 additions & 3 deletions apps/hostd/components/Home/HomeContracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function HomeContracts() {
label="Active contracts"
color={contracts.config.data['active'].color}
value={contracts.stats['active']}
format={(v) => v.toFixed(0)}
valueFormat={(v) => v.toFixed(0)}
defaultMode="latest"
isLoading={contracts.isLoading}
enabledModes={['latest', 'average']}
Expand All @@ -29,7 +29,7 @@ export function HomeContracts() {
label="Successful contracts"
color={contracts.config.data['successful'].color}
value={contracts.stats['successful']}
format={(v) => v.toFixed(0)}
valueFormat={(v) => v.toFixed(0)}
defaultMode="latest"
isLoading={contracts.isLoading}
enabledModes={['latest', 'average']}
Expand All @@ -39,7 +39,7 @@ export function HomeContracts() {
label="Failed contracts"
color={contracts.config.data['failed'].color}
value={contracts.stats['failed']}
format={(v) => v.toFixed(0)}
valueFormat={(v) => v.toFixed(0)}
defaultMode="latest"
isLoading={contracts.isLoading}
enabledModes={['latest', 'average']}
Expand Down
4 changes: 2 additions & 2 deletions apps/hostd/components/Home/HomeOperations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function HomeOperations() {
defaultMode="total"
isLoading={operations.isLoading}
enabledModes={['total', 'average', 'latest']}
format={humanNumber}
valueFormat={humanNumber}
/>
<DatumCardConfigurable
category="operations"
Expand All @@ -33,7 +33,7 @@ export function HomeOperations() {
defaultMode="total"
isLoading={operations.isLoading}
enabledModes={['total', 'average', 'latest']}
format={humanNumber}
valueFormat={humanNumber}
/>
</DatumScrollArea>
<ChartXY
Expand Down
6 changes: 3 additions & 3 deletions apps/hostd/components/Home/HomeStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function HomeStorage() {
defaultMode="latest"
isLoading={storage.isLoading}
enabledModes={['latest', 'average']}
format={humanBytes}
valueFormat={humanBytes}
/>
<DatumCardConfigurable
category="storage"
Expand All @@ -32,7 +32,7 @@ export function HomeStorage() {
defaultMode="latest"
isLoading={storage.isLoading}
enabledModes={['latest', 'average']}
format={humanBytes}
valueFormat={humanBytes}
/>
<DatumCardConfigurable
category="storage"
Expand All @@ -42,7 +42,7 @@ export function HomeStorage() {
defaultMode="latest"
isLoading={storage.isLoading}
enabledModes={['latest', 'average']}
format={humanBytes}
valueFormat={humanBytes}
/>
</DatumScrollArea>
<ChartXY
Expand Down
13 changes: 9 additions & 4 deletions libs/design-system/src/app/DatumCardConfigurable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ type Props = {
diff: number
change: number
}
scFixed?: number
value?: {
total: number
average: number
latest: number
diff: number
change: number
}
valueFormat?: (val: number) => string
extendedSuffix?: string
format?: (val: number) => string
defaultMode: Mode
enabledModes?: Mode[]
showChange?: boolean
Expand All @@ -49,9 +50,10 @@ export function DatumCardConfigurable({
label,
color,
sc,
scFixed = 2,
value,
extendedSuffix,
format = (val) => val.toFixed(2),
valueFormat = (val) => val.toFixed(2),
defaultMode,
enabledModes = ['total', 'average', 'latest'],
isLoading,
Expand Down Expand Up @@ -80,9 +82,12 @@ export function DatumCardConfigurable({
</Select>
}
sc={sc?.[mode] !== undefined ? new BigNumber(sc[mode]) : undefined}
scFixed={scFixed}
extendedSuffix={extendedSuffix}
value={
value?.[mode] !== undefined && format ? format(value[mode]) : undefined
value?.[mode] !== undefined && valueFormat
? valueFormat(value[mode])
: undefined
}
comment={
sc ? (
Expand Down Expand Up @@ -111,7 +116,7 @@ export function DatumCardConfigurable({
<div className="flex items-center gap-4">
<ValueNum
tooltip="Net change over time range:"
format={(val) => format(val.toNumber())}
format={(val) => valueFormat(val.toNumber())}
value={new BigNumber(value.diff)}
/>
{showChange && value.change !== undefined && (
Expand Down
4 changes: 3 additions & 1 deletion libs/design-system/src/components/DatumCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {
entityType?: EntityType
entityValue?: string
sc?: BigNumber
scFixed?: number
sf?: number
comment?: React.ReactNode
commentTip?: React.ReactNode
Expand All @@ -39,6 +40,7 @@ export function DatumCard({
extendedSuffix,
hash,
sc,
scFixed = 2,
sf,
comment,
commentTip,
Expand Down Expand Up @@ -77,7 +79,7 @@ export function DatumCard({
scaleSize={scaleSize}
variant="value"
value={sc}
fixed={0}
fixed={scFixed}
/>
)}
{sf !== undefined && (
Expand Down
Loading