Skip to content

Commit

Permalink
refactor: clean up code formatting and remove unused props in Schedul…
Browse files Browse the repository at this point in the history
…ed Maintenance components
  • Loading branch information
simlarsen committed Jan 23, 2025
1 parent b2cb95e commit ea38e26
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import BasicFormModal from "Common/UI/Components/FormModal/BasicFormModal";
import DropdownUtil from "Common/UI/Utils/Dropdown";
import IconProp from "Common/Types/Icon/IconProp";
import { ButtonStyleType } from "Common/UI/Components/Button/Button";
import FormValues from "Common/UI/Components/Forms/Types/FormValues";
import { SaveFilterProps } from "Common/UI/Components/ModelTable/BaseModelTable";
import Navigation from "Common/UI/Utils/Navigation";
import RouteMap, { RouteUtil } from "../../Utils/RouteMap";
Expand All @@ -40,7 +39,6 @@ export interface ComponentProps {
title?: string | undefined;
description?: string | undefined;
disableCreate?: boolean | undefined;
createInitialValues?: FormValues<ScheduledMaintenance> | undefined;
saveFilterProps?: SaveFilterProps | undefined;
}

Expand All @@ -56,36 +54,34 @@ const ScheduledMaintenancesTable: FunctionComponent<ComponentProps> = (
setShowScheduledMaintenanceTemplateModal,
] = useState<boolean>(false);


let cardbuttons: Array<CardButtonSchema> = [];

const fetchScheduledMaintenanceTemplates: () => Promise<void> =
async (): Promise<void> => {
setError("");
setIsLoading(true);

async (): Promise<void> => {
setError("");
setIsLoading(true);

try {
const listResult: ListResult<ScheduledMaintenanceTemplate> =
await ModelAPI.getList<ScheduledMaintenanceTemplate>({
modelType: ScheduledMaintenanceTemplate,
query: {},
limit: LIMIT_PER_PROJECT,
skip: 0,
select: {
templateName: true,
_id: true,
},
sort: {},
});
try {
const listResult: ListResult<ScheduledMaintenanceTemplate> =
await ModelAPI.getList<ScheduledMaintenanceTemplate>({
modelType: ScheduledMaintenanceTemplate,
query: {},
limit: LIMIT_PER_PROJECT,
skip: 0,
select: {
templateName: true,
_id: true,
},
sort: {},
});

setScheduledMaintenanceTemplates(listResult.data);
} catch (err) {
setError(API.getFriendlyMessage(err));
}
setScheduledMaintenanceTemplates(listResult.data);
} catch (err) {
setError(API.getFriendlyMessage(err));
}

setIsLoading(false);
};
setIsLoading(false);
};

if (!props.disableCreate) {
// then add a card button that takes to monitor create page
Expand Down Expand Up @@ -114,9 +110,6 @@ const ScheduledMaintenancesTable: FunctionComponent<ComponentProps> = (
];
}




return (
<div>
<ModelTable<ScheduledMaintenance>
Expand All @@ -129,20 +122,17 @@ const ScheduledMaintenancesTable: FunctionComponent<ComponentProps> = (
isCreateable={false}
isViewable={true}
saveFilterProps={props.saveFilterProps}
showCreateForm={
false
}
showCreateForm={false}
cardProps={{
title: props.title || "Scheduled Maintenance Events",
description:
props.description ||
"Here is a list of scheduled maintenance events for this project.",
buttons: cardbuttons
buttons: cardbuttons,
}}
noItemsMessage={
props.noItemsMessage || "No scheduled Maintenance Event found."
}

showViewIdButton={true}
viewButtonText="View Event"
showRefreshButton={true}
Expand Down Expand Up @@ -382,7 +372,6 @@ const ScheduledMaintenancesTable: FunctionComponent<ComponentProps> = (
setIsLoading(false);
}}
onSubmit={async (data: JSONObject) => {

const scheduledMaintenanceTemplateId: ObjectID = data[
"scheduledMaintenanceTemplateId"
] as ObjectID;
Expand All @@ -391,9 +380,14 @@ const ScheduledMaintenancesTable: FunctionComponent<ComponentProps> = (
Navigation.navigate(
RouteUtil.populateRouteParams(
new Route(
(RouteMap[PageMap.SCHEDULED_MAINTENANCE_EVENT_CREATE] as Route).toString(),
(
RouteMap[
PageMap.SCHEDULED_MAINTENANCE_EVENT_CREATE
] as Route
).toString(),
).addQueryParams({
scheduledMaintenanceTemplateId: scheduledMaintenanceTemplateId.toString(),
scheduledMaintenanceTemplateId:
scheduledMaintenanceTemplateId.toString(),
}),
),
);
Expand Down
4 changes: 1 addition & 3 deletions Dashboard/src/Pages/Monitor/View/Incidents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ const MonitorIncidents: FunctionComponent<
return (
<Fragment>
<DisabledWarning monitorId={modelId} />
<IncidentsTable
query={query}
/>
<IncidentsTable query={query} />
</Fragment>
);
};
Expand Down
18 changes: 10 additions & 8 deletions Dashboard/src/Pages/ScheduledMaintenanceEvents/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ const ScheduledMaintenanceCreate: FunctionComponent<
const [isLoading, setIsLoading] = useState<boolean>(true);
const [error, setError] = useState<string>("");

const [initialValuesForScheduledMaintenance, setInitialValuesForScheduledMaintenance] =
useState<JSONObject>({});
const [
initialValuesForScheduledMaintenance,
setInitialValuesForScheduledMaintenance,
] = useState<JSONObject>({});

useEffect(() => {
if (Navigation.getQueryStringByName("scheduledMaintenanceTemplateId")) {
fetchScheduledMaintenanceTemplate(
new ObjectID(
Navigation.getQueryStringByName("scheduledMaintenanceTemplateId") || "",
Navigation.getQueryStringByName("scheduledMaintenanceTemplateId") ||
"",
),
);
} else {
Expand Down Expand Up @@ -156,7 +159,6 @@ const ScheduledMaintenanceCreate: FunctionComponent<
}

setIsLoading(false);

};

return (
Expand Down Expand Up @@ -338,12 +340,12 @@ const ScheduledMaintenanceCreate: FunctionComponent<
placeholder: "Select Users",
overrideFieldKey: "ownerUsers",
},

{
field: {
shouldStatusPageSubscribersBeNotifiedOnEventCreated: true,
},

title: "Event Created: Notify Status Page Subscribers",
stepId: "subscribers",
description:
Expand All @@ -357,7 +359,7 @@ const ScheduledMaintenanceCreate: FunctionComponent<
shouldStatusPageSubscribersBeNotifiedWhenEventChangedToOngoing:
true,
},

title: "Event Ongoing: Notify Status Page Subscribers",
stepId: "subscribers",
description:
Expand All @@ -371,7 +373,7 @@ const ScheduledMaintenanceCreate: FunctionComponent<
shouldStatusPageSubscribersBeNotifiedWhenEventChangedToEnded:
true,
},

title: "Event Ended: Notify Status Page Subscribers",
stepId: "subscribers",
description:
Expand Down
12 changes: 8 additions & 4 deletions Dashboard/src/Pages/ScheduledMaintenanceEvents/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import Navigation from "Common/UI/Utils/Navigation";
import React, { FunctionComponent, ReactElement } from "react";
import { Outlet } from "react-router-dom";

const ScheduledMaintenancesLayout: FunctionComponent<LayoutPageComponentProps> = (
props: LayoutPageComponentProps,
): ReactElement => {
const ScheduledMaintenancesLayout: FunctionComponent<
LayoutPageComponentProps
> = (props: LayoutPageComponentProps): ReactElement => {
const path: string = Navigation.getRoutePath(RouteUtil.getRoutes());
return (
<Page
title={"Scheduled Maintenance Events"}
sideMenu={props.hideSideMenu ? undefined : <SideMenu project={props.currentProject || undefined} />}
sideMenu={
props.hideSideMenu ? undefined : (
<SideMenu project={props.currentProject || undefined} />
)
}
breadcrumbLinks={getScheduleMaintenanceBreadcrumbs(path)}
>
<Outlet />
Expand Down
23 changes: 13 additions & 10 deletions Dashboard/src/Routes/ScheduleMaintenaceEventsRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const ScheduledMaintenanceEventViewDescription: LazyExoticComponent<
return import("../Pages/ScheduledMaintenanceEvents/View/Description");
});


const ScheduledMaintenanceEventCreate: LazyExoticComponent<
FunctionComponent<ComponentProps>
> = lazy(() => {
Expand All @@ -84,17 +83,24 @@ const ScheduledMaintenanceEventCreate: LazyExoticComponent<
const ScheduledMaintenanceEventsRoutes: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {


let hideSideMenu: boolean = false;

if (Navigation.isOnThisPage(RouteMap[PageMap.SCHEDULED_MAINTENANCE_EVENT_CREATE] as Route)) {
if (
Navigation.isOnThisPage(
RouteMap[PageMap.SCHEDULED_MAINTENANCE_EVENT_CREATE] as Route,
)
) {
hideSideMenu = true;
}

return (
<Routes>
<PageRoute path="/" element={<ScheduledMaintenancesLaoyut {...props} hideSideMenu={hideSideMenu} />}>
<PageRoute
path="/"
element={
<ScheduledMaintenancesLaoyut {...props} hideSideMenu={hideSideMenu} />
}
>
<PageRoute
index
element={
Expand Down Expand Up @@ -128,8 +134,7 @@ const ScheduledMaintenanceEventsRoutes: FunctionComponent<ComponentProps> = (
}
/>


<PageRoute
<PageRoute
path={
ScheduledMaintenanceEventsRoutePath[
PageMap.SCHEDULED_MAINTENANCE_EVENT_CREATE
Expand All @@ -140,9 +145,7 @@ const ScheduledMaintenanceEventsRoutes: FunctionComponent<ComponentProps> = (
<ScheduledMaintenanceEventCreate
{...props}
pageRoute={
RouteMap[
PageMap.SCHEDULED_MAINTENANCE_EVENT_CREATE
] as Route
RouteMap[PageMap.SCHEDULED_MAINTENANCE_EVENT_CREATE] as Route
}
/>
</Suspense>
Expand Down

0 comments on commit ea38e26

Please sign in to comment.