forked from hpcc-systems/HPCC-Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiskUsage.tsx
More file actions
135 lines (121 loc) · 5.11 KB
/
Copy pathDiskUsage.tsx
File metadata and controls
135 lines (121 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import * as React from "react";
import { Link } from "@fluentui/react";
import { Divider, Toolbar, ToolbarButton } from "@fluentui/react-components";
import { ArrowClockwise20Regular } from "@fluentui/react-icons";
import { ComponentDetails as ComponentDetailsWidget, Summary as SummaryWidget } from "src/DiskUsage";
import nlsHPCC from "src/nlsHPCC";
import * as Utility from "src/Utility";
import { AutosizeHpccJSComponent } from "../layouts/HpccJSAdapter";
import { HolyGrail } from "../layouts/HolyGrail";
import { SizeMe } from "../layouts/SizeMe";
import { pushUrl } from "../util/history";
import { FluentGrid, useFluentStoreState } from "./controls/Grid";
import { FolderUsageCards } from "./cards/DiskUsageCard";
import { useTargetClusterUsageEx } from "../hooks/diskUsage";
interface SummaryProps {
cluster?: string;
}
export const Summary: React.FunctionComponent<SummaryProps> = ({
cluster
}) => {
const summary = React.useMemo(() => {
const retVal = new SummaryWidget(cluster)
.refresh(false)
.on("click", (widget, details) => {
pushUrl(`/operations/clusters/${details.Name}/usage`);
})
;
return retVal;
}, [cluster]);
return <AutosizeHpccJSComponent widget={summary}></AutosizeHpccJSComponent >;
};
interface ClusterUsageProps {
cluster: string;
}
export const ClusterUsage: React.FunctionComponent<ClusterUsageProps> = ({
cluster
}) => {
const { refreshTable } = useFluentStoreState({});
const [refreshToken, setRefreshToken] = React.useState(0);
const { data: usage, refresh } = useTargetClusterUsageEx(cluster);
// Grid ---
const columns = React.useMemo(() => {
return {
PercentUsed: {
label: nlsHPCC.PercentUsed, width: 50, formatter: (percent) => {
let className = "";
if (percent <= 70) { className = "bgFilled bgGreen"; }
else if (percent > 70 && percent < 80) { className = "bgFilled bgOrange"; }
else { className = "bgFilled bgRed"; }
return <span className={className}>{percent}</span>;
}
},
Component: { label: nlsHPCC.Component, width: 90 },
Type: { label: nlsHPCC.Type, width: 40 },
IPAddress: {
label: nlsHPCC.IPAddress, width: 140,
formatter: (ip) => <Link href={`#/operations/machines/${ip}/usage`}>{ip}</Link>
},
Path: { label: nlsHPCC.Path, width: 220 },
InUse: { label: nlsHPCC.InUse, width: 50 },
Total: { label: nlsHPCC.Total, width: 50 },
};
}, []);
type Columns = typeof columns;
type Row = { __hpcc_id: string } & { [K in keyof Columns]: string | number };
const data = React.useMemo<Row[]>(() => {
const rows: Row[] = [];
(usage ?? []).forEach(component => {
component.ComponentUsages.forEach(cu => {
cu.MachineUsages.forEach(mu => {
mu.DiskUsages.forEach((du, i) => {
rows.push({
__hpcc_id: `__usage_${i}`,
PercentUsed: Math.round((du.InUse / du.Total) * 100),
Component: cu.Name,
IPAddress: mu.Name,
Type: du.Name,
Path: du.Path,
InUse: Utility.convertedSize(du.InUse),
Total: Utility.convertedSize(du.Total)
});
});
});
});
});
return rows;
}, [usage]);
return <HolyGrail
header={
<Toolbar>
<ToolbarButton appearance="subtle" icon={<ArrowClockwise20Regular />} aria-label={nlsHPCC.Refresh} onClick={() => { refresh(); setRefreshToken(t => t + 1); }}>
{nlsHPCC.Refresh}
</ToolbarButton>
</Toolbar>
}
main={<SizeMe>{({ size }) => {
return <div style={{ position: "relative", width: "100%", height: "100%" }}>
<div style={{ position: "absolute", width: "100%", height: `${size.height}px`, overflowY: "auto" }}>
<Divider>{nlsHPCC.Category}</Divider>
<FolderUsageCards cluster={cluster} refreshToken={refreshToken} />
<Divider>{nlsHPCC.Folders}</Divider>
<FluentGrid data={data} primaryID="__hpcc_id" sort={{ attribute: "__hpcc_id", descending: false }} columns={columns} setSelection={() => null} setTotal={() => null} refresh={refreshTable} />
</div>
</div>;
}}</SizeMe>}
/>;
};
interface MachineUsageProps {
machine: string;
}
export const MachineUsage: React.FunctionComponent<MachineUsageProps> = ({
machine
}) => {
const summary = React.useMemo(() => {
const retVal = new ComponentDetailsWidget(machine)
.refresh()
;
return retVal;
}, [machine]);
return <AutosizeHpccJSComponent widget={summary}></AutosizeHpccJSComponent >;
};