diff --git a/Dashboard/src/Components/OnCallDutySchedule/ScheduleElement.tsx b/Dashboard/src/Components/OnCallDutySchedule/ScheduleElement.tsx index c568e52958..2954172bb5 100644 --- a/Dashboard/src/Components/OnCallDutySchedule/ScheduleElement.tsx +++ b/Dashboard/src/Components/OnCallDutySchedule/ScheduleElement.tsx @@ -1,42 +1,98 @@ +import OnCallDutySchedule from "Common/Models/DatabaseModels/OnCallDutyPolicySchedule"; +import BaseModel from "Common/Models/DatabaseModels/DatabaseBaseModel/DatabaseBaseModel"; +import { JSONObject } from "Common/Types/JSON"; +import JSONFunctions from "Common/Types/JSONFunctions"; +import Icon from "Common/UI/Components/Icon/Icon"; +import IconProp from "Common/Types/Icon/IconProp"; import Route from "Common/Types/API/Route"; import AppLink from "../AppLink/AppLink"; -import OnCallDutySchedule from "Common/Models/DatabaseModels/OnCallDutyPolicySchedule"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - schedule: OnCallDutySchedule; + schedule?: OnCallDutySchedule | JSONObject | undefined | null; + prefix?: string | undefined; + suffix?: string | undefined; + suffixClassName?: string | undefined; + scheduleNameClassName?: string | undefined; + prefixClassName?: string | undefined; onNavigateComplete?: (() => void) | undefined; } const OnCallDutyScheduleElement: FunctionComponent = ( props: ComponentProps, ): ReactElement => { - if ( - props.schedule._id && - (props.schedule.projectId || - (props.schedule.project && props.schedule.project._id)) - ) { - const projectId: string | undefined = props.schedule.projectId - ? props.schedule.projectId.toString() - : props.schedule.project - ? props.schedule.project._id - : ""; - return ( - - {props.schedule.name} - - ); + let schedule: JSONObject | null | undefined = null; + + if (props.schedule instanceof OnCallDutySchedule) { + schedule = BaseModel.toJSONObject(props.schedule, OnCallDutySchedule); + } else { + schedule = props.schedule; } - return {props.schedule.name}; + if (JSONFunctions.isEmptyObject(schedule)) { + return <>; + } + + if (schedule) { + const scheduleName: string = + (schedule["name"]?.toString() as string) || "On-Call Schedule"; + + const scheduleId: string | undefined = + schedule["_id"]?.toString() || schedule["id"]?.toString(); + + const projectId: string | undefined = + schedule["projectId"]?.toString() || + (schedule["project"] as JSONObject)?.["_id"]?.toString(); + + const content: ReactElement = ( +
+
+ +
+
+
+ + {props.prefix} + {" "} + + {scheduleName} + {" "} +
+
+ {props.suffix && ( +
+

{props.suffix}

+
+ )} +
+ ); + + if (scheduleId && projectId) { + return ( + + {content} + + ); + } + + return content; + } + + return <>; }; export default OnCallDutyScheduleElement; diff --git a/Dashboard/src/Components/OnCallDutySchedule/SchedulesElement.tsx b/Dashboard/src/Components/OnCallDutySchedule/SchedulesElement.tsx index 45eedd182b..3bc7cd7bf6 100644 --- a/Dashboard/src/Components/OnCallDutySchedule/SchedulesElement.tsx +++ b/Dashboard/src/Components/OnCallDutySchedule/SchedulesElement.tsx @@ -4,7 +4,6 @@ import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { schedules: Array; - onNavigateComplete?: (() => void) | undefined; } const OnCallDutySchedulesElement: FunctionComponent = ( @@ -19,10 +18,7 @@ const OnCallDutySchedulesElement: FunctionComponent = ( {props.schedules.map((schedule: OnCallDutySchedule, i: number) => { return ( - + {i !== props.schedules.length - 1 && } ); diff --git a/Dashboard/src/Pages/OnCallDuty/IncomingCallPolicy/Escalation.tsx b/Dashboard/src/Pages/OnCallDuty/IncomingCallPolicy/Escalation.tsx index 90455c2ea5..802413077c 100644 --- a/Dashboard/src/Pages/OnCallDuty/IncomingCallPolicy/Escalation.tsx +++ b/Dashboard/src/Pages/OnCallDuty/IncomingCallPolicy/Escalation.tsx @@ -11,6 +11,7 @@ import FormFieldSchemaType from "Common/UI/Components/Forms/Types/FormFieldSchem import FormValues from "Common/UI/Components/Forms/Types/FormValues"; import FieldType from "Common/UI/Components/Types/FieldType"; import UserElement from "../../../Components/User/User"; +import OnCallDutyScheduleElement from "../../../Components/OnCallDutySchedule/ScheduleElement"; import BadDataException from "Common/Types/Exception/BadDataException"; import ProjectUtil from "Common/UI/Utils/Project"; import SortOrder from "Common/Types/BaseDatabase/SortOrder"; @@ -250,7 +251,9 @@ const IncomingCallPolicyEscalationPage: FunctionComponent< { field: { onCallDutyPolicySchedule: { + _id: true, name: true, + projectId: true, }, }, title: "On-Call Schedule", @@ -260,8 +263,12 @@ const IncomingCallPolicyEscalationPage: FunctionComponent< getElement: ( item: IncomingCallPolicyEscalationRule, ): ReactElement => { - if (item.onCallDutyPolicySchedule?.name) { - return {item.onCallDutyPolicySchedule.name}; + if (item.onCallDutyPolicySchedule) { + return ( + + ); } return <>; },