Skip to content

Commit

Permalink
Refactor field types in multiple components to use specific model types
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Apr 21, 2024
1 parent 351734d commit 7f41ceb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Dashboard/src/Pages/OnCallDuty/OnCallDutyPolicy/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const OnCallDutyPolicyView: FunctionComponent<PageComponentProps> = (
return (
<Fragment>
{/* OnCallDutyPolicy View */}
<CardModelDetail
<CardModelDetail<OnCallDutyPolicy>
name="On-Call Policy > On-Call Policy Details"
cardProps={{
title: 'On-Call Policy Details',
Expand Down Expand Up @@ -105,7 +105,7 @@ const OnCallDutyPolicyView: FunctionComponent<PageComponentProps> = (
},
title: 'Labels',
fieldType: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: OnCallDutyPolicy): ReactElement => {
return (
<LabelsElement
labels={
Expand Down
4 changes: 2 additions & 2 deletions Dashboard/src/Pages/OnCallDuty/OnCallDutySchedule/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const OnCallDutyScheduleView: FunctionComponent<PageComponentProps> = (
return (
<Fragment>
{/* OnCallDutySchedule View */}
<CardModelDetail
<CardModelDetail<OnCallDutySchedule>
name="On-Call Schedule > On-Call Schedule Details"
cardProps={{
title: 'On-Call Schedule Details',
Expand Down Expand Up @@ -105,7 +105,7 @@ const OnCallDutyScheduleView: FunctionComponent<PageComponentProps> = (
},
title: 'Labels',
fieldType: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: OnCallDutySchedule): ReactElement => {
return (
<LabelsElement
labels={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,11 @@ const ScheduledMaintenanceDelete: FunctionComponent<PageComponentProps> = (

type: FieldType.Entity,

getElement: (item: JSONObject): ReactElement => {
getElement: (item: ScheduledMaintenanceInternalNote): ReactElement => {
return (
<UserElement
user={
BaseModel.fromJSON(
item['createdByUser'] as JSONObject,
User
) as User
item['createdByUser']
}
suffix={'wrote'}
usernameClassName={
Expand Down
45 changes: 16 additions & 29 deletions Dashboard/src/Pages/Settings/IncidentTemplatesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import ProjectUser from '../../Utils/ProjectUser';
import UserElement from '../../Components/User/User';
import User from 'Model/Models/User';
import ModelTable from 'CommonUI/src/Components/ModelTable/ModelTable';
import { Black } from 'Common/Types/BrandColors';

const TeamView: FunctionComponent<PageComponentProps> = (
_props: PageComponentProps
Expand All @@ -41,7 +42,7 @@ const TeamView: FunctionComponent<PageComponentProps> = (
return (
<Fragment>
{/* Incident View */}
<CardModelDetail
<CardModelDetail<IncidentTemplate>
name="Incident Template Details"
cardProps={{
title: 'Incident Template Details',
Expand Down Expand Up @@ -249,26 +250,18 @@ const TeamView: FunctionComponent<PageComponentProps> = (
},
title: 'Incident Severity',
fieldType: FieldType.Entity,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: IncidentTemplate): ReactElement => {
if (!item['incidentSeverity']) {
return <p>No incident severity.</p>;
}

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 @@ -283,16 +276,13 @@ const TeamView: FunctionComponent<PageComponentProps> = (
},
title: 'Monitors Affected',
fieldType: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: IncidentTemplate): ReactElement => {
return (
<MonitorsElement
monitors={
BaseModel.fromJSON(
(item[
'monitors'
] as JSONArray) || [],
Monitor
) as Array<Monitor>
item[
'monitors'
] || []
}
/>
);
Expand All @@ -307,16 +297,13 @@ const TeamView: FunctionComponent<PageComponentProps> = (
},
title: 'On-Call Duty Policies',
fieldType: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: IncidentTemplate): ReactElement => {
return (
<OnCallDutyPoliciesView
onCallPolicies={
BaseModel.fromJSON(
(item[
'onCallDutyPolicies'
] as JSONArray) || [],
OnCallDutyPolicy
) as Array<OnCallDutyPolicy>
item[
'onCallDutyPolicies'
] || []
}
/>
);
Expand All @@ -338,7 +325,7 @@ const TeamView: FunctionComponent<PageComponentProps> = (
},
title: 'Labels',
fieldType: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: IncidentTemplate): ReactElement => {
return (
<LabelsElement
labels={
Expand Down Expand Up @@ -421,7 +408,7 @@ const TeamView: FunctionComponent<PageComponentProps> = (
title: 'Team',
type: FieldType.Entity,

getElement: (item: JSONObject): ReactElement => {
getElement: (item: IncidentTemplateOwnerTeam): ReactElement => {
if (!item['team']) {
throw new BadDataException('Team not found');
}
Expand Down Expand Up @@ -509,7 +496,7 @@ const TeamView: FunctionComponent<PageComponentProps> = (
},
title: 'User',
type: FieldType.Entity,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: IncidentTemplateOwnerUser): ReactElement => {
if (!item['user']) {
throw new BadDataException('User not found');
}
Expand Down
2 changes: 1 addition & 1 deletion Dashboard/src/Pages/StatusPages/View/EmailSubscribers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ const StatusPageDelete: FunctionComponent<PageComponentProps> = (
title: 'Status',
type: FieldType.Text,
getElement: (
item: JSONObject
item: StatusPageSubscriber
): ReactElement => {
if (item['isUnsubscribed']) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const StatusPageDelete: FunctionComponent<PageComponentProps> = (
description:
'These monitor statuses are be considered as down when we calculate uptime %',
fieldType: FieldType.EntityArray,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: StatusPage): ReactElement => {
if (item['downtimeMonitorStatuses']) {
return (
<MonitorStatuesElement
Expand Down
4 changes: 2 additions & 2 deletions Dashboard/src/Pages/Telemetry/Services/View/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ServiceDelete: FunctionComponent<PageComponentProps> = (
return (
<Fragment>
{/* Service View */}
<CardModelDetail
<CardModelDetail<TelemetryService>
name="Service Details"
formSteps={[
{
Expand Down Expand Up @@ -104,7 +104,7 @@ const ServiceDelete: FunctionComponent<PageComponentProps> = (
},
title: 'Labels',
fieldType: FieldType.Element,
getElement: (item: JSONObject): ReactElement => {
getElement: (item: TelemetryService): ReactElement => {
return (
<LabelsElement
labels={
Expand Down

0 comments on commit 7f41ceb

Please sign in to comment.