Skip to content

Commit

Permalink
refactor: Update TelemetryExceptionElement to handle archived exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Aug 29, 2024
1 parent bc9a8c5 commit e85f8c1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Dashboard/src/Components/Exceptions/ExceptionElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const TelemetryExceptionElement: FunctionComponent<ComponentProps> = (
};

const getArchivedIcon: GetReactElementFunction = (): ReactElement => {
if (!props.isResolved || !props.isArchived) {
if (!props.isArchived) {
return <></>;
}

Expand Down
83 changes: 54 additions & 29 deletions Dashboard/src/Components/Exceptions/ExceptionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import RouteMap, { RouteUtil } from "../../Utils/RouteMap";
import Route from "Common/Types/API/Route";
import PageMap from "../../Utils/PageMap";
import User from "Common/Models/DatabaseModels/User";
import { BulkActionFailed, BulkActionOnClickProps } from "Common/UI/Components/BulkUpdate/BulkUpdateForm";
import {
BulkActionFailed,
BulkActionOnClickProps,
} from "Common/UI/Components/BulkUpdate/BulkUpdateForm";
import { ModalTableBulkDefaultActions } from "Common/UI/Components/ModelTable/BaseModelTable";
import { ButtonStyleType } from "Common/UI/Components/Button/Button";
import BadDataException from "Common/Types/Exception/BadDataException";
Expand Down Expand Up @@ -72,15 +75,19 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (
}}
bulkActions={{
buttons: [

{
title: "Resolve",
buttonStyleType: ButtonStyleType.NORMAL,
onClick: async (props: BulkActionOnClickProps<TelemetryException>) => {
const inProgressItems: Array<TelemetryException> = [...props.items]; // items to be disabled
onClick: async (
props: BulkActionOnClickProps<TelemetryException>,
) => {
const inProgressItems: Array<TelemetryException> = [
...props.items,
]; // items to be disabled
const totalItems: Array<TelemetryException> = [...props.items]; // total items
const successItems: Array<TelemetryException> = []; // items that are disabled
const failedItems: Array<BulkActionFailed<TelemetryException>> = []; // items that failed to disable
const failedItems: Array<BulkActionFailed<TelemetryException>> =
[]; // items that failed to disable

props.onBulkActionStart();

Expand All @@ -91,18 +98,20 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (

try {
if (!exception.id) {
throw new BadDataException("Telemetry Exception ID not found");
throw new BadDataException(
"Telemetry Exception ID not found",
);
}

if (!exception.isResolved) {

await ModelAPI.updateById<TelemetryException>({
id: exception.id,
modelType: TelemetryException,
data: {
isResolved: true,
markedAsResolvedAt: OneUptimeDate.getCurrentDate(),
markedAsResolvedByUserId: UserUtil.getUserId() || null
markedAsResolvedByUserId:
UserUtil.getUserId() || null,
},
});
}
Expand Down Expand Up @@ -137,11 +146,16 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (
{
title: "Unresolve",
buttonStyleType: ButtonStyleType.NORMAL,
onClick: async (props: BulkActionOnClickProps<TelemetryException>) => {
const inProgressItems: Array<TelemetryException> = [...props.items]; // items to be disabled
onClick: async (
props: BulkActionOnClickProps<TelemetryException>,
) => {
const inProgressItems: Array<TelemetryException> = [
...props.items,
]; // items to be disabled
const totalItems: Array<TelemetryException> = [...props.items]; // total items
const successItems: Array<TelemetryException> = []; // items that are disabled
const failedItems: Array<BulkActionFailed<TelemetryException>> = []; // items that failed to disable
const failedItems: Array<BulkActionFailed<TelemetryException>> =
[]; // items that failed to disable

props.onBulkActionStart();

Expand All @@ -152,18 +166,19 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (

try {
if (!exception.id) {
throw new BadDataException("Telemetry Exception ID not found");
throw new BadDataException(
"Telemetry Exception ID not found",
);
}

if (exception.isResolved) {

await ModelAPI.updateById<TelemetryException>({
id: exception.id,
modelType: TelemetryException,
data: {
isResolved: false,
markedAsResolvedAt: null,
markedAsResolvedByUserId: null
markedAsResolvedByUserId: null,
},
});
}
Expand Down Expand Up @@ -200,11 +215,16 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (
{
title: "Archive",
buttonStyleType: ButtonStyleType.NORMAL,
onClick: async (props: BulkActionOnClickProps<TelemetryException>) => {
const inProgressItems: Array<TelemetryException> = [...props.items]; // items to be disabled
onClick: async (
props: BulkActionOnClickProps<TelemetryException>,
) => {
const inProgressItems: Array<TelemetryException> = [
...props.items,
]; // items to be disabled
const totalItems: Array<TelemetryException> = [...props.items]; // total items
const successItems: Array<TelemetryException> = []; // items that are disabled
const failedItems: Array<BulkActionFailed<TelemetryException>> = []; // items that failed to disable
const failedItems: Array<BulkActionFailed<TelemetryException>> =
[]; // items that failed to disable

props.onBulkActionStart();

Expand All @@ -215,18 +235,20 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (

try {
if (!exception.id) {
throw new BadDataException("Telemetry Exception ID not found");
throw new BadDataException(
"Telemetry Exception ID not found",
);
}

if (!exception.isArchived) {

await ModelAPI.updateById<TelemetryException>({
id: exception.id,
modelType: TelemetryException,
data: {
isArchived: true,
markedAsArchivedAt: OneUptimeDate.getCurrentDate(),
markedAsArchivedByUserId: UserUtil.getUserId() || null
markedAsArchivedByUserId:
UserUtil.getUserId() || null,
},
});
}
Expand Down Expand Up @@ -261,11 +283,16 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (
{
title: "Unarchive",
buttonStyleType: ButtonStyleType.NORMAL,
onClick: async (props: BulkActionOnClickProps<TelemetryException>) => {
const inProgressItems: Array<TelemetryException> = [...props.items]; // items to be disabled
onClick: async (
props: BulkActionOnClickProps<TelemetryException>,
) => {
const inProgressItems: Array<TelemetryException> = [
...props.items,
]; // items to be disabled
const totalItems: Array<TelemetryException> = [...props.items]; // total items
const successItems: Array<TelemetryException> = []; // items that are disabled
const failedItems: Array<BulkActionFailed<TelemetryException>> = []; // items that failed to disable
const failedItems: Array<BulkActionFailed<TelemetryException>> =
[]; // items that failed to disable

props.onBulkActionStart();

Expand All @@ -276,18 +303,19 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (

try {
if (!exception.id) {
throw new BadDataException("Telemetry Exception ID not found");
throw new BadDataException(
"Telemetry Exception ID not found",
);
}

if (exception.isArchived) {

await ModelAPI.updateById<TelemetryException>({
id: exception.id,
modelType: TelemetryException,
data: {
isArchived: false,
markedAsArchivedAt: null,
markedAsArchivedByUserId: null
markedAsArchivedByUserId: null,
},
});
}
Expand All @@ -309,7 +337,6 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (
}

props.onBulkActionEnd();

},

icon: IconProp.Unarchive,
Expand All @@ -321,15 +348,13 @@ const TelemetryExceptionTable: FunctionComponent<ComponentProps> = (
},
},


ModalTableBulkDefaultActions.Delete,
],
}}
showViewIdButton={false}
noItemsMessage={"No exceptions found."}
showRefreshButton={true}
viewPageRoute={viewRoute}

filters={[
{
field: {
Expand Down

0 comments on commit e85f8c1

Please sign in to comment.