Skip to content

Commit 9a2c9ae

Browse files
authored
fix sorted column of system table (#530)
* fix sorted column of system table * pin create_at column and change selector name
1 parent 8178ed4 commit 9a2c9ae

File tree

2 files changed

+82
-41
lines changed

2 files changed

+82
-41
lines changed

frontend/src/components/SystemsTable/SystemTableContent.tsx

+75-40
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,26 @@ export function SystemTableContent({
5858
taskCategories,
5959
}: Props) {
6060
const { userInfo } = useUser();
61+
if (
62+
filterValue.sortField &&
63+
filterValue.sortField !== "created_at" &&
64+
!metricNames.includes(filterValue.sortField)
65+
) {
66+
metricNames.push(filterValue.sortField);
67+
}
6168
const metricColumns: ColumnsType<SystemModel> = metricNames.map((metric) => ({
6269
dataIndex: ["results", ...metric.split(".")],
6370
title: metric,
6471
width: 135,
6572
ellipsis: true,
6673
align: "center",
74+
fixed: filterValue.sortField === metric ? "left" : false,
75+
sorter: filterValue.sortField === metric,
76+
showSorterTooltip: false,
77+
sortOrder:
78+
filterValue.sortField === metric && filterValue.sortDir === "asc"
79+
? "ascend"
80+
: "descend",
6781
}));
6882

6983
function showSystemAnalysis(systemID: string) {
@@ -211,6 +225,7 @@ export function SystemTableContent({
211225
],
212226
filteredValue: filterValue.split ? [filterValue.split] : null,
213227
},
228+
...metricColumns,
214229
{
215230
dataIndex: "source_language",
216231
width: 100,
@@ -223,7 +238,6 @@ export function SystemTableContent({
223238
title: "Output Lang",
224239
align: "center",
225240
},
226-
...metricColumns,
227241
{
228242
dataIndex: "preferred_username",
229243
title: "Creator",
@@ -236,6 +250,13 @@ export function SystemTableContent({
236250
render: (_, record) => record.created_at.format("MM/DD/YYYY HH:mm"),
237251
width: 130,
238252
align: "center",
253+
fixed: filterValue.sortField === "created_at" ? "right" : false,
254+
sorter: filterValue.sortField === "created_at",
255+
showSorterTooltip: false,
256+
sortOrder:
257+
filterValue.sortField === "created_at" && filterValue.sortDir === "asc"
258+
? "ascend"
259+
: "descend",
239260
},
240261
{
241262
dataIndex: "system_tags",
@@ -245,50 +266,64 @@ export function SystemTableContent({
245266
width: 130,
246267
align: "center",
247268
},
248-
{
249-
dataIndex: "action",
250-
title: "",
251-
fixed: "right",
252-
width: 90,
253-
render: (_, record) => {
254-
const notCreator = record.creator !== userInfo?.id;
255-
return (
256-
<Space size="small" direction="vertical">
257-
<Space size="small">
258-
<Button
259-
size="small"
260-
onClick={() => showSystemAnalysis(record.system_id)}
261-
>
262-
Analysis
263-
</Button>
264-
</Space>
265-
<Space size="small">
269+
];
270+
columns.sort(function (a, b) {
271+
if (
272+
(a.fixed === "left" && b.fixed !== "left") ||
273+
(a.fixed !== "right" && b.fixed === "right")
274+
) {
275+
return -1;
276+
} else if (
277+
(b.fixed === "left" && a.fixed !== "left") ||
278+
(b.fixed !== "right" && a.fixed === "right")
279+
) {
280+
return 1;
281+
}
282+
return 0;
283+
});
284+
columns.push({
285+
dataIndex: "action",
286+
title: "",
287+
fixed: "right",
288+
width: 90,
289+
render: (_, record) => {
290+
const notCreator = record.creator !== userInfo?.id;
291+
return (
292+
<Space size="small" direction="vertical">
293+
<Space size="small">
294+
<Button
295+
size="small"
296+
onClick={() => showSystemAnalysis(record.system_id)}
297+
>
298+
Analysis
299+
</Button>
300+
</Space>
301+
<Space size="small">
302+
<Button
303+
size="small"
304+
disabled={notCreator}
305+
icon={<EditOutlined />}
306+
onClick={() => {
307+
showEditDrawer(record.system_id);
308+
}}
309+
/>
310+
<Popconfirm
311+
disabled={notCreator}
312+
title="Are you sure?"
313+
onConfirm={() => deleteSystem(record.system_id)}
314+
>
266315
<Button
267-
size="small"
316+
danger
268317
disabled={notCreator}
269-
icon={<EditOutlined />}
270-
onClick={() => {
271-
showEditDrawer(record.system_id);
272-
}}
318+
size="small"
319+
icon={<DeleteOutlined />}
273320
/>
274-
<Popconfirm
275-
disabled={notCreator}
276-
title="Are you sure?"
277-
onConfirm={() => deleteSystem(record.system_id)}
278-
>
279-
<Button
280-
danger
281-
disabled={notCreator}
282-
size="small"
283-
icon={<DeleteOutlined />}
284-
/>
285-
</Popconfirm>
286-
</Space>
321+
</Popconfirm>
287322
</Space>
288-
);
289-
},
323+
</Space>
324+
);
290325
},
291-
];
326+
});
292327

293328
// rowSelection object indicates the need for row selection
294329
const rowSelection = {

frontend/src/components/SystemsTable/SystemTableTools.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,16 @@ export function SystemTableTools({
208208
<Space style={{ width: "fit-content", float: "right" }}>
209209
{mineVsAllSystemsToggle}
210210
<div style={{ display: "flex", flexDirection: "row" }}>
211+
<Input
212+
disabled
213+
value="Sorted by"
214+
style={{ width: "90px", color: "black" }}
215+
/>
211216
<Select
217+
allowClear
212218
options={[
213219
...metricOptions.map((opt) => ({ value: opt, label: opt })),
214-
{ value: "created_at", label: "Created At" },
220+
{ value: "created_at", label: "Time" },
215221
]}
216222
value={value.sortField}
217223
onChange={(value) => onChange({ sortField: value })}

0 commit comments

Comments
 (0)