-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
PlacementGroupTable.tsx
201 lines (196 loc) · 6.22 KB
/
PlacementGroupTable.tsx
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import {
Box,
InputAdornment,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
TextField,
TextFieldProps,
Tooltip,
} from "@material-ui/core";
import Autocomplete from "@material-ui/lab/Autocomplete";
import Pagination from "@material-ui/lab/Pagination";
import React, { useState } from "react";
import rowStyles from "../common/RowStyles";
import { Bundle, PlacementGroup } from "../type/placementGroup";
import { useFilter } from "../util/hook";
import StateCounter from "./StatesCounter";
import { StatusChip } from "./StatusChip";
const BundleResourceRequirements = ({ bundles }: { bundles: Bundle[] }) => {
return (
<div>
{bundles.map(({ unit_resources }, index) => {
return `{${Object.entries(unit_resources || {})
.map(([key, val]) => `${key}: ${val}`)
.join(", ")}}, `;
})}
</div>
);
};
const PlacementGroupTable = ({
placementGroups = [],
jobId = null,
}: {
placementGroups: PlacementGroup[];
jobId?: string | null;
}) => {
const [pageNo, setPageNo] = useState(1);
const { changeFilter, filterFunc } = useFilter();
const [pageSize, setPageSize] = useState(10);
const placementGroupList = placementGroups.filter(filterFunc);
const list = placementGroupList.slice(
(pageNo - 1) * pageSize,
pageNo * pageSize,
);
const classes = rowStyles();
const columns = [
{ label: "ID" },
{ label: "Name" },
{ label: "Job Id" },
{ label: "State" },
{ label: "Reserved Resources" },
{ label: "Scheduling Detail" },
];
return (
<div>
<div style={{ flex: 1, display: "flex", alignItems: "center" }}>
<Autocomplete
style={{ margin: 8, width: 120 }}
options={Array.from(
new Set(placementGroups.map((e) => e.placement_group_id)),
)}
onInputChange={(_: any, value: string) => {
changeFilter("placement_group_id", value.trim());
}}
renderInput={(params: TextFieldProps) => (
<TextField {...params} label="Placement group ID" />
)}
/>
<Autocomplete
style={{ margin: 8, width: 120 }}
options={Array.from(new Set(placementGroups.map((e) => e.state)))}
onInputChange={(_: any, value: string) => {
changeFilter("state", value.trim());
}}
renderInput={(params: TextFieldProps) => (
<TextField {...params} label="State" />
)}
/>
<Autocomplete
style={{ margin: 8, width: 150 }}
defaultValue={jobId}
options={Array.from(
new Set(placementGroups.map((e) => e.creator_job_id)),
)}
onInputChange={(_: any, value: string) => {
changeFilter("creator_job_id", value.trim());
}}
renderInput={(params: TextFieldProps) => (
<TextField {...params} label="Job Id" />
)}
/>
<Autocomplete
style={{ margin: 8, width: 150 }}
options={Array.from(new Set(placementGroups.map((e) => e.name)))}
onInputChange={(_: any, value: string) => {
changeFilter("name", value.trim());
}}
renderInput={(params: TextFieldProps) => (
<TextField {...params} label="Name" />
)}
/>
<TextField
style={{ margin: 8, width: 120 }}
label="Page Size"
size="small"
defaultValue={10}
InputProps={{
onChange: ({ target: { value } }) => {
setPageSize(Math.min(Number(value), 500) || 10);
},
endAdornment: (
<InputAdornment position="end">Per Page</InputAdornment>
),
}}
/>
</div>
<div style={{ display: "flex", alignItems: "center" }}>
<div>
<Pagination
page={pageNo}
onChange={(e, num) => setPageNo(num)}
count={Math.ceil(placementGroupList.length / pageSize)}
/>
</div>
<div>
<StateCounter type="placementGroup" list={placementGroupList} />
</div>
</div>
<div className={classes.tableContainer}>
<Table>
<TableHead>
<TableRow>
{columns.map(({ label }) => (
<TableCell align="center" key={label}>
<Box
display="flex"
justifyContent="center"
alignItems="center"
>
{label}
</Box>
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{list.map(
({
placement_group_id,
name,
creator_job_id,
state,
stats,
bundles,
}) => (
<TableRow key={placement_group_id}>
<TableCell align="center">
<Tooltip
className={classes.idCol}
title={placement_group_id}
arrow
interactive
>
<div>{placement_group_id}</div>
</Tooltip>
</TableCell>
<TableCell align="center">{name ? name : "-"}</TableCell>
<TableCell align="center">{creator_job_id}</TableCell>
<TableCell align="center">
<StatusChip type="placementGroup" status={state} />
</TableCell>
<TableCell align="center">
<Tooltip
className={classes.OverflowCol}
title={<BundleResourceRequirements bundles={bundles} />}
arrow
interactive
>
<BundleResourceRequirements bundles={bundles} />
</Tooltip>
</TableCell>
<TableCell align="center">
{stats ? stats.scheduling_state : "-"}
</TableCell>
</TableRow>
),
)}
</TableBody>
</Table>
</div>
</div>
);
};
export default PlacementGroupTable;