Space allocation (#24)
* Update the props * Display the space allocation horizontally
This commit is contained in:
parent
cf0b5d68aa
commit
ba52e9afa4
|
@ -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>
|
<div className="nodeSpaceAllocation-legendItem-text">
|
||||||
<span>{d.title}</span>
|
<small>{d.title}</small>
|
||||||
|
<SimpleText variant="light" size="small">
|
||||||
|
{PrettyBytes(d.size)}
|
||||||
|
</SimpleText>
|
||||||
</div>
|
</div>
|
||||||
<small>{PrettyBytes(d.size)}</small>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue