Skip to content

Commit

Permalink
Refactor Dashboard components for improved readability and consistenc…
Browse files Browse the repository at this point in the history
…y in code formatting
  • Loading branch information
simlarsen committed Nov 6, 2024
1 parent 7fd0000 commit 988d828
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 33 deletions.
6 changes: 2 additions & 4 deletions Dashboard/src/Components/Dashboard/Canvas/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ const DashboardCanvas: FunctionComponent<ComponentProps> = (
string | null
>(null);

type RenderComponentFunction = (
componentId: ObjectID,
) => ReactElement;
type RenderComponentFunction = (componentId: ObjectID) => ReactElement;

const renderComponent: RenderComponentFunction = (
componentId: ObjectID,
Expand Down Expand Up @@ -158,7 +156,7 @@ const DashboardCanvas: FunctionComponent<ComponentProps> = (
component.componentId.toString() ===
updatedComponent.componentId.toString()
) {
return {...updatedComponent};
return { ...updatedComponent };
}

return component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ export interface ComponentProps extends DashboardBaseComponentProps {
const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {

const component: DashboardBaseComponent = props.dashboardViewConfig.components.find(
(component: DashboardBaseComponent) => component.componentId.toString() === props.componentId.toString(),
) as DashboardBaseComponent;
const component: DashboardBaseComponent =
props.dashboardViewConfig.components.find(
(component: DashboardBaseComponent) => {
return (
component.componentId.toString() === props.componentId.toString()
);
},
) as DashboardBaseComponent;

const widthOfComponent: number = component.widthInDashboardUnits;
const heightOfComponent: number = component.heightInDashboardUnits;
Expand All @@ -69,20 +73,20 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
const dashboardComponentRef: React.RefObject<HTMLDivElement> =
React.useRef<HTMLDivElement>(null);


const refreshTopAndLeftInPx: () => void = () => {
if (dashboardComponentRef.current === null) {
return;
}

const topInPx: number = dashboardComponentRef.current.getBoundingClientRect().top;
const leftInPx: number = dashboardComponentRef.current.getBoundingClientRect().left;
const topInPx: number =
dashboardComponentRef.current.getBoundingClientRect().top;
const leftInPx: number =
dashboardComponentRef.current.getBoundingClientRect().left;

setTopInPx(topInPx);
setLeftInPx(leftInPx);
};


useEffect(() => {
refreshTopAndLeftInPx();
}, [props.dashboardViewConfig]);
Expand All @@ -93,8 +97,7 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
mouseEvent: MouseEvent,
): void => {
const dashboardComponentOldTopInPx: number = topInPx;
const dashboardComponentOldLeftInPx: number =
leftInPx;
const dashboardComponentOldLeftInPx: number = leftInPx;

const newMoveToTop: number = mouseEvent.pageY;
const newMoveToLeft: number = mouseEvent.pageX;
Expand Down Expand Up @@ -292,8 +295,8 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
stopResizeAndMove();
}}
className="move-element cursor-move absolute w-4 h-4 bg-blue-300 hover:bg-blue-400 rounded-full cursor-pointer"
onDragStart={(_event: React.DragEvent<HTMLDivElement>) => { }}
onDragEnd={(_event: React.DragEvent<HTMLDivElement>) => { }}
onDragStart={(_event: React.DragEvent<HTMLDivElement>) => {}}
onDragEnd={(_event: React.DragEvent<HTMLDivElement>) => {}}
></div>
);
};
Expand Down Expand Up @@ -354,14 +357,16 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
}}
style={{
margin: `${MarginForEachUnitInPx}px`,
height: `${GetDashboardUnitHeightInPx(props.totalCurrentDashboardWidthInPx) *
heightOfComponent +
height: `${
GetDashboardUnitHeightInPx(props.totalCurrentDashboardWidthInPx) *
heightOfComponent +
SpaceBetweenUnitsInPx * (heightOfComponent - 1)
}px`,
width: `${GetDashboardUnitWidthInPx(props.totalCurrentDashboardWidthInPx) *
widthOfComponent +
}px`,
width: `${
GetDashboardUnitWidthInPx(props.totalCurrentDashboardWidthInPx) *
widthOfComponent +
(SpaceBetweenUnitsInPx - 2) * (widthOfComponent - 1)
}px`,
}px`,
}}
ref={dashboardComponentRef}
>
Expand Down
5 changes: 4 additions & 1 deletion Dashboard/src/Components/Dashboard/DashboardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ const DashboardViewer: FunctionComponent<ComponentProps> = (
return;
}

setDashboardViewConfig(dashboard.dashboardViewConfig || DashboardViewConfigUtil.createDefaultDashboardViewConfig());
setDashboardViewConfig(
dashboard.dashboardViewConfig ||
DashboardViewConfigUtil.createDefaultDashboardViewConfig(),
);
} catch (err) {
setError(API.getFriendlyErrorMessage(err as Error));
}
Expand Down
30 changes: 20 additions & 10 deletions Worker/Jobs/IncidentOwners/SendStateChangeNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import EmailTemplateType from "Common/Types/Email/EmailTemplateType";
import NotificationSettingEventType from "Common/Types/NotificationSetting/NotificationSettingEventType";
import ObjectID from "Common/Types/ObjectID";
import { SMSMessage } from "Common/Types/SMS/SMS";
import Text from "Common/Types/Text";
import { EVERY_MINUTE } from "Common/Utils/CronTime";
import IncidentService from "Common/Server/Services/IncidentService";
import IncidentStateTimelineService from "Common/Server/Services/IncidentStateTimelineService";
Expand Down Expand Up @@ -47,6 +46,7 @@ RunCron(
incidentId: true,
incidentState: {
name: true,
isResolvedState: true,
},
},
});
Expand Down Expand Up @@ -129,6 +129,13 @@ RunCron(
continue;
}

const resourcesAffected: string =
incident
.monitors!.map((monitor: Monitor) => {
return monitor.name!;
})
.join(", ") || "";

for (const user of owners) {
const vars: Dictionary<string> = {
incidentTitle: incident.title!,
Expand All @@ -138,12 +145,7 @@ RunCron(
incident.description! || "",
MarkdownContentType.Email,
),
resourcesAffected:
incident
.monitors!.map((monitor: Monitor) => {
return monitor.name!;
})
.join(", ") || "None",
resourcesAffected: resourcesAffected || "None",
stateChangedAt:
OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones({
date: incidentStateTimeline.createdAt!,
Expand All @@ -162,12 +164,20 @@ RunCron(
vars["isOwner"] = "true";
}

let subjectLine: string = `[Incident] ${incident.title!}`;

if (incidentState.isResolvedState) {
if (resourcesAffected) {
subjectLine = `[Incident] Incident on ${resourcesAffected} is resolved`;
} else {
subjectLine = `[Incident] Incident is resolved`;
}
}

const emailMessage: EmailEnvelope = {
templateType: EmailTemplateType.IncidentOwnerStateChanged,
vars: vars,
subject: `[Incident ${Text.uppercaseFirstLetter(
incidentState!.name!,
)}] ${incident.title!}`,
subject: subjectLine,
};

const sms: SMSMessage = {
Expand Down

0 comments on commit 988d828

Please sign in to comment.