Skip to content

Commit f96a2b4

Browse files
authored
fix: Update EventGrid and ServiceItem components (#2)
1 parent 1faf3df commit f96a2b4

File tree

4 files changed

+83
-54
lines changed

4 files changed

+83
-54
lines changed

src/Components/Home/EventGrid.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export function EventGrid() {
9595
const s = x.Latest.Status;
9696

9797
const res =
98+
!x.End &&
9899
s != EventStatus.Completed &&
99100
s != EventStatus.Resolved &&
100101
s != EventStatus.Cancelled

src/Components/Home/ServiceItem.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ export function ServiceItem({ RegionService }: IServiceItem) {
3030
Id: x.Id,
3131
Type: x.Type,
3232
Start: x.Start,
33+
End: x.End,
3334
Status: orderBy([...x.Histories], y => y.Created, 'desc').at(0)?.Status
3435
}))
3536
.filter(x => {
37+
if (x.Type !== EventType.Maintenance && x.End) {
38+
return false;
39+
}
40+
3641
if (!x.Status) {
3742
return true;
3843
}
44+
3945
return ![EventStatus.Completed, EventStatus.Resolved, EventStatus.Cancelled]
4046
.includes(x.Status);
4147
})
@@ -48,6 +54,11 @@ export function ServiceItem({ RegionService }: IServiceItem) {
4854
setFuture(dayjs(res.Start).isAfter(dayjs()));
4955
setId(res.Id);
5056
}
57+
else {
58+
setStatus(EventType.Operational);
59+
setFuture(false);
60+
setId(undefined);
61+
}
5162
}, [DB, RegionService]);
5263

5364
return (

src/Pages/Home.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { ScaleNotification } from "@telekom/scale-components-react";
22
import { useCreation } from "ahooks";
3-
import { chain } from "lodash";
3+
import { chain, orderBy } from "lodash";
44
import { useEffect, useMemo, useState } from "react";
55
import { Helmet } from "react-helmet";
66
import { BehaviorSubject } from "rxjs";
7-
import { EventType } from "~/Components/Event/Enums";
7+
import { EventStatus, EventType } from "~/Components/Event/Enums";
88
import { EventGrid } from "~/Components/Home/EventGrid";
99
import "~/Components/Home/Home.css";
1010
import { Indicator } from "~/Components/Home/Indicator";
1111
import { RegionSelector } from "~/Components/Home/RegionSelector";
1212
import { StatusCard } from "~/Components/Home/StatusCard";
1313
import { Station } from "~/Helpers/Entities";
14+
import { Logger } from "~/Helpers/Logger";
1415
import { useStatus } from "~/Services/Status";
1516

17+
const log = new Logger("Home");
18+
1619
/**
1720
* @author Aloento
1821
* @since 1.0.0
@@ -46,11 +49,20 @@ export function Home() {
4649
const abnormalCount = useMemo(() => {
4750
const service = chain(DB.Events)
4851
.filter(e => !e.End)
52+
.filter(e => e.Type !== EventType.Maintenance)
53+
.filter(e => {
54+
const status = orderBy(Array.from(e.Histories), y => y.Created, 'desc').at(0)?.Status;
55+
if (!status) {
56+
return true;
57+
}
58+
return ![EventStatus.Completed, EventStatus.Resolved, EventStatus.Cancelled].includes(status);
59+
})
4960
.flatMap(e => [...e.RegionServices])
5061
.map(rs => rs.Service)
5162
.uniqBy(s => s.Id)
5263
.value();
5364

65+
log.debug(service);
5466
return service.length;
5567
}, [DB]);
5668

src/Services/Status.Trans.ts

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ const log = new Logger("Service", "Status", "Transformer");
1515
export function Transformer(list: StatusEntity[]): IStatusContext {
1616
let id = 0;
1717
const db = EmptyDB();
18-
const ng = process.env.SD_BACKEND_NG;
1918

20-
for (const item of list) {
21-
if (ng) {
22-
// @ts-expect-error
23-
item.attributes = item.attrs;
24-
}
19+
if (!list?.length) {
20+
log.warn("Empty List.");
21+
return db;
22+
}
2523

24+
for (const item of list) {
2625
if (item.attributes.length < 3) {
2726
log.debug("Skipped Hidden Item.", item);
2827
continue;
@@ -94,6 +93,10 @@ export function Transformer(list: StatusEntity[]): IStatusContext {
9493
db.RegionService.push(regionService);
9594
}
9695

96+
if (!item.incidents?.length) {
97+
continue;
98+
}
99+
97100
for (const incident of item.incidents) {
98101
let dbEvent = db.Events.find((x) => x.Id === incident.id);
99102

@@ -124,55 +127,57 @@ export function Transformer(list: StatusEntity[]): IStatusContext {
124127
dbEvent.End = dayjs(incident.end_date).toDate();
125128
}
126129

127-
for (const update of incident.updates) {
128-
const status = (() => {
129-
switch (update.status) {
130-
case StatusEnum.System:
131-
return incident.end_date
132-
? EventStatus.Cancelled
133-
: EventStatus.Investigating;
134-
135-
case StatusEnum.Analyzing:
136-
return EventStatus.Investigating;
137-
// @ts-expect-error
138-
case StatusEnum.Reopened:
139-
dbEvent.End = undefined;
140-
case StatusEnum.Fixing:
141-
return EventStatus.Fixing;
142-
case StatusEnum.Observing:
143-
return EventStatus.Monitoring;
144-
case StatusEnum.Resolved:
145-
case StatusEnum.Changed:
146-
return EventStatus.Resolved;
147-
148-
case StatusEnum.Description:
149-
case StatusEnum.Scheduled:
150-
case StatusEnum.Modified:
151-
return EventStatus.Scheduled;
152-
case StatusEnum.InProgress:
153-
return EventStatus.Performing;
154-
case StatusEnum.Completed:
155-
return EventStatus.Completed;
156-
157-
default:
158-
break;
130+
if (incident.updates?.length) {
131+
for (const update of incident.updates) {
132+
const status = (() => {
133+
switch (update.status) {
134+
case StatusEnum.System:
135+
return incident.end_date
136+
? EventStatus.Cancelled
137+
: EventStatus.Investigating;
138+
139+
case StatusEnum.Analyzing:
140+
return EventStatus.Investigating;
141+
// @ts-expect-error
142+
case StatusEnum.Reopened:
143+
dbEvent.End = undefined;
144+
case StatusEnum.Fixing:
145+
return EventStatus.Fixing;
146+
case StatusEnum.Observing:
147+
return EventStatus.Monitoring;
148+
case StatusEnum.Resolved:
149+
case StatusEnum.Changed:
150+
return EventStatus.Resolved;
151+
152+
case StatusEnum.Description:
153+
case StatusEnum.Scheduled:
154+
case StatusEnum.Modified:
155+
return EventStatus.Scheduled;
156+
case StatusEnum.InProgress:
157+
return EventStatus.Performing;
158+
case StatusEnum.Completed:
159+
return EventStatus.Completed;
160+
161+
default:
162+
break;
163+
}
164+
})();
165+
166+
if (!status) {
167+
log.debug("Skipped Unknown Status.", update, incident);
168+
continue;
159169
}
160-
})();
161170

162-
if (!status) {
163-
log.debug("Skipped Unknown Status.", update, incident);
164-
continue;
165-
}
171+
const history = {
172+
Id: id++,
173+
Message: update.text,
174+
Created: dayjs(update.timestamp).toDate(),
175+
Status: status,
176+
Event: dbEvent,
177+
};
166178

167-
const history = {
168-
Id: id++,
169-
Message: update.text,
170-
Created: dayjs(update.timestamp).toDate(),
171-
Status: status,
172-
Event: dbEvent,
173-
};
174-
175-
dbEvent.Histories.add(history);
179+
dbEvent.Histories.add(history);
180+
}
176181
}
177182

178183
db.Events.push(dbEvent);

0 commit comments

Comments
 (0)