Skip to content

Commit a74477f

Browse files
committed
Add filtering to history table
1 parent fff9eba commit a74477f

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

website/src/page/readable/historyTable.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: MIT-0
33
import "@cloudscape-design/global-styles/index.css";
44

5+
import { useState } from "react";
56
import { useTranslation } from "react-i18next";
67
import { useNavigate } from "react-router-dom";
78

@@ -12,6 +13,7 @@ import {
1213
Link,
1314
SpaceBetween,
1415
Table,
16+
TextFilter,
1517
} from "@cloudscape-design/components";
1618

1719
import { useReadableJobs } from "./hooks/useReadableJobs";
@@ -24,6 +26,7 @@ export default function HistoryTable() {
2426
const { jobs, loading } = useReadableJobs();
2527
const { t } = useTranslation();
2628
const navigate = useNavigate();
29+
const [ filteringText, setFilteringText ] = useState("");
2730

2831
async function createAndNavigate() {
2932
const jobId = await CreateJob();
@@ -62,7 +65,9 @@ export default function HistoryTable() {
6265
cell: (item) => formatTimestamp(item.updatedAt),
6366
},
6467
]}
65-
items={jobs}
68+
items={jobs.filter(item =>
69+
(item.name?.toLowerCase() ?? '').includes(filteringText.toLowerCase())
70+
)}
6671
loadingText={t("generic_loading")}
6772
loading={loading}
6873
trackBy="id"
@@ -81,6 +86,12 @@ export default function HistoryTable() {
8186
}
8287
stickyHeader
8388
stripedRows
89+
filter={
90+
<TextFilter
91+
filteringText={filteringText}
92+
onChange={({ detail }) => setFilteringText(detail.filteringText)}
93+
countText={`${jobs.filter(item => (item.name?.toLowerCase() ?? '').includes(filteringText.toLowerCase())).length} matches`} />
94+
}
8495
/>
8596
);
8697
}

website/src/page/translation/historyTable.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Table,
1616
TextContent,
1717
Toggle,
18+
TextFilter,
1819
} from "@cloudscape-design/components";
1920

2021
import { useTranslationJobs } from "./hooks/useTranslationJobs";
@@ -51,6 +52,7 @@ export default function HistoryTable() {
5152
const { t } = useTranslation();
5253
const navigate = useNavigate();
5354
const [hideExpired, setHideExpired] = useState(true);
55+
const [ filteringText, setFilteringText ] = useState("");
5456

5557
const toggleExpired = () => setHideExpired(!hideExpired);
5658

@@ -176,9 +178,12 @@ export default function HistoryTable() {
176178
},
177179
]}
178180
stickyColumns={{ first: 0, last: 1 }}
179-
items={jobs.filter(
180-
(job) => !hideExpired || job.jobStatus.toUpperCase() !== "EXPIRED"
181-
)}
181+
items={jobs.filter(item => {
182+
if (filteringText) {
183+
return (item.jobName?.toLowerCase() ?? '').includes(filteringText.toLowerCase());
184+
}
185+
return !hideExpired || item.jobStatus.toUpperCase() !== "EXPIRED";
186+
})}
182187
loadingText={t("generic_loading")}
183188
loading={loading}
184189
trackBy="id"
@@ -212,6 +217,12 @@ export default function HistoryTable() {
212217
}
213218
stickyHeader
214219
stripedRows
220+
filter={
221+
<TextFilter
222+
filteringText={filteringText}
223+
onChange={({ detail }) => setFilteringText(detail.filteringText)}
224+
countText={`${jobs.filter(item => (item.jobName?.toLowerCase() ?? '').includes(filteringText.toLowerCase())).length} matches`} />
225+
}
215226
/>
216227
);
217228
}

0 commit comments

Comments
 (0)