Skip to content

Commit 351072d

Browse files
committed
feat: Implement GetStatusList function and update EventEditor and NewForm components to utilize IsIncident for status handling
1 parent 33b66ec commit 351072d

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

src/Components/Event/Enums.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ export enum EventStatus {
8585
Changed = "Changed",
8686
}
8787

88+
/**
89+
* @author Aloento
90+
* @since 1.1.0
91+
* @version 0.1.0
92+
*/
93+
export function GetStatusList(type: EventType): EventStatus[] {
94+
switch (type) {
95+
case EventType.Maintenance:
96+
return Object.values(EventStatus).slice(4, 9);
97+
case EventType.Information:
98+
return [EventStatus.Planned, EventStatus.Active, EventStatus.Completed, EventStatus.Cancelled];
99+
default:
100+
return Object.values(EventStatus).slice(0, 4);
101+
}
102+
}
103+
88104
/**
89105
* @author Aloento
90106
* @since 1.0.0

src/Components/Event/EventEditor.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { useBoolean } from "ahooks";
33
import dayjs from "dayjs";
44
import { Dic } from "~/Helpers/Entities";
55
import { Models } from "~/Services/Status.Models";
6-
import { EventStatus, EventType, IsOpenStatus } from "./Enums";
6+
import { EventStatus, EventType, GetStatusList, IsIncident, IsOpenStatus } from "./Enums";
77
import { useEditForm } from "./useEditForm";
88

99
/**
1010
* @author Aloento
1111
* @since 1.0.0
12-
* @version 0.1.0
12+
* @version 0.2.0
1313
*/
1414
export function EventEditor({ Event }: { Event: Models.IEvent }) {
1515
const { State, Actions, Validation, OnSubmit, Loading } = useEditForm(Event);
@@ -49,7 +49,7 @@ export function EventEditor({ Event }: { Event: Models.IEvent }) {
4949
<ScaleDropdownSelect
5050
label="Type"
5151
value={State.type}
52-
disabled={Event.Type === EventType.Maintenance}
52+
disabled={!IsIncident(Event.Type)}
5353
onScale-change={(e) => Actions.setType(e.target.value as EventType)}
5454
invalid={!!Validation.type}
5555
helperText={Validation.type}
@@ -67,11 +67,8 @@ export function EventEditor({ Event }: { Event: Models.IEvent }) {
6767
invalid={!!Validation.status}
6868
helperText={Validation.status}
6969
>
70-
{Object.values(EventStatus)
71-
.slice(
72-
State.type === EventType.Maintenance ? 4 : 0,
73-
State.type === EventType.Maintenance ? 9 : 4
74-
).map((status, i) =>
70+
{GetStatusList(State.type)
71+
.map((status, i) =>
7572
<ScaleDropdownSelectItem value={status} key={i}>
7673
{status}
7774
</ScaleDropdownSelectItem>)}
@@ -80,7 +77,7 @@ export function EventEditor({ Event }: { Event: Models.IEvent }) {
8077
<ScaleTextField
8178
type="datetime-local"
8279
label="Start CET"
83-
disabled={State.type !== EventType.Maintenance && IsOpenStatus(Event.Status)}
80+
disabled={IsIncident(State.type) && IsOpenStatus(Event.Status)}
8481
value={dayjs(State.start).format(Dic.Picker)}
8582
onScale-input={(e) => Actions.setStart(new Date(e.target.value as string))}
8683
invalid={!!Validation.start}
@@ -90,7 +87,7 @@ export function EventEditor({ Event }: { Event: Models.IEvent }) {
9087
<ScaleTextField
9188
type="datetime-local"
9289
label="(Plan) End CET"
93-
disabled={!(State.type === EventType.Maintenance || !IsOpenStatus(State.status))}
90+
disabled={!(!IsIncident(State.type) || !IsOpenStatus(State.status))}
9491
value={State.end ? dayjs(State.end).format(Dic.Picker) : null}
9592
onScale-input={(e) => Actions.setEnd(new Date(e.target.value as string))}
9693
invalid={!!Validation.end}

src/Components/New/NewForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import dayjs from "dayjs";
33
import { orderBy } from "lodash";
44
import { Dic } from "~/Helpers/Entities";
55
import { useStatus } from "~/Services/Status";
6-
import { EventType } from "../Event/Enums";
6+
import { EventType, IsIncident } from "../Event/Enums";
77
import { useNewForm } from "./useNewForm";
88

99
/**
@@ -122,7 +122,7 @@ export function NewForm() {
122122
helperText={Validation.start}
123123
/>
124124

125-
{State.type === EventType.Maintenance && (
125+
{!IsIncident(State.type) && (
126126
<ScaleTextField
127127
type="datetime-local"
128128
label="(Plan) End CET"

src/Components/New/useNewForm.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { useEffect, useState } from "react";
33
import { useStatus } from "~/Services/Status";
44
import { Models } from "~/Services/Status.Models";
55
import { useAccessToken } from "../Auth/useAccessToken";
6-
import { EventStatus, EventType, GetEventImpact } from "../Event/Enums";
6+
import { EventStatus, EventType, GetEventImpact, IsIncident } from "../Event/Enums";
77
import { useRouter } from "../Router";
88

99
/**
1010
* @author Aloento
1111
* @since 1.0.0
12-
* @version 0.1.0
12+
* @version 0.2.0
1313
*/
1414
export function useNewForm() {
1515
const { DB, Update } = useStatus();
@@ -52,7 +52,7 @@ export function useNewForm() {
5252
_setType(value);
5353
setValType(undefined);
5454

55-
if (value !== EventType.Maintenance) {
55+
if (IsIncident(value)) {
5656
_setEnd(undefined);
5757
}
5858

@@ -86,7 +86,7 @@ export function useNewForm() {
8686
setValStart("Start Date cannot be later than End Date.");
8787
err = true;
8888
}
89-
if (value > now && type !== EventType.Maintenance) {
89+
if (value > now && IsIncident(type)) {
9090
setValStart("Start Date cannot be in the future.");
9191
err = true;
9292
}
@@ -148,8 +148,8 @@ export function useNewForm() {
148148
return;
149149
}
150150

151-
const status = type === EventType.Maintenance
152-
? EventStatus.Modified : EventStatus.Analysing
151+
const status = IsIncident(type)
152+
? EventStatus.Analysing : EventStatus.Planned
153153

154154
const event: Models.IEvent = {
155155
Id: Math.max(...DB.Events.map(event => event.Id), 0) + 1,
@@ -162,7 +162,7 @@ export function useNewForm() {
162162
Histories: new Set()
163163
};
164164

165-
if (type === EventType.Maintenance)
165+
if (!IsIncident(type))
166166
event.Description = description;
167167
else
168168
event.Histories.add({
@@ -183,7 +183,7 @@ export function useNewForm() {
183183
start_date: start.toISOString()
184184
}
185185

186-
if (type === EventType.Maintenance && end) {
186+
if (!IsIncident(type) && end) {
187187
body.end_date = end
188188
}
189189

0 commit comments

Comments
 (0)