Skip to content

Commit

Permalink
Refactor import statements and update component types in multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Apr 22, 2024
1 parent ba993ba commit 3a7c9f7
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ModelTable from 'CommonUI/src/Components/ModelTable/ModelTable';
import OnCallDutyPolicyExecutionLog from 'Model/Models/OnCallDutyPolicyExecutionLog';
import DashboardNavigation from '../../../Utils/Navigation';
import FieldType from 'CommonUI/src/Components/Types/FieldType';
import { JSONObject } from 'Common/Types/JSON';
import Pill from 'CommonUI/src/Components/Pill/Pill';
import { Green, Red, Yellow } from 'Common/Types/BrandColors';
import { ButtonStyleType } from 'CommonUI/src/Components/Button/Button';
Expand All @@ -13,15 +12,13 @@ import { ErrorFunction, VoidFunction } from 'Common/Types/FunctionTypes';
import Incident from 'Model/Models/Incident';
import OnCallDutyPolicyStatus from 'Common/Types/OnCallDutyPolicy/OnCallDutyPolicyStatus';
import UserElement from '../../../Components/User/User';
import User from 'Model/Models/User';
import DropdownUtil from 'CommonUI/src/Utils/Dropdown';
import ObjectID from 'Common/Types/ObjectID';
import Query from 'CommonUI/src/Utils/BaseDatabase/Query';
import Columns from 'CommonUI/src/Components/ModelTable/Columns';
import OnCallPolicyView from '../OnCallPolicy';
import OnCallDutyPolicy from 'Model/Models/OnCallDutyPolicy';
import Navigation from 'CommonUI/src/Utils/Navigation';
import BaseModel from 'Common/Models/BaseModel';
import Filter from 'CommonUI/src/Components/ModelFilter/Filter';

export interface ComponentProps {
Expand Down Expand Up @@ -122,7 +119,7 @@ const ExecutionLogsTable: FunctionComponent<ComponentProps> = (
},
title: 'Triggered By Incident',
type: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: OnCallDutyPolicyExecutionLog): ReactElement => {
if (item['triggeredByIncident']) {
return (
<IncidentView
Expand All @@ -147,7 +144,7 @@ const ExecutionLogsTable: FunctionComponent<ComponentProps> = (
title: 'Status',
type: FieldType.Element,

getElement: (item: JSONObject): ReactElement => {
getElement: (item: OnCallDutyPolicyExecutionLog): ReactElement => {
if (item['status'] === OnCallDutyPolicyStatus.Completed) {
return (
<Pill
Expand Down Expand Up @@ -194,18 +191,9 @@ const ExecutionLogsTable: FunctionComponent<ComponentProps> = (
},
title: 'Acknowledged By',
type: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: OnCallDutyPolicyExecutionLog): ReactElement => {
if (item['acknowledgedByUser']) {
return (
<UserElement
user={
BaseModel.fromJSON(
item['acknowledgedByUser'] as JSONObject,
User
) as User
}
/>
);
return <UserElement user={item['acknowledgedByUser']} />;
}

return <p>-</p>;
Expand Down Expand Up @@ -243,7 +231,7 @@ const ExecutionLogsTable: FunctionComponent<ComponentProps> = (
title: 'View Status Message',
buttonStyleType: ButtonStyleType.NORMAL,
onClick: async (
item: JSONObject,
item: OnCallDutyPolicyExecutionLog,
onCompleteAction: VoidFunction,
onError: ErrorFunction
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { FunctionComponent, ReactElement, useState } from 'react';
import ModelTable from 'CommonUI/src/Components/ModelTable/ModelTable';
import DashboardNavigation from '../../../Utils/Navigation';
import FieldType from 'CommonUI/src/Components/Types/FieldType';
import { JSONObject } from 'Common/Types/JSON';
import Pill from 'CommonUI/src/Components/Pill/Pill';
import { Green, Red, Yellow } from 'Common/Types/BrandColors';
import { ButtonStyleType } from 'CommonUI/src/Components/Button/Button';
Expand Down Expand Up @@ -60,7 +59,7 @@ const ExecutionLogTimelineTable: FunctionComponent<ComponentProps> = (
title: 'View Status Message',
buttonStyleType: ButtonStyleType.NORMAL,
onClick: async (
item: JSONObject,
item: OnCallDutyPolicyExecutionLogTimeline,
onCompleteAction: VoidFunction,
onError: ErrorFunction
) => {
Expand Down Expand Up @@ -131,7 +130,9 @@ const ExecutionLogTimelineTable: FunctionComponent<ComponentProps> = (
},
title: 'Escalation Rule',
type: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (
item: OnCallDutyPolicyExecutionLogTimeline
): ReactElement => {
if (
item &&
item['onCallDutyPolicyEscalationRule']
Expand Down Expand Up @@ -165,15 +166,15 @@ const ExecutionLogTimelineTable: FunctionComponent<ComponentProps> = (
},
title: 'Notification Sent To',
type: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (
item: OnCallDutyPolicyExecutionLogTimeline
): ReactElement => {
if (item['alertSentToUser']) {
return (
<UserElement
user={
BaseModel.fromJSON(
item[
'alertSentToUser'
] as JSONObject,
item['alertSentToUser'],
User
) as User
}
Expand All @@ -200,7 +201,9 @@ const ExecutionLogTimelineTable: FunctionComponent<ComponentProps> = (
title: 'Status',
type: FieldType.Element,

getElement: (item: JSONObject): ReactElement => {
getElement: (
item: OnCallDutyPolicyExecutionLogTimeline
): ReactElement => {
if (
item['status'] ===
OnCallDutyExecutionLogTimelineStatus.NotificationSent
Expand Down
59 changes: 14 additions & 45 deletions Dashboard/src/Pages/Global/NewIncidents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import RouteMap, { RouteUtil } from '../../Utils/RouteMap';
import PageMap from '../../Utils/PageMap';
import ModelTable from 'CommonUI/src/Components/ModelTable/ModelTable';
import FieldType from 'CommonUI/src/Components/Types/FieldType';
import { JSONArray, JSONObject } from 'Common/Types/JSON';
import Incident from 'Model/Models/Incident';
import Pill from 'CommonUI/src/Components/Pill/Pill';
import MonitorsElement from '../../Components/Monitor/Monitors';
import Monitor from 'Model/Models/Monitor';
import Color from 'Common/Types/Color';
import ProjectElement from '../../Components/Project/Project';
import Project from 'Model/Models/Project';
import BaseModel from 'Common/Models/BaseModel';
import { RequestOptions } from 'CommonUI/src/Utils/ModelAPI/ModelAPI';
import { Black } from 'Common/Types/BrandColors';

const Home: FunctionComponent<PageComponentProps> = (
_props: PageComponentProps
Expand Down Expand Up @@ -112,17 +108,9 @@ const Home: FunctionComponent<PageComponentProps> = (
type: FieldType.Text,

selectedProperty: 'name',
getElement: (item: JSONObject): ReactElement => {
getElement: (item: Incident): ReactElement => {
return (
<ProjectElement
project={
BaseModel.fromJSON(
(item['project'] as JSONObject) ||
[],
Project
) as Project
}
/>
<ProjectElement project={item['project']!} />
);
},
},
Expand All @@ -149,23 +137,17 @@ const Home: FunctionComponent<PageComponentProps> = (
},
title: 'Current State',
type: FieldType.Entity,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: Incident): ReactElement => {
if (item['currentIncidentState']) {
return (
<Pill
color={
(
item[
'currentIncidentState'
] as JSONObject
)['color'] as Color
item.currentIncidentState.color ||
Black
}
text={
(
item[
'currentIncidentState'
] as JSONObject
)['name'] as string
item.currentIncidentState.name ||
'Unknown'
}
/>
);
Expand All @@ -183,23 +165,16 @@ const Home: FunctionComponent<PageComponentProps> = (
},
title: 'Incident Severity',
type: FieldType.Entity,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: Incident): ReactElement => {
if (item['incidentSeverity']) {
return (
<Pill
color={
(
item[
'incidentSeverity'
] as JSONObject
)['color'] as Color
item.incidentSeverity.color || Black
}
text={
(
item[
'incidentSeverity'
] as JSONObject
)['name'] as string
item.incidentSeverity.name ||
'Unknown'
}
/>
);
Expand All @@ -218,16 +193,10 @@ const Home: FunctionComponent<PageComponentProps> = (
},
title: 'Monitors Affected',
type: FieldType.Text,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: Incident): ReactElement => {
return (
<MonitorsElement
monitors={
BaseModel.fromJSON(
(item['monitors'] as JSONArray) ||
[],
Monitor
) as Array<Monitor>
}
monitors={item['monitors'] || []}
/>
);
},
Expand Down
5 changes: 2 additions & 3 deletions Dashboard/src/Pages/Incidents/View/Owners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import BadDataException from 'Common/Types/Exception/BadDataException';
import FormFieldSchemaType from 'CommonUI/src/Components/Forms/Types/FormFieldSchemaType';
import Team from 'Model/Models/Team';
import FieldType from 'CommonUI/src/Components/Types/FieldType';
import { JSONObject } from 'Common/Types/JSON';
import TeamElement from '../../../Components/Team/Team';
import IncidentOwnerUser from 'Model/Models/IncidentOwnerUser';
import User from 'Model/Models/User';
Expand Down Expand Up @@ -105,7 +104,7 @@ const IncidentOwners: FunctionComponent<PageComponentProps> = (
title: 'Team',
type: FieldType.Entity,

getElement: (item: JSONObject): ReactElement => {
getElement: (item: IncidentOwnerTeam): ReactElement => {
if (!item['team']) {
throw new BadDataException('Team not found');
}
Expand Down Expand Up @@ -208,7 +207,7 @@ const IncidentOwners: FunctionComponent<PageComponentProps> = (
title: 'User',
type: FieldType.Entity,

getElement: (item: JSONObject): ReactElement => {
getElement: (item: IncidentOwnerUser): ReactElement => {
if (!item['user']) {
throw new BadDataException('User not found');
}
Expand Down
21 changes: 10 additions & 11 deletions Dashboard/src/Pages/Incidents/View/StateTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import BadDataException from 'Common/Types/Exception/BadDataException';
import FormFieldSchemaType from 'CommonUI/src/Components/Forms/Types/FormFieldSchemaType';
import IncidentState from 'Model/Models/IncidentState';
import FieldType from 'CommonUI/src/Components/Types/FieldType';
import { JSONObject } from 'Common/Types/JSON';
import Color from 'Common/Types/Color';
import Pill from 'CommonUI/src/Components/Pill/Pill';
import Navigation from 'CommonUI/src/Utils/Navigation';
Expand Down Expand Up @@ -58,7 +57,7 @@ const IncidentViewStateTimeline: FunctionComponent<PageComponentProps> = (
buttonStyleType: ButtonStyleType.NORMAL,
icon: IconProp.TransparentCube,
onClick: async (
item: JSONObject,
item: IncidentStateTimeline,
onCompleteAction: VoidFunction
) => {
setRootCause(
Expand All @@ -76,7 +75,7 @@ const IncidentViewStateTimeline: FunctionComponent<PageComponentProps> = (
buttonStyleType: ButtonStyleType.NORMAL,
icon: IconProp.List,
onClick: async (
item: JSONObject,
item: IncidentStateTimeline,
onCompleteAction: VoidFunction
) => {
setLogs(
Expand Down Expand Up @@ -187,7 +186,9 @@ const IncidentViewStateTimeline: FunctionComponent<PageComponentProps> = (
title: 'Incident Status',
type: FieldType.Text,

getElement: (item: JSONObject): ReactElement => {
getElement: (
item: IncidentStateTimeline
): ReactElement => {
if (!item['incidentState']) {
throw new BadDataException(
'Incident Status not found'
Expand All @@ -197,14 +198,10 @@ const IncidentViewStateTimeline: FunctionComponent<PageComponentProps> = (
return (
<Pill
color={
(item['incidentState'] as JSONObject)[
'color'
] as Color
item['incidentState']['color'] as Color
}
text={
(item['incidentState'] as JSONObject)[
'name'
] as string
item['incidentState']['name'] as string
}
/>
);
Expand All @@ -231,7 +228,9 @@ const IncidentViewStateTimeline: FunctionComponent<PageComponentProps> = (
},
title: 'Duration',
type: FieldType.Text,
getElement: (item: JSONObject): ReactElement => {
getElement: (
item: IncidentStateTimeline
): ReactElement => {
return (
<p>
{OneUptimeDate.differenceBetweenTwoDatesAsFromattedString(
Expand Down
3 changes: 1 addition & 2 deletions Dashboard/src/Pages/Monitor/View/Criteria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Monitor from 'Model/Models/Monitor';
import CardModelDetail from 'CommonUI/src/Components/ModelDetail/CardModelDetail';
import IconProp from 'Common/Types/Icon/IconProp';
import FormFieldSchemaType from 'CommonUI/src/Components/Forms/Types/FormFieldSchemaType';
import { JSONObject } from 'Common/Types/JSON';
import MonitorStepsViewer from '../../../Components/Monitor/MonitorSteps/MonitorSteps';
import {
CustomElementProps,
Expand Down Expand Up @@ -159,7 +158,7 @@ const MonitorCriteria: FunctionComponent<PageComponentProps> = (
monitorSteps: true,
},
title: '',
getElement: (item: JSONObject): ReactElement => {
getElement: (item: Monitor): ReactElement => {
return (
<MonitorStepsViewer
monitorSteps={
Expand Down
Loading

0 comments on commit 3a7c9f7

Please sign in to comment.