Skip to content

Commit 8a4bfa4

Browse files
committed
feat: Refactor EventCard, EventGrid, ServiceItem, Home, SLA, and TransformerV2 to utilize IsIncident for improved event handling and update version to 0.2.0
1 parent 351072d commit 8a4bfa4

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

src/Components/Event/EventCard.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Dic } from "~/Helpers/Entities";
33
import { Models } from "~/Services/Status.Models";
44
import { Authorized } from "../Auth/With";
55
import { Indicator } from "../Home/Indicator";
6-
import { EventStatus, EventType } from "./Enums";
6+
import { EventStatus, IsIncident } from "./Enums";
77
import { EventAffected } from "./EventAffected";
88
import { EventEditor } from "./EventEditor";
99
import { EventExtract } from "./EventExtract";
1010

1111
/**
1212
* @author Aloento
1313
* @since 1.0.0
14-
* @version 0.1.0
14+
* @version 0.2.0
1515
*/
1616
export function EventCard({ Event }: { Event: Models.IEvent }) {
1717
return (
@@ -51,12 +51,12 @@ export function EventCard({ Event }: { Event: Models.IEvent }) {
5151
</label>
5252

5353
<label className="text-xl font-medium text-slate-600 whitespace-nowrap">
54-
{Event.Type === EventType.Maintenance &&
54+
{!IsIncident(Event.Type) &&
5555
Event.Status !== EventStatus.Completed &&
5656
"(Plan)"} End At:
5757
</label>
5858

59-
{Event.Type === EventType.Maintenance && Event.Description &&
59+
{!IsIncident(Event.Type) && Event.Description &&
6060
<label className="text-xl font-medium text-slate-600">
6161
Description:
6262
</label>}
@@ -79,7 +79,7 @@ export function EventCard({ Event }: { Event: Models.IEvent }) {
7979
{Event.End ? dayjs(Event.End).tz(Dic.TZ).format(Dic.TimeTZ) : "Still Ongoing"}
8080
</label>
8181

82-
{Event.Type === EventType.Maintenance && Event.Description &&
82+
{!IsIncident(Event.Type) && Event.Description &&
8383
<label className="text-xl font-medium text-slate-700 break-all">
8484
{Event.Description}
8585
</label>}

src/Components/Home/EventGrid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { chain } from "lodash";
55
import { useEffect, useRef } from "react";
66
import { Dic } from "~/Helpers/Entities";
77
import { useStatus } from "~/Services/Status";
8-
import { EventType, IsOpenStatus } from "../Event/Enums";
8+
import { EventType, IsIncident, IsOpenStatus } from "../Event/Enums";
99

1010
/**
1111
* @author Aloento
@@ -87,7 +87,7 @@ export function EventGrid() {
8787
}
8888
})
8989
.filter(x => {
90-
if (x.Type !== EventType.Maintenance && x.End) {
90+
if (IsIncident(x.Type) && x.End) {
9191
return false;
9292
}
9393

src/Components/Home/ServiceItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { chain } from "lodash";
44
import { useEffect, useState } from "react";
55
import { useStatus } from "~/Services/Status";
66
import { Models } from "~/Services/Status.Models";
7-
import { EventType, IsOpenStatus } from "../Event/Enums";
7+
import { EventType, IsIncident, IsOpenStatus } from "../Event/Enums";
88
import { Indicator } from "./Indicator";
99
import "./ServiceItem.css";
1010

@@ -15,7 +15,7 @@ interface IServiceItem {
1515
/**
1616
* @author Aloento
1717
* @since 1.0.0
18-
* @version 0.1.0
18+
* @version 0.2.0
1919
*/
2020
export function ServiceItem({ RegionService }: IServiceItem) {
2121
const { DB } = useStatus();
@@ -27,7 +27,7 @@ export function ServiceItem({ RegionService }: IServiceItem) {
2727
useEffect(() => {
2828
const res = chain([...RegionService.Events])
2929
.filter(x => {
30-
if (x.Type !== EventType.Maintenance && x.End) {
30+
if (IsIncident(x.Type) && x.End) {
3131
return false;
3232
}
3333

src/Helpers/SLA.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dayjs from 'dayjs';
22
import { chain } from 'lodash';
3-
import { EventType } from '~/Components/Event/Enums';
3+
import { IsIncident } from '~/Components/Event/Enums';
44
import { Models } from "~/Services/Status.Models";
55

66
/**
@@ -14,8 +14,7 @@ export function Calc6Months(service: Models.IRegionService) {
1414

1515
const events = chain(Array.from(service.Events))
1616
.filter(e =>
17-
dayjs(e.Start).isAfter(sixMonth) &&
18-
e.Type !== EventType.Maintenance)
17+
dayjs(e.Start).isAfter(sixMonth) && IsIncident(e.Type))
1918
.value();
2019

2120
const results = [];

src/Pages/Home.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { chain } from "lodash";
66
import { useEffect, useMemo, useState } from "react";
77
import { Helmet } from "react-helmet";
88
import { BehaviorSubject, Subject } from "rxjs";
9-
import { EventType, IsOpenStatus } from "~/Components/Event/Enums";
9+
import { EventType, IsIncident, IsOpenStatus } from "~/Components/Event/Enums";
1010
import { EventGrid } from "~/Components/Home/EventGrid";
1111
import "~/Components/Home/Home.css";
1212
import { Indicator } from "~/Components/Home/Indicator";
@@ -21,7 +21,7 @@ const log = new Logger("Home");
2121
/**
2222
* @author Aloento
2323
* @since 1.0.0
24-
* @version 0.1.0
24+
* @version 0.2.0
2525
*/
2626
export function Home() {
2727
const { DB } = useStatus();
@@ -60,7 +60,7 @@ export function Home() {
6060
const abnormalCount = useMemo(() => {
6161
const service = chain(DB.Events)
6262
.filter(e => !e.End)
63-
.filter(e => e.Type !== EventType.Maintenance)
63+
.filter(e => IsIncident(e.Type))
6464
.filter(e => IsOpenStatus(e.Status))
6565
.flatMap(e => [...e.RegionServices])
6666
.map(rs => rs.Service)

src/Services/Status.Trans.V2.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dayjs from "dayjs";
22
import { orderBy } from "lodash";
3-
import { EventStatus, EventType, GetEventType } from "~/Components/Event/Enums";
3+
import { EventStatus, GetEventType, IsIncident } from "~/Components/Event/Enums";
44
import { Logger } from "~/Helpers/Logger";
55
import { EmptyDB } from "./Status";
66
import { IncidentEntityV2, NameEnum, StatusEntityV2, StatusEnum } from "./Status.Entities";
@@ -11,7 +11,7 @@ const log = new Logger("Service", "Status", "TransformerV2");
1111
/**
1212
* @author Aloento
1313
* @since 1.0.0
14-
* @version 0.1.0
14+
* @version 0.2.0
1515
*/
1616
export function TransformerV2({ Components, Events }: { Components: StatusEntityV2[], Events: IncidentEntityV2[] }): IStatusContext {
1717
let id = 0;
@@ -111,7 +111,7 @@ export function TransformerV2({ Components, Events }: { Components: StatusEntity
111111
Title: event.title,
112112
Start: dayjs(event.start_date).toDate(),
113113
Type: type,
114-
Status: type === EventType.Maintenance ? EventStatus.Planned : EventStatus.Analysing,
114+
Status: IsIncident(type) ? EventStatus.Analysing : EventStatus.Planned,
115115
Histories: new Set(),
116116
RegionServices: new Set(),
117117
};
@@ -144,7 +144,7 @@ export function TransformerV2({ Components, Events }: { Components: StatusEntity
144144
switch (update.status) {
145145
case StatusEnum.System:
146146
return event.end_date
147-
? type === EventType.Maintenance ? EventStatus.Completed : EventStatus.Resolved
147+
? IsIncident(type) ? EventStatus.Resolved : EventStatus.Completed
148148
: prev;
149149

150150
case StatusEnum.Analyzing:
@@ -210,7 +210,7 @@ export function TransformerV2({ Components, Events }: { Components: StatusEntity
210210
}
211211

212212
if (dbEvent.End &&
213-
type === EventType.Maintenance &&
213+
!IsIncident(type) &&
214214
dayjs(dbEvent.End).isBefore(dayjs())) {
215215
dbEvent.Status = EventStatus.Completed;
216216
}

0 commit comments

Comments
 (0)