Skip to content

Commit

Permalink
refactor: clean up code formatting and improve readability in Alert c…
Browse files Browse the repository at this point in the history
…omponents
  • Loading branch information
simlarsen committed Jan 17, 2025
1 parent b55bb4c commit c19913a
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 85 deletions.
66 changes: 15 additions & 51 deletions Dashboard/src/Components/Alert/AlertFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,27 @@ const AlertFeedElement: FunctionComponent<ComponentProps> = (
});
};

type GetFeedItemFromAlertFeed = (
alertFeed: AlertFeed,
) => FeedItemProps;
type GetFeedItemFromAlertFeed = (alertFeed: AlertFeed) => FeedItemProps;

const getFeedItemFromAlertFeed: GetFeedItemFromAlertFeed = (
alertFeed: AlertFeed,
): FeedItemProps => {
let icon: IconProp = IconProp.Circle;

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.AlertCreated
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.AlertCreated) {
icon = IconProp.Alert;
}

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.AlertStateChanged
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.AlertStateChanged) {
icon = IconProp.ArrowCircleRight;
}

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.AlertUpdated
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.AlertUpdated) {
icon = IconProp.Edit;
}

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.OwnerNotificationSent
alertFeed.alertFeedEventType === AlertFeedEventType.OwnerNotificationSent
) {
icon = IconProp.Bell;
}
Expand All @@ -93,69 +81,45 @@ const AlertFeedElement: FunctionComponent<ComponentProps> = (
icon = IconProp.Notification;
}

if (
alertFeed.alertFeedEventType === AlertFeedEventType.PublicNote
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.PublicNote) {
icon = IconProp.Announcement;
}

if (
alertFeed.alertFeedEventType === AlertFeedEventType.PrivateNote
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.PrivateNote) {
icon = IconProp.Lock;
}

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.OwnerUserAdded
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.OwnerUserAdded) {
icon = IconProp.User;
}

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.OwnerTeamAdded
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.OwnerTeamAdded) {
icon = IconProp.Team;
}

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.RemediationNotes
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.RemediationNotes) {
icon = IconProp.Wrench;
}

if (
alertFeed.alertFeedEventType === AlertFeedEventType.RootCause
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.RootCause) {
icon = IconProp.Cube;
}

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.OwnerUserRemoved
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.OwnerUserRemoved) {
icon = IconProp.Close;
}

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.OwnerTeamRemoved
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.OwnerTeamRemoved) {
icon = IconProp.Close;
}

if (
alertFeed.alertFeedEventType ===
AlertFeedEventType.OnCallNotification
alertFeed.alertFeedEventType === AlertFeedEventType.OnCallNotification
) {
icon = IconProp.Alert;
}

if (
alertFeed.alertFeedEventType === AlertFeedEventType.OnCallPolicy
) {
if (alertFeed.alertFeedEventType === AlertFeedEventType.OnCallPolicy) {
icon = IconProp.Call;
}

Expand Down
13 changes: 6 additions & 7 deletions Dashboard/src/Components/Alert/ChangeState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,11 @@ const ChangeAlertState: FunctionComponent<ComponentProps> = (
}}
onSuccess={(model: AlertStateTimeline) => {
//get alert state and update current alert state
const alertState: AlertState | undefined =
alertStates.find((state: AlertState) => {
return (
state.id?.toString() === model.alertStateId?.toString()
);
});
const alertState: AlertState | undefined = alertStates.find(
(state: AlertState) => {
return state.id?.toString() === model.alertStateId?.toString();
},
);

setCurrentAlertState(alertState);

Expand All @@ -237,7 +236,7 @@ const ChangeAlertState: FunctionComponent<ComponentProps> = (
required: false,
overrideFieldKey: "privateNote",
showEvenIfPermissionDoesNotExist: true,
}
},
],
formType: FormType.Create,
}}
Expand Down
4 changes: 1 addition & 3 deletions Dashboard/src/Pages/Alerts/View/Description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import CardModelDetail from "Common/UI/Components/ModelDetail/CardModelDetail";
import FormFieldSchemaType from "Common/UI/Components/Forms/Types/FormFieldSchemaType";
import FieldType from "Common/UI/Components/Types/FieldType";

const AlertDelete: FunctionComponent<
PageComponentProps
> = (): ReactElement => {
const AlertDelete: FunctionComponent<PageComponentProps> = (): ReactElement => {
const modelId: ObjectID = Navigation.getLastParamAsObjectID(1);

return (
Expand Down
4 changes: 1 addition & 3 deletions Dashboard/src/Pages/Alerts/View/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ const AlertView: FunctionComponent<PageComponentProps> = (): ReactElement => {
getElement: (item: Alert): ReactElement => {
return <LabelsElement labels={item["labels"] || []} />;
},
}

},
],
modelId: modelId,
}}
Expand All @@ -506,7 +505,6 @@ const AlertView: FunctionComponent<PageComponentProps> = (): ReactElement => {
/>
</div>


{telemetryQuery &&
telemetryQuery.telemetryType === TelemetryType.Log &&
telemetryQuery.telemetryQuery && (
Expand Down
4 changes: 1 addition & 3 deletions Dashboard/src/Pages/Alerts/View/Remediation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import CardModelDetail from "Common/UI/Components/ModelDetail/CardModelDetail";
import FormFieldSchemaType from "Common/UI/Components/Forms/Types/FormFieldSchemaType";
import FieldType from "Common/UI/Components/Types/FieldType";

const AlertDelete: FunctionComponent<
PageComponentProps
> = (): ReactElement => {
const AlertDelete: FunctionComponent<PageComponentProps> = (): ReactElement => {
const modelId: ObjectID = Navigation.getLastParamAsObjectID(1);

return (
Expand Down
4 changes: 1 addition & 3 deletions Dashboard/src/Pages/Alerts/View/RootCause.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import React, { FunctionComponent, ReactElement } from "react";
import CardModelDetail from "Common/UI/Components/ModelDetail/CardModelDetail";
import FieldType from "Common/UI/Components/Types/FieldType";

const AlertDelete: FunctionComponent<
PageComponentProps
> = (): ReactElement => {
const AlertDelete: FunctionComponent<PageComponentProps> = (): ReactElement => {
const modelId: ObjectID = Navigation.getLastParamAsObjectID(1);

return (
Expand Down
1 change: 0 additions & 1 deletion Dashboard/src/Pages/Alerts/View/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const DashboardSideMenu: FunctionComponent<ComponentProps> = (
icon={IconProp.Wrench}
/>


<SideMenuItem
link={{
title: "State Timeline",
Expand Down
17 changes: 6 additions & 11 deletions Dashboard/src/Routes/AlertRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ const AlertViewOwner: LazyExoticComponent<FunctionComponent<ComponentProps>> =
return import("../Pages/Alerts/View/Owners");
});



const AlertViewRootCause: LazyExoticComponent<
const AlertViewRootCause: LazyExoticComponent<
FunctionComponent<ComponentProps>
> = lazy(() => {
return import("../Pages/Alerts/View/RootCause");
Expand All @@ -66,15 +64,13 @@ const AlertViewRemediation: LazyExoticComponent<
FunctionComponent<ComponentProps>
> = lazy(() => {
return import("../Pages/Alerts/View/Remediation");
}
);

const AlertDescription: LazyExoticComponent<
FunctionComponent<ComponentProps>
> = lazy(() => {
return import("../Pages/Alerts/View/Description");
});

const AlertDescription: LazyExoticComponent<FunctionComponent<ComponentProps>> =
lazy(() => {
return import("../Pages/Alerts/View/Description");
});

const AlertsRoutes: FunctionComponent<ComponentProps> = (
props: ComponentProps,
) => {
Expand Down Expand Up @@ -167,7 +163,6 @@ const AlertsRoutes: FunctionComponent<ComponentProps> = (
/>
</Suspense>
}

/>

<PageRoute
Expand Down
3 changes: 0 additions & 3 deletions Dashboard/src/Utils/Breadcrumbs/AlertBreadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ export function getAlertsBreadcrumbs(path: string): Array<Link> | undefined {
"Alerts",
"Description",
]),



};
return breadcrumpLinksMap[path];
}

0 comments on commit c19913a

Please sign in to comment.