Skip to content

Commit 1f91a46

Browse files
committed
feat: filter events by PendingReview status in History and Reviews components
1 parent 5139e36 commit 1f91a46

3 files changed

Lines changed: 46 additions & 190 deletions

File tree

src/Pages/History.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import dayjs from "dayjs";
33
import { chain } from "lodash";
44
import { useEffect, useRef, useState } from "react";
55
import { Helmet } from "react-helmet";
6+
import { EventStatus } from "~/Components/Event/Enums";
67
import { EventFilters } from "~/Components/History/EventFilters";
78
import { getEventTag } from "~/Components/History/EventTag";
89
import { useEventFilters } from "~/Components/History/useEventFilters";
@@ -26,14 +27,18 @@ export function History() {
2627
return stored ? parseInt(stored, 10) : 20;
2728
});
2829

30+
const events = DB.Events.filter(
31+
(x) => x.Status !== EventStatus.PendingReview
32+
);
33+
2934
const {
3035
filters,
3136
validation,
3237
filteredEvents,
3338
setFilters,
3439
setValidation,
3540
clearFilters,
36-
} = useEventFilters(DB.Events);
41+
} = useEventFilters(events);
3742

3843
useEffect(() => {
3944
if (!gridRef.current) {
@@ -102,7 +107,7 @@ export function History() {
102107
filters={filters}
103108
validation={validation}
104109
regions={DB.Regions}
105-
totalEvents={DB.Events.length}
110+
totalEvents={events.length}
106111
filteredCount={filteredEvents.length}
107112
onFiltersChange={setFilters}
108113
onValidationChange={setValidation}

src/Pages/Reviews.tsx

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { ScaleDataGrid, ScaleIconActionCheckmark, ScaleIconActionMenu, ScaleMenuFlyoutItem, ScaleMenuFlyoutList } from "@telekom/scale-components-react";
2+
import dayjs from "dayjs";
3+
import { chain } from "lodash";
24
import { useEffect, useRef, useState } from "react";
35
import { Helmet } from "react-helmet";
6+
import { EventStatus } from "~/Components/Event/Enums";
47
import { Dic } from "~/Helpers/Entities";
5-
import reviewsHistoryMock from "./reviewsHistoryMock.json";
8+
import { useStatus } from "~/Services/Status";
69

710
const PAGE_SIZE_KEY = "reviewsPageSize";
811
const PAGE_SIZE_OPTIONS = [10, 20, 50];
@@ -13,22 +16,15 @@ const PAGE_SIZE_OPTIONS = [10, 20, 50];
1316
* @version 0.3.0
1417
*/
1518
export function Reviews() {
19+
const { DB } = useStatus();
1620
const gridRef = useRef<HTMLScaleDataGridElement>(null);
1721

1822
const [pageSize, setPageSize] = useState<number>(() => {
1923
const stored = localStorage.getItem(PAGE_SIZE_KEY);
2024
return stored ? parseInt(stored, 10) : 10;
2125
});
2226

23-
interface ReviewItem {
24-
id: number;
25-
planStartCET: string;
26-
planEndCET: string;
27-
region: string;
28-
service: string;
29-
}
30-
31-
const historyItems = reviewsHistoryMock as ReviewItem[];
27+
const pendingEvents = DB.Events.filter((x) => x.Status === EventStatus.PendingReview);
3228

3329
useEffect(() => {
3430
if (!gridRef.current) {
@@ -46,23 +42,41 @@ export function Reviews() {
4642
{ type: "actions", label: "Detail" },
4743
];
4844

49-
const events = historyItems.map((item) => [
50-
item.id,
51-
item.planStartCET,
52-
item.planEndCET,
53-
item.region,
54-
item.service,
55-
[
56-
{
57-
label: "↗",
58-
variant: "secondary",
59-
href: `/Event/${item.id}`
60-
}
61-
]
62-
]);
45+
const events = chain(pendingEvents)
46+
.map((x) => {
47+
const rs = Array.from(x.RegionServices);
48+
49+
const services = chain(rs)
50+
.map(s => s.Service.Name)
51+
.uniq()
52+
.value();
53+
54+
const regions = chain(rs)
55+
.map(r => r.Region.Name)
56+
.uniq()
57+
.value();
58+
59+
return [
60+
x.Id,
61+
dayjs(x.Start).tz(Dic.TZ).format(Dic.Time),
62+
x.End ? dayjs(x.End).tz(Dic.TZ).format(Dic.Time) : "-",
63+
regions.join(", "),
64+
services.length > 2
65+
? `${services.slice(0, 2).join(", ")} +${services.length - 2}`
66+
: services.join(", "),
67+
[
68+
{
69+
label: "↗",
70+
variant: "secondary",
71+
href: `/Event/${x.Id}`
72+
}
73+
]
74+
];
75+
})
76+
.value();
6377

6478
grid.rows = events;
65-
}, [gridRef.current, historyItems]);
79+
}, [gridRef.current, pendingEvents]);
6680

6781
return (
6882
<>

src/Pages/reviewsHistoryMock.json

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)