Space allocation (#24)

* Update the props

* Display the space allocation horizontally
This commit is contained in:
Arnaud 2024-09-20 15:34:07 +02:00 committed by GitHub
parent cf0b5d68aa
commit ba52e9afa4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 25 deletions

View File

@ -1,36 +1,41 @@
import { SimpleText } from "../SimpleText/SimpleText";
import { PrettyBytes } from "../utils/bytes"; import { PrettyBytes } from "../utils/bytes";
import "./spaceAllocation.css"; import "./spaceAllocation.css";
type Props = { type Props = {
data: { data: {
title: string; title: string;
percent: number;
size: number; size: number;
}[]; }[];
}; };
export function SpaceAllocation({ data }: Props) { export function SpaceAllocation({ data }: Props) {
const total = data.reduce((acc, val) => acc + val.size, 0);
return ( return (
<> <>
<div className="nodeSpaceAllocation-bar"> <div className="nodeSpaceAllocation-bar">
{data.map((d, index) => ( {data.map((d, index) => (
<span <span
key={d.title}
className={`nodeSpaceAllocation-barItem nodeSpaceAllocation-barQuota nodeSpaceAllocation-quota-${index}`} className={`nodeSpaceAllocation-barItem nodeSpaceAllocation-barQuota nodeSpaceAllocation-quota-${index}`}
style={{ width: d.percent + "%" }} style={{ width: (d.size / total) * 100 + "%" }}
></span> ></span>
))} ))}
</div> </div>
<div className="nodeSpaceAllocation-legend"> <div className="nodeSpaceAllocation-legend">
{data.map((d, index) => ( {data.map((d, index) => (
<div className="nodeSpaceAllocation-legendRow"> <div key={d.title} className="nodeSpaceAllocation-legendRow">
<div className="nodeSpaceAllocation-legendLeft">
<div <div
className={`nodeSpaceAllocation-legendItem nodeSpaceAllocation-quota nodeSpaceAllocation-quota-${index}`} className={`nodeSpaceAllocation-legendItem nodeSpaceAllocation-quota nodeSpaceAllocation-quota-${index}`}
></div> ></div>
<span>{d.title}</span> <div className="nodeSpaceAllocation-legendItem-text">
<small>{d.title}</small>
<SimpleText variant="light" size="small">
{PrettyBytes(d.size)}
</SimpleText>
</div> </div>
<small>{PrettyBytes(d.size)}</small>
</div> </div>
))} ))}
</div> </div>

View File

@ -2,7 +2,7 @@
height: 10px; height: 10px;
display: flex; display: flex;
gap: 0.75rem; gap: 0.75rem;
margin-bottom: 1.5rem; margin-bottom: 1rem;
} }
.nodeSpaceAllocation-barQuota { .nodeSpaceAllocation-barQuota {
@ -22,19 +22,21 @@
} }
.nodeSpaceAllocation-quota-0 { .nodeSpaceAllocation-quota-0 {
background-color: var(--codex-color);
}
.nodeSpaceAllocation-quota-1 {
background-color: var(--codex-color-primary); background-color: var(--codex-color-primary);
} }
.nodeSpaceAllocation-quota-2 { .nodeSpaceAllocation-quota-1 {
background-color: #f9fa93; background-color: #f9fa93;
} }
.nodeSpaceAllocation-quota-2 {
background-color: var(--codex-color);
}
.nodeSpaceAllocation-legend { .nodeSpaceAllocation-legend {
margin-top: 0.75rem; margin-top: 0.75rem;
display: flex;
gap: 0.75rem;
} }
.nodeSpaceAllocation-legendItem { .nodeSpaceAllocation-legendItem {
@ -48,11 +50,11 @@
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
margin-bottom: 0.75rem; margin-bottom: 0.75rem;
gap: 0.75rem; gap: 0.5rem;
} }
.nodeSpaceAllocation-legendLeft { .nodeSpaceAllocation-legendItem-text {
display: flex; display: flex;
align-items: center; flex-direction: column;
gap: 0.75rem; line-height: 1rem;
} }

View File

@ -18,18 +18,15 @@ export const Default: Story = {
args: { args: {
data: [ data: [
{ {
title: "Maximum storage space used by the node", title: "Space allocated",
percent: 60,
size: 10000000, size: 10000000,
}, },
{ {
title: "Amount of storage space currently in use", title: "New space allocation",
percent: 20,
size: 10000000 * 0.2, size: 10000000 * 0.2,
}, },
{ {
title: "Amount of storage space reserved", title: "Remaining space",
percent: 20,
size: 10000000 * 0.2, size: 10000000 * 0.2,
}, },
], ],