From 4d1797e9fa43847e2521cdfa9c6ddb98d96f1fab Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Tue, 14 Jan 2025 18:16:51 +0000 Subject: [PATCH] refactor: clean up code formatting and remove unnecessary whitespace in various files --- Common/Models/DatabaseModels/AlertFeed.ts | 1 - Common/Models/DatabaseModels/IncidentFeed.ts | 4 - .../1736856662868-MigrationName.ts | 33 +- .../Postgres/SchemaMigrations/Index.ts | 2 +- Common/Server/Services/AlertFeedService.ts | 5 +- Common/Server/Services/IncidentFeedService.ts | 2 +- .../Services/IncidentInternalNoteService.ts | 1 - .../Services/IncidentOwnerTeamService.ts | 66 ++-- .../Services/IncidentOwnerUserService.ts | 64 ++-- Common/Server/Services/IncidentService.ts | 76 ++-- .../Services/IncidentStateTimelineService.ts | 10 +- .../OnCallDutyPolicyExecutionLogService.ts | 83 +++-- ...llDutyPolicyExecutionLogTimelineService.ts | 146 ++++---- .../ScheduledMaintenanceFeedService.ts | 5 +- Common/UI/Components/Feed/Feed.tsx | 10 +- Common/UI/Components/Feed/FeedItem.tsx | 192 +++++----- Common/UI/Components/Icon/Icon.tsx | 8 +- .../ProgressButtons/ProgressButtonItem.tsx | 98 +++-- .../ProgressButtons/ProgressButtons.tsx | 73 ++-- Common/UI/Utils/User.ts | 1 - .../src/Components/Incident/IncidentFeed.tsx | 340 ++++++++++-------- Dashboard/src/Components/User/User.tsx | 4 +- Dashboard/src/Pages/Incidents/View/Index.tsx | 5 +- 23 files changed, 669 insertions(+), 560 deletions(-) diff --git a/Common/Models/DatabaseModels/AlertFeed.ts b/Common/Models/DatabaseModels/AlertFeed.ts index 23562a7c80..9d6f73ff51 100644 --- a/Common/Models/DatabaseModels/AlertFeed.ts +++ b/Common/Models/DatabaseModels/AlertFeed.ts @@ -489,7 +489,6 @@ export default class AlertFeed extends BaseModel { }) public userId?: ObjectID = undefined; - @ColumnAccessControl({ create: [ Permission.ProjectOwner, diff --git a/Common/Models/DatabaseModels/IncidentFeed.ts b/Common/Models/DatabaseModels/IncidentFeed.ts index 6d92309ef3..865c3e7b90 100644 --- a/Common/Models/DatabaseModels/IncidentFeed.ts +++ b/Common/Models/DatabaseModels/IncidentFeed.ts @@ -497,8 +497,6 @@ export default class IncidentFeed extends BaseModel { }) public userId?: ObjectID = undefined; - - @ColumnAccessControl({ create: [ Permission.ProjectOwner, @@ -525,6 +523,4 @@ export default class IncidentFeed extends BaseModel { unique: false, }) public postedAt?: Date = undefined; - - } diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1736856662868-MigrationName.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1736856662868-MigrationName.ts index c29fb192f4..9bd46f9aca 100644 --- a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1736856662868-MigrationName.ts +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1736856662868-MigrationName.ts @@ -1,18 +1,27 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class MigrationName1736856662868 implements MigrationInterface { - public name = 'MigrationName1736856662868' + public name = "MigrationName1736856662868"; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "IncidentFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`); - await queryRunner.query(`ALTER TABLE "AlertFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`); - await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceFeed" DROP COLUMN "postedAt"`); - await queryRunner.query(`ALTER TABLE "AlertFeed" DROP COLUMN "postedAt"`); - await queryRunner.query(`ALTER TABLE "IncidentFeed" DROP COLUMN "postedAt"`); - } + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "IncidentFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`, + ); + await queryRunner.query( + `ALTER TABLE "AlertFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`, + ); + await queryRunner.query( + `ALTER TABLE "ScheduledMaintenanceFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`, + ); + } + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "ScheduledMaintenanceFeed" DROP COLUMN "postedAt"`, + ); + await queryRunner.query(`ALTER TABLE "AlertFeed" DROP COLUMN "postedAt"`); + await queryRunner.query( + `ALTER TABLE "IncidentFeed" DROP COLUMN "postedAt"`, + ); + } } diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts index 73d6f69784..b37e1a87aa 100644 --- a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts @@ -193,5 +193,5 @@ export default [ MigrationName1736787495707, MigrationName1736787985322, MigrationName1736788706141, - MigrationName1736856662868 + MigrationName1736856662868, ]; diff --git a/Common/Server/Services/AlertFeedService.ts b/Common/Server/Services/AlertFeedService.ts index 096232d79d..a19d935a07 100644 --- a/Common/Server/Services/AlertFeedService.ts +++ b/Common/Server/Services/AlertFeedService.ts @@ -61,10 +61,9 @@ export class Service extends DatabaseService { alertFeed.alertFeedEventType = data.alertFeedEventType; alertFeed.projectId = data.projectId; - if(!data.postedAt){ + if (!data.postedAt) { alertFeed.postedAt = OneUptimeDate.getCurrentDate(); - } - + } if (data.moreInformationInMarkdown) { alertFeed.moreInformationInMarkdown = data.moreInformationInMarkdown; diff --git a/Common/Server/Services/IncidentFeedService.ts b/Common/Server/Services/IncidentFeedService.ts index 2381adbbcf..ab5a70f815 100644 --- a/Common/Server/Services/IncidentFeedService.ts +++ b/Common/Server/Services/IncidentFeedService.ts @@ -56,7 +56,7 @@ export class Service extends DatabaseService { incidentFeed.incidentFeedEventType = data.incidentFeedEventType; incidentFeed.projectId = data.projectId; - if(!data.postedAt){ + if (!data.postedAt) { incidentFeed.postedAt = OneUptimeDate.getCurrentDate(); } diff --git a/Common/Server/Services/IncidentInternalNoteService.ts b/Common/Server/Services/IncidentInternalNoteService.ts index 9d1c1393ee..0f9f5dd76c 100644 --- a/Common/Server/Services/IncidentInternalNoteService.ts +++ b/Common/Server/Services/IncidentInternalNoteService.ts @@ -17,7 +17,6 @@ export class Service extends DatabaseService { ): Promise { const userId: ObjectID | null | undefined = createdItem.createdByUserId || createdItem.createdByUser?.id; - await IncidentFeedService.createIncidentFeed({ incidentId: createdItem.incidentId!, diff --git a/Common/Server/Services/IncidentOwnerTeamService.ts b/Common/Server/Services/IncidentOwnerTeamService.ts index ff41e331e0..6dc0ae6a94 100644 --- a/Common/Server/Services/IncidentOwnerTeamService.ts +++ b/Common/Server/Services/IncidentOwnerTeamService.ts @@ -14,57 +14,57 @@ export class Service extends DatabaseService { super(Model); } - - protected override async onBeforeDelete(deleteBy: DeleteBy): Promise> { + protected override async onBeforeDelete( + deleteBy: DeleteBy, + ): Promise> { const itemsToDelete: Model[] = await this.findBy({ query: deleteBy.query, limit: deleteBy.limit, skip: deleteBy.skip, props: { - isRoot: true + isRoot: true, }, select: { incidentId: true, projectId: true, teamId: true, - } - }) + }, + }); return { carryForward: { - itemsToDelete: itemsToDelete + itemsToDelete: itemsToDelete, }, - deleteBy: deleteBy - } + deleteBy: deleteBy, + }; } - protected override async onDeleteSuccess(onDelete: OnDelete, _itemIdsBeforeDelete: Array): Promise> { - - const deleteByUserId: ObjectID | undefined = onDelete.deleteBy.deletedByUser?.id || onDelete.deleteBy.props.userId; + protected override async onDeleteSuccess( + onDelete: OnDelete, + _itemIdsBeforeDelete: Array, + ): Promise> { + const deleteByUserId: ObjectID | undefined = + onDelete.deleteBy.deletedByUser?.id || onDelete.deleteBy.props.userId; const itemsToDelete: Model[] = onDelete.carryForward.itemsToDelete; for (const item of itemsToDelete) { - const incidentId: ObjectID | undefined = item.incidentId; const projectId: ObjectID | undefined = item.projectId; const teamId: ObjectID | undefined = item.teamId; - if (incidentId && teamId && projectId) { - const team: Team | null = await TeamService.findOneById({ id: teamId, select: { - name: true + name: true, }, props: { - isRoot: true - } - }) + isRoot: true, + }, + }); if (team && team.name) { - await IncidentFeedService.createIncidentFeed({ incidentId: incidentId, projectId: projectId, @@ -78,36 +78,33 @@ export class Service extends DatabaseService { } return onDelete; - } - public override async onCreateSuccess(onCreate: OnCreate, createdItem: Model): Promise { - // add incident feed. + public override async onCreateSuccess( + onCreate: OnCreate, + createdItem: Model, + ): Promise { + // add incident feed. const incidentId: ObjectID | undefined = createdItem.incidentId; const projectId: ObjectID | undefined = createdItem.projectId; const teamId: ObjectID | undefined = createdItem.teamId; - const createdByUserId: ObjectID | undefined = createdItem.createdByUserId || onCreate.createBy.props.userId; - + const createdByUserId: ObjectID | undefined = + createdItem.createdByUserId || onCreate.createBy.props.userId; if (incidentId && teamId && projectId) { - - const team: Team | null = await TeamService.findOneById({ id: teamId, select: { - name: true + name: true, }, props: { - isRoot: true - } - }) + isRoot: true, + }, + }); if (team && team.name) { - - await IncidentFeedService.createIncidentFeed({ - incidentId: incidentId, projectId: projectId, incidentFeedEventType: IncidentFeedEventType.OwnerTeamAdded, @@ -115,13 +112,10 @@ export class Service extends DatabaseService { feedInfoInMarkdown: `**Team ${team.name}** was added to the incident as the owner.`, userId: createdByUserId || undefined, }); - } - } return createdItem; - } } diff --git a/Common/Server/Services/IncidentOwnerUserService.ts b/Common/Server/Services/IncidentOwnerUserService.ts index 8f28ee8354..c6cce9de5f 100644 --- a/Common/Server/Services/IncidentOwnerUserService.ts +++ b/Common/Server/Services/IncidentOwnerUserService.ts @@ -14,57 +14,58 @@ export class Service extends DatabaseService { super(Model); } - protected override async onBeforeDelete(deleteBy: DeleteBy): Promise> { + protected override async onBeforeDelete( + deleteBy: DeleteBy, + ): Promise> { const itemsToDelete: Model[] = await this.findBy({ query: deleteBy.query, limit: deleteBy.limit, skip: deleteBy.skip, props: { - isRoot: true + isRoot: true, }, select: { incidentId: true, projectId: true, userId: true, - } - }) + }, + }); return { carryForward: { - itemsToDelete: itemsToDelete + itemsToDelete: itemsToDelete, }, - deleteBy: deleteBy - } + deleteBy: deleteBy, + }; } - protected override async onDeleteSuccess(onDelete: OnDelete, _itemIdsBeforeDelete: Array): Promise> { - - const deleteByUserId: ObjectID | undefined = onDelete.deleteBy.deletedByUser?.id || onDelete.deleteBy.props.userId; + protected override async onDeleteSuccess( + onDelete: OnDelete, + _itemIdsBeforeDelete: Array, + ): Promise> { + const deleteByUserId: ObjectID | undefined = + onDelete.deleteBy.deletedByUser?.id || onDelete.deleteBy.props.userId; const itemsToDelete: Model[] = onDelete.carryForward.itemsToDelete; for (const item of itemsToDelete) { - const incidentId: ObjectID | undefined = item.incidentId; const projectId: ObjectID | undefined = item.projectId; const userId: ObjectID | undefined = item.userId; - if (incidentId && userId && projectId) { - const user: User | null = await UserService.findOneById({ id: userId, select: { name: true, - email: true + email: true, }, props: { - isRoot: true - } - }) + isRoot: true, + }, + }); if (user && user.name) { - await IncidentFeedService.createIncidentFeed({ incidentId: incidentId, projectId: projectId, @@ -78,35 +79,33 @@ export class Service extends DatabaseService { } return onDelete; - } - - public override async onCreateSuccess(onCreate: OnCreate, createdItem: Model): Promise { - // add incident feed. + public override async onCreateSuccess( + onCreate: OnCreate, + createdItem: Model, + ): Promise { + // add incident feed. const incidentId: ObjectID | undefined = createdItem.incidentId; const projectId: ObjectID | undefined = createdItem.projectId; const userId: ObjectID | undefined = createdItem.userId; - const createdByUserId: ObjectID | undefined = createdItem.createdByUserId || onCreate.createBy.props.userId; - + const createdByUserId: ObjectID | undefined = + createdItem.createdByUserId || onCreate.createBy.props.userId; if (incidentId && userId && projectId) { - - const user: User | null = await UserService.findOneById({ id: userId, select: { name: true, - email: true + email: true, }, props: { - isRoot: true - } - }) + isRoot: true, + }, + }); if (user && user.name) { - await IncidentFeedService.createIncidentFeed({ incidentId: incidentId, projectId: projectId, @@ -115,13 +114,10 @@ export class Service extends DatabaseService { feedInfoInMarkdown: `**${user.name.toString()}** (${user.email?.toString()}) was added to the incident as the owner.`, userId: createdByUserId || undefined, }); - } - } return createdItem; - } } diff --git a/Common/Server/Services/IncidentService.ts b/Common/Server/Services/IncidentService.ts index 40f299e9bd..94a40e6680 100644 --- a/Common/Server/Services/IncidentService.ts +++ b/Common/Server/Services/IncidentService.ts @@ -227,16 +227,16 @@ export class Service extends DatabaseService { logger.debug( "Mutex acquired - IncidentService.incident-create " + - projectId.toString() + - " at " + - OneUptimeDate.getCurrentDateAsFormattedString(), + projectId.toString() + + " at " + + OneUptimeDate.getCurrentDateAsFormattedString(), ); } catch (err) { logger.debug( "Mutex acquire failed - IncidentService.incident-create " + - projectId.toString() + - " at " + - OneUptimeDate.getCurrentDateAsFormattedString(), + projectId.toString() + + " at " + + OneUptimeDate.getCurrentDateAsFormattedString(), ); logger.error(err); } @@ -314,24 +314,23 @@ export class Service extends DatabaseService { await Semaphore.release(mutex); logger.debug( "Mutex released - IncidentService.incident-create " + - projectId.toString() + - " at " + - OneUptimeDate.getCurrentDateAsFormattedString(), + projectId.toString() + + " at " + + OneUptimeDate.getCurrentDateAsFormattedString(), ); } catch (err) { logger.debug( "Mutex release failed - IncidentService.incident-create " + - projectId.toString() + - " at " + - OneUptimeDate.getCurrentDateAsFormattedString(), + projectId.toString() + + " at " + + OneUptimeDate.getCurrentDateAsFormattedString(), ); logger.error(err); } } - - const createdByUserId: ObjectID | undefined | null = createdItem.createdByUserId || createdItem.createdByUser?.id; - + const createdByUserId: ObjectID | undefined | null = + createdItem.createdByUserId || createdItem.createdByUser?.id; await IncidentFeedService.createIncidentFeed({ incidentId: createdItem.id!, @@ -366,9 +365,9 @@ ${createdItem.description || "No description provided."} createdItem.changeMonitorStatusToId, true, // notifyMonitorOwners createdItem.rootCause || - "Status was changed because incident " + - createdItem.id.toString() + - " was created.", + "Status was changed because incident " + + createdItem.id.toString() + + " was created.", createdItem.createdStateLog, onCreate.createBy.props, ); @@ -392,7 +391,6 @@ ${createdItem.description || "No description provided."} }, }); - await IncidentFeedService.createIncidentFeed({ incidentId: createdItem.id!, projectId: createdItem.projectId!, @@ -413,7 +411,6 @@ ${createdItem.rootCause || "No root cause provided."}`, ${createdItem.remediationNotes || "No remediation notes provided."}`, }); - // add owners. if ( @@ -425,9 +422,9 @@ ${createdItem.remediationNotes || "No remediation notes provided."}`, createdItem.projectId, createdItem.id, (onCreate.createBy.miscDataProps["ownerUsers"] as Array) || - [], + [], (onCreate.createBy.miscDataProps["ownerTeams"] as Array) || - [], + [], false, onCreate.createBy.props, ); @@ -646,16 +643,13 @@ ${createdItem.remediationNotes || "No remediation notes provided."}`, } if (updatedItemIds.length > 0) { - for (const incidentId of updatedItemIds) { - if (onUpdate.updateBy.data.title) { - - // add incident feed. - const createdByUserId: ObjectID | undefined | null = onUpdate.updateBy.props.userId; + // add incident feed. + const createdByUserId: ObjectID | undefined | null = + onUpdate.updateBy.props.userId; await IncidentFeedService.createIncidentFeed({ - incidentId: incidentId, projectId: onUpdate.updateBy.props.tenantId as ObjectID, incidentFeedEventType: IncidentFeedEventType.IncidentUpdated, @@ -665,17 +659,15 @@ ${createdItem.remediationNotes || "No remediation notes provided."}`, ${onUpdate.updateBy.data.title || "No title provided."} `, userId: createdByUserId || undefined, - }) + }); } - if (onUpdate.updateBy.data.description) { - - // add incident feed. - const createdByUserId: ObjectID | undefined | null = onUpdate.updateBy.props.userId; + // add incident feed. + const createdByUserId: ObjectID | undefined | null = + onUpdate.updateBy.props.userId; await IncidentFeedService.createIncidentFeed({ - incidentId: incidentId, projectId: onUpdate.updateBy.props.tenantId as ObjectID, incidentFeedEventType: IncidentFeedEventType.IncidentUpdated, @@ -686,16 +678,14 @@ ${onUpdate.updateBy.data.description || "No description provided."} `, userId: createdByUserId || undefined, }); - } if (onUpdate.updateBy.data.remediationNotes) { - - // add incident feed. - const createdByUserId: ObjectID | undefined | null = onUpdate.updateBy.props.userId; + // add incident feed. + const createdByUserId: ObjectID | undefined | null = + onUpdate.updateBy.props.userId; await IncidentFeedService.createIncidentFeed({ - incidentId: incidentId, projectId: onUpdate.updateBy.props.tenantId as ObjectID, incidentFeedEventType: IncidentFeedEventType.IncidentUpdated, @@ -708,11 +698,9 @@ ${onUpdate.updateBy.data.remediationNotes || "No remediation notes provided."} }); } } - } return onUpdate; - } public async doesMonitorHasMoreActiveManualIncidents( @@ -817,7 +805,7 @@ ${onUpdate.updateBy.data.remediationNotes || "No remediation notes provided."} if ( latestState && latestState.monitorStatusId?.toString() === - resolvedMonitorState.id!.toString() + resolvedMonitorState.id!.toString() ) { // already on this state. Skip. continue; @@ -930,7 +918,7 @@ ${onUpdate.updateBy.data.remediationNotes || "No remediation notes provided."} lastIncidentStatusTimeline && lastIncidentStatusTimeline.incidentStateId && lastIncidentStatusTimeline.incidentStateId.toString() === - incidentStateId.toString() + incidentStateId.toString() ) { return; } @@ -1148,7 +1136,7 @@ ${onUpdate.updateBy.data.remediationNotes || "No remediation notes provided."} timeToResolveMetric.description = "Time taken to resolve the incident"; timeToResolveMetric.value = OneUptimeDate.getDifferenceInSeconds( resolvedIncidentStateTimeline?.startsAt || - OneUptimeDate.getCurrentDate(), + OneUptimeDate.getCurrentDate(), incidentStartsAt, ); timeToResolveMetric.unit = "seconds"; diff --git a/Common/Server/Services/IncidentStateTimelineService.ts b/Common/Server/Services/IncidentStateTimelineService.ts index 47ab99d204..29f2d7f5d5 100644 --- a/Common/Server/Services/IncidentStateTimelineService.ts +++ b/Common/Server/Services/IncidentStateTimelineService.ts @@ -122,11 +122,8 @@ export class Service extends DatabaseService { )?.["publicNote"] as string | undefined; if (publicNote) { - // mark status page subscribers as notified for this state change because we dont want to send duplicate (two) emails one for public note and one for state change. - if ( - createBy.data.shouldStatusPageSubscribersBeNotified - ) { + if (createBy.data.shouldStatusPageSubscribersBeNotified) { createBy.data.isStatusPageSubscribersNotified = true; } } @@ -237,12 +234,9 @@ ${createdItem.rootCause}`, } } - if (onCreate.carryForward.publicNote) { - const publicNote: string = onCreate.carryForward.publicNote; - const incidentPublicNote: IncidentPublicNote = new IncidentPublicNote(); incidentPublicNote.incidentId = createdItem.incidentId; incidentPublicNote.note = publicNote; @@ -252,12 +246,10 @@ ${createdItem.rootCause}`, incidentPublicNote.shouldStatusPageSubscribersBeNotifiedOnNoteCreated = Boolean(createdItem.shouldStatusPageSubscribersBeNotified); - await IncidentPublicNoteService.create({ data: incidentPublicNote, props: onCreate.createBy.props, }); - } IncidentService.refreshIncidentMetrics({ diff --git a/Common/Server/Services/OnCallDutyPolicyExecutionLogService.ts b/Common/Server/Services/OnCallDutyPolicyExecutionLogService.ts index a834821c6c..fef643b8eb 100644 --- a/Common/Server/Services/OnCallDutyPolicyExecutionLogService.ts +++ b/Common/Server/Services/OnCallDutyPolicyExecutionLogService.ts @@ -38,20 +38,19 @@ export class Service extends DatabaseService { _onCreate: OnCreate, createdItem: Model, ): Promise { - if (createdItem.triggeredByIncidentId) { - - const onCallPolicy: OnCallDutyPolicy | null = await OnCallDutyPolicyService.findOneById({ - id: createdItem.onCallDutyPolicyId!, - select: { - _id: true, - projectId: true, - name: true, - }, - props: { - isRoot: true, - }, - }); + const onCallPolicy: OnCallDutyPolicy | null = + await OnCallDutyPolicyService.findOneById({ + id: createdItem.onCallDutyPolicyId!, + select: { + _id: true, + projectId: true, + name: true, + }, + props: { + isRoot: true, + }, + }); if (onCallPolicy && onCallPolicy.id) { await IncidentFeedService.createIncidentFeed({ @@ -130,40 +129,47 @@ export class Service extends DatabaseService { return createdItem; } - - protected override async onUpdateSuccess(onUpdate: OnUpdate, _updatedItemIds: Array): Promise> { - // if status is updtaed then check if this on-call is related to the incident, if yes, then add to incident feed. - if(onUpdate.updateBy.data.status && onUpdate.updateBy.query.id) { - + protected override async onUpdateSuccess( + onUpdate: OnUpdate, + _updatedItemIds: Array, + ): Promise> { + // if status is updtaed then check if this on-call is related to the incident, if yes, then add to incident feed. + if (onUpdate.updateBy.data.status && onUpdate.updateBy.query.id) { const id: ObjectID = onUpdate.updateBy.query.id! as ObjectID; - const onCalldutyPolicyExecutionLog: Model | null = await this.findOneById({ - id: id, - select: { - _id: true, - projectId: true, - onCallDutyPolicyId: true, - status: true, - statusMessage: true, - triggeredByIncidentId: true, - }, - props: { - isRoot: true, - }, - }); - - if(onCalldutyPolicyExecutionLog && onCalldutyPolicyExecutionLog.triggeredByIncidentId) { - const onCallPolicy: OnCallDutyPolicy | null = await OnCallDutyPolicyService.findOneById({ - id: onCalldutyPolicyExecutionLog.onCallDutyPolicyId!, + const onCalldutyPolicyExecutionLog: Model | null = await this.findOneById( + { + id: id, select: { _id: true, projectId: true, - name: true, + onCallDutyPolicyId: true, + status: true, + statusMessage: true, + triggeredByIncidentId: true, }, props: { isRoot: true, }, - }); + }, + ); + + if ( + onCalldutyPolicyExecutionLog && + onCalldutyPolicyExecutionLog.triggeredByIncidentId + ) { + const onCallPolicy: OnCallDutyPolicy | null = + await OnCallDutyPolicyService.findOneById({ + id: onCalldutyPolicyExecutionLog.onCallDutyPolicyId!, + select: { + _id: true, + projectId: true, + name: true, + }, + props: { + isRoot: true, + }, + }); if (onCallPolicy && onCallPolicy.id) { await IncidentFeedService.createIncidentFeed({ @@ -174,7 +180,6 @@ export class Service extends DatabaseService { feedInfoInMarkdown: `**On Call Policy Status Updated: ** On Call Policy **${onCallPolicy.name}** status updated to **${onCalldutyPolicyExecutionLog.status}**. ${onCalldutyPolicyExecutionLog.statusMessage}`, }); } - } } diff --git a/Common/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.ts b/Common/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.ts index a109efe76d..8a4c575a2b 100644 --- a/Common/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.ts +++ b/Common/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.ts @@ -15,9 +15,9 @@ export class Service extends DatabaseService { super(Model); } - - public getColorBasedOnStatus(status: OnCallDutyExecutionLogTimelineStatus): Color { - + public getColorBasedOnStatus( + status: OnCallDutyExecutionLogTimelineStatus, + ): Color { switch (status) { case OnCallDutyExecutionLogTimelineStatus.Started: return Blue500; @@ -34,52 +34,48 @@ export class Service extends DatabaseService { default: return Blue500; } - } - public async addToIncidentFeed( - data: { - onCallDutyPolicyExecutionLogTimelineId: ObjectID; - } - ): Promise { - - const onCallDutyPolicyExecutionLogTimeline: Model | null = await this.findOneById({ - id: data.onCallDutyPolicyExecutionLogTimelineId, - select: { - _id: true, - onCallDutyPolicyId: true, - triggeredByIncidentId: true, - status: true, - statusMessage: true, - alertSentToUserId: true, - onCallDutyPolicy: { - name: true, - _id: true, - }, - alertSentToUser: { - name: true, - email: true, - }, - onCallDutyPolicyEscalationRule: { - name: true, + public async addToIncidentFeed(data: { + onCallDutyPolicyExecutionLogTimelineId: ObjectID; + }): Promise { + const onCallDutyPolicyExecutionLogTimeline: Model | null = + await this.findOneById({ + id: data.onCallDutyPolicyExecutionLogTimelineId, + select: { _id: true, + onCallDutyPolicyId: true, + triggeredByIncidentId: true, + status: true, + statusMessage: true, + alertSentToUserId: true, + onCallDutyPolicy: { + name: true, + _id: true, + }, + alertSentToUser: { + name: true, + email: true, + }, + onCallDutyPolicyEscalationRule: { + name: true, + _id: true, + }, + onCallDutySchedule: { + name: true, + _id: true, + }, + isAcknowledged: true, + acknowledgedAt: true, + userBelongsToTeam: { + name: true, + _id: true, + }, }, - onCallDutySchedule: { - name: true, - _id: true, + props: { + isRoot: true, }, - isAcknowledged: true, - acknowledgedAt: true, - userBelongsToTeam: { - name: true, - _id: true - } - }, - props: { - isRoot: true, - } - }); - + }); if (!onCallDutyPolicyExecutionLogTimeline) { return; @@ -89,46 +85,55 @@ export class Service extends DatabaseService { return; } - const onCallPolicy: OnCallDutyPolicy | null = await OnCallDutyPolicyService.findOneById({ - id: onCallDutyPolicyExecutionLogTimeline.onCallDutyPolicyId!, - select: { - _id: true, - projectId: true, - name: true, - }, - props: { - isRoot: true, - }, - }); + const onCallPolicy: OnCallDutyPolicy | null = + await OnCallDutyPolicyService.findOneById({ + id: onCallDutyPolicyExecutionLogTimeline.onCallDutyPolicyId!, + select: { + _id: true, + projectId: true, + name: true, + }, + props: { + isRoot: true, + }, + }); if (onCallPolicy && onCallPolicy.id) { - const status: OnCallDutyExecutionLogTimelineStatus = onCallDutyPolicyExecutionLogTimeline.status!; - - - if (status && (status === OnCallDutyExecutionLogTimelineStatus.Skipped || status === OnCallDutyExecutionLogTimelineStatus.Error || status === OnCallDutyExecutionLogTimelineStatus.SuccessfullyAcknowledged || status === OnCallDutyExecutionLogTimelineStatus.NotificationSent)) { - - const displayColor: Color = status ? this.getColorBasedOnStatus(status) : Blue500; - - - let feedInfoInMarkdown: string = ` - The On Call Policy "${onCallPolicy.name}" has been triggered. The escalation rule "${onCallDutyPolicyExecutionLogTimeline.onCallDutyPolicyEscalationRule?.name}" ${onCallDutyPolicyExecutionLogTimeline.onCallDutySchedule?.name ? " and schedule " + onCallDutyPolicyExecutionLogTimeline.onCallDutySchedule?.name + "" : ""} were applied. The user "${onCallDutyPolicyExecutionLogTimeline.alertSentToUser?.name}" (${onCallDutyPolicyExecutionLogTimeline.alertSentToUser?.email}) was alerted. The current status is "${status}" with the message: "${onCallDutyPolicyExecutionLogTimeline.statusMessage}". ${onCallDutyPolicyExecutionLogTimeline.userBelongsToTeam?.name ? "The user belongs to the team " + onCallDutyPolicyExecutionLogTimeline.userBelongsToTeam?.name : ""} ${onCallDutyPolicyExecutionLogTimeline.isAcknowledged ? "The alert was acknowledged at " + onCallDutyPolicyExecutionLogTimeline.acknowledgedAt : ""} + const status: OnCallDutyExecutionLogTimelineStatus = + onCallDutyPolicyExecutionLogTimeline.status!; + + if ( + status && + (status === OnCallDutyExecutionLogTimelineStatus.Skipped || + status === OnCallDutyExecutionLogTimelineStatus.Error || + status === + OnCallDutyExecutionLogTimelineStatus.SuccessfullyAcknowledged || + status === OnCallDutyExecutionLogTimelineStatus.NotificationSent) + ) { + const displayColor: Color = status + ? this.getColorBasedOnStatus(status) + : Blue500; + + const feedInfoInMarkdown: string = ` + The On Call Policy "${onCallPolicy.name}" has been triggered. The escalation rule "${onCallDutyPolicyExecutionLogTimeline.onCallDutyPolicyEscalationRule?.name}" ${onCallDutyPolicyExecutionLogTimeline.onCallDutySchedule?.name ? String(" and schedule " + onCallDutyPolicyExecutionLogTimeline.onCallDutySchedule?.name) : ""} were applied. The user "${onCallDutyPolicyExecutionLogTimeline.alertSentToUser?.name}" (${onCallDutyPolicyExecutionLogTimeline.alertSentToUser?.email}) was alerted. The current status is "${status}" with the message: "${onCallDutyPolicyExecutionLogTimeline.statusMessage}". ${onCallDutyPolicyExecutionLogTimeline.userBelongsToTeam?.name ? "The user belongs to the team " + onCallDutyPolicyExecutionLogTimeline.userBelongsToTeam?.name : ""} ${onCallDutyPolicyExecutionLogTimeline.isAcknowledged ? "The alert was acknowledged at " + onCallDutyPolicyExecutionLogTimeline.acknowledgedAt : ""} `; - await IncidentFeedService.createIncidentFeed({ - incidentId: onCallDutyPolicyExecutionLogTimeline.triggeredByIncidentId, + incidentId: + onCallDutyPolicyExecutionLogTimeline.triggeredByIncidentId, projectId: onCallPolicy.projectId!, incidentFeedEventType: IncidentFeedEventType.OnCallPolicy, displayColor: displayColor, feedInfoInMarkdown: feedInfoInMarkdown, }); - } - } } - protected override async onCreateSuccess(_onCreate: OnCreate, createdItem: Model): Promise { + protected override async onCreateSuccess( + _onCreate: OnCreate, + createdItem: Model, + ): Promise { if (createdItem.triggeredByIncidentId) { await this.addToIncidentFeed({ onCallDutyPolicyExecutionLogTimelineId: createdItem.id!, @@ -137,6 +142,5 @@ export class Service extends DatabaseService { return createdItem; } - } export default new Service(); diff --git a/Common/Server/Services/ScheduledMaintenanceFeedService.ts b/Common/Server/Services/ScheduledMaintenanceFeedService.ts index 9f05f81fb8..bb439a96a9 100644 --- a/Common/Server/Services/ScheduledMaintenanceFeedService.ts +++ b/Common/Server/Services/ScheduledMaintenanceFeedService.ts @@ -26,7 +26,7 @@ export class Service extends DatabaseService { moreInformationInMarkdown?: string | undefined; displayColor?: Color | undefined; userId?: ObjectID | undefined; - postedAt?: Date | undefined; + postedAt?: Date | undefined; }): Promise { if (!data.scheduledMaintenanceId) { throw new BadDataException("Scheduled Maintenance ID is required"); @@ -67,8 +67,7 @@ export class Service extends DatabaseService { data.moreInformationInMarkdown; } - - if(!data.postedAt){ + if (!data.postedAt) { scheduledMaintenanceFeed.postedAt = OneUptimeDate.getCurrentDate(); } diff --git a/Common/UI/Components/Feed/Feed.tsx b/Common/UI/Components/Feed/Feed.tsx index 0e72bfbba3..edfbd8b249 100644 --- a/Common/UI/Components/Feed/Feed.tsx +++ b/Common/UI/Components/Feed/Feed.tsx @@ -15,13 +15,11 @@ const Feed: FunctionComponent = (
    {props.items.length === 0 && (
    -
    )} + + + )} {props.items.map((item: FeedItemProps) => { - return ( - - ); + return ; })}
diff --git a/Common/UI/Components/Feed/FeedItem.tsx b/Common/UI/Components/Feed/FeedItem.tsx index 6d84987a28..99ec7e1543 100644 --- a/Common/UI/Components/Feed/FeedItem.tsx +++ b/Common/UI/Components/Feed/FeedItem.tsx @@ -29,112 +29,142 @@ export interface ComponentProps { const FeedItem: FunctionComponent = ( props: ComponentProps, ): ReactElement => { - - - const [showMoreInformationModal, setShowMoreInformationModal] = useState(false); - + const [showMoreInformationModal, setShowMoreInformationModal] = + useState(false); const getMoreInformationModal: GetReactElementFunction = (): ReactElement => { if (showMoreInformationModal) { - return ( - - - } - isLoading={false} - submitButtonText={"Close"} - onSubmit={() => { - return setShowMoreInformationModal(false); - }} - submitButtonType={ButtonStyleType.NORMAL} - />) + return ( + + + + } + isLoading={false} + submitButtonText={"Close"} + onSubmit={() => { + return setShowMoreInformationModal(false); + }} + submitButtonType={ButtonStyleType.NORMAL} + /> + ); } return <>; - } - + }; const getUserIcon: GetReactElementFunction = (): ReactElement => { - return
- {!props.user?.profilePictureId && } - - {props.user?.profilePictureId && } - - {props.icon && - - } -
- } - + return ( +
+ {!props.user?.profilePictureId && ( + + )} + + {props.user?.profilePictureId && ( + + )} + + {props.icon && ( + + + + )} +
+ ); + }; const getItem: GetReactElementFunction = (): ReactElement => { - return
  • -
    - -
    -
    - {props.user && getUserIcon()} - {!props.user && props.icon && getIconItem()} -
    -
    -
    - {props.user?.name &&
    -
    - {props.user?.name?.toString() || "Unknown User"} + return ( +
  • +
    + +
    +
    + {props.user && getUserIcon()} + {!props.user && props.icon && getIconItem()} +
    +
    +
    + {props.user?.name && ( +
    +
    + {props.user?.name?.toString() || "Unknown User"} +
    +
    + )} +
    + +
    + {OneUptimeDate.fromNow(props.itemDateTime)} +
    +
    -
    } -
    - -
    {OneUptimeDate.fromNow(props.itemDateTime)}
    -
    -
    -
    - {props.textInMarkdown &&
    - -
    } - {props.element &&
    {props.element}
    } - {props.moreTextInMarkdown &&
    } +
    + {props.textInMarkdown && ( +
    + +
    + )} + {props.element &&
    {props.element}
    } + {props.moreTextInMarkdown && ( +
    +
    + )} +
    - - {getMoreInformationModal()} -
  • ; - } + {getMoreInformationModal()} + + ); + }; const getIconItem: GetReactElementFunction = (): ReactElement => { - if (!props.icon) { return <>; } return (
    - +
    - ) - } + ); + }; return getItem(); - - }; export default FeedItem; diff --git a/Common/UI/Components/Icon/Icon.tsx b/Common/UI/Components/Icon/Icon.tsx index 26c98892d7..4d62e14fc8 100644 --- a/Common/UI/Components/Icon/Icon.tsx +++ b/Common/UI/Components/Icon/Icon.tsx @@ -1075,9 +1075,13 @@ const Icon: FunctionComponent = ({ d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />, ); - }else if (icon === IconProp.Text) { + } else if (icon === IconProp.Text) { return getSvgWrapper( - + , ); } else if (icon === IconProp.SendMessage) { return getSvgWrapper( diff --git a/Common/UI/Components/ProgressButtons/ProgressButtonItem.tsx b/Common/UI/Components/ProgressButtons/ProgressButtonItem.tsx index e96377664b..4f47b31e5f 100644 --- a/Common/UI/Components/ProgressButtons/ProgressButtonItem.tsx +++ b/Common/UI/Components/ProgressButtons/ProgressButtonItem.tsx @@ -3,49 +3,79 @@ import Color from "../../../Types/Color"; import Icon from "../Icon/Icon"; import IconProp from "../../../Types/Icon/IconProp"; - export interface ProgressItemProps { - id: string; - title: string; - color: Color; + id: string; + title: string; + color: Color; } export interface ComponentProps extends ProgressItemProps { - isCompletedStep?: boolean; - stepCount: number; - isCurrentStep: boolean; - isLastStep: boolean; - onClick: () => void; + isCompletedStep?: boolean; + stepCount: number; + isCurrentStep: boolean; + isLastStep: boolean; + onClick: () => void; } const ProgressButtonItem: FunctionComponent = ( - props: ComponentProps, + props: ComponentProps, ): ReactElement => { - return ( -
  • props.onClick()}> - - - - {props.isCompletedStep && - - } - {props.isCurrentStep && - {props.stepCount} - } - {!props.isCompletedStep && !props.isCompletedStep && - {props.stepCount} - } - {props.title} - - + return ( +
  • { + return props.onClick(); + }} + > + + + {props.isCompletedStep && ( + + + + )} + {props.isCurrentStep && ( + + {props.stepCount} + + )} + {!props.isCompletedStep && !props.isCompletedStep && ( + + + {props.stepCount} + + + )} + + {props.title} + + + - {!props.isLastStep && } -
  • - ); + {!props.isLastStep && ( + + )} + + ); }; export default ProgressButtonItem; diff --git a/Common/UI/Components/ProgressButtons/ProgressButtons.tsx b/Common/UI/Components/ProgressButtons/ProgressButtons.tsx index feabc81809..59f2255f8c 100644 --- a/Common/UI/Components/ProgressButtons/ProgressButtons.tsx +++ b/Common/UI/Components/ProgressButtons/ProgressButtons.tsx @@ -2,37 +2,66 @@ import React, { FunctionComponent, ReactElement } from "react"; import ProgressButtonItem, { ProgressItemProps } from "./ProgressButtonItem"; export interface ComponentProps { - id: string; - progressButtonItems: Array; - currentStepId: string; - onStepClick?: (stepId: string) => void; + id: string; + progressButtonItems: Array; + currentStepId: string; + onStepClick?: (stepId: string) => void; } const ProgressButtons: FunctionComponent = ( - props: ComponentProps, + props: ComponentProps, ): ReactElement => { - const isStepCompleted = (stepId: string): boolean => { - return props.progressButtonItems.findIndex((progressButtonItem: ProgressItemProps) => progressButtonItem.id === stepId) < props.progressButtonItems.findIndex((progressButtonItem: ProgressItemProps) => progressButtonItem.id === props.currentStepId); - } + type IsStepCompletedFunction = (stepId: string) => boolean; + const isStepCompleted: IsStepCompletedFunction = (stepId: string): boolean => { return ( - + ); }; export default ProgressButtons; diff --git a/Common/UI/Utils/User.ts b/Common/UI/Utils/User.ts index 838eb1b3af..260a8bb2c4 100644 --- a/Common/UI/Utils/User.ts +++ b/Common/UI/Utils/User.ts @@ -13,7 +13,6 @@ import Cookie from "./Cookie"; import CookieName from "Common/Types/CookieName"; export default class UserUtil { - public static setProfilePicId(id: ObjectID | null): void { if (!id) { LocalStorage.removeItem("profile_pic_id"); diff --git a/Dashboard/src/Components/Incident/IncidentFeed.tsx b/Dashboard/src/Components/Incident/IncidentFeed.tsx index 02ddc1ea85..7897a5afd7 100644 --- a/Dashboard/src/Components/Incident/IncidentFeed.tsx +++ b/Dashboard/src/Components/Incident/IncidentFeed.tsx @@ -5,7 +5,9 @@ import Feed from "Common/UI/Components/Feed/Feed"; import API from "Common/UI/Utils/API/API"; import ComponentLoader from "Common/UI/Components/ComponentLoader/ComponentLoader"; import ErrorMessage from "Common/UI/Components/ErrorMessage/ErrorMessage"; -import IncidentFeed, { IncidentFeedEventType } from "Common/Models/DatabaseModels/IncidentFeed"; +import IncidentFeed, { + IncidentFeedEventType, +} from "Common/Models/DatabaseModels/IncidentFeed"; import ListResult from "Common/UI/Utils/BaseDatabase/ListResult"; import ModelAPI from "Common/UI/Utils/ModelAPI/ModelAPI"; import SortOrder from "Common/Types/BaseDatabase/SortOrder"; @@ -16,179 +18,217 @@ import IconProp from "Common/Types/Icon/IconProp"; import { ButtonStyleType } from "Common/UI/Components/Button/Button"; export interface ComponentProps { - incidentId?: ObjectID; + incidentId?: ObjectID; } const IncidentFeedElement: FunctionComponent = ( - props: ComponentProps, + props: ComponentProps, ): ReactElement => { - - const [isLoading, setIsLoading] = React.useState(false); - const [error, setError] = React.useState(undefined); - const [feedItems, setFeedItems] = React.useState([]); - - - const getFeedItemsFromIncidentFeeds = (incidentFeeds: IncidentFeed[]): FeedItemProps[] => { - return incidentFeeds.map((incidentFeed: IncidentFeed) => { - return getFeedItemFromIncidentFeed(incidentFeed); - }); + const [isLoading, setIsLoading] = React.useState(false); + const [error, setError] = React.useState(undefined); + const [feedItems, setFeedItems] = React.useState([]); + + const getFeedItemsFromIncidentFeeds = ( + incidentFeeds: IncidentFeed[], + ): FeedItemProps[] => { + return incidentFeeds.map((incidentFeed: IncidentFeed) => { + return getFeedItemFromIncidentFeed(incidentFeed); + }); + }; + + const getFeedItemFromIncidentFeed = ( + incidentFeed: IncidentFeed, + ): FeedItemProps => { + let icon: IconProp = IconProp.Circle; + + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.IncidentCreated + ) { + icon = IconProp.Alert; } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.IncidentStateChanged + ) { + icon = IconProp.ArrowCircleRight; + } - const getFeedItemFromIncidentFeed = (incidentFeed: IncidentFeed): FeedItemProps => { - - - let icon: IconProp = IconProp.Circle; - - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.IncidentCreated){ - icon = IconProp.Alert; - } - - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.IncidentStateChanged){ - icon = IconProp.ArrowCircleRight; - } - - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.IncidentUpdated){ - icon = IconProp.Edit; - } - - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OwnerNotificationSent){ - icon = IconProp.Bell; - } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.IncidentUpdated + ) { + icon = IconProp.Edit; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.SubscriberNotificationSent){ - icon = IconProp.Notification; - } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.OwnerNotificationSent + ) { + icon = IconProp.Bell; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.PublicNote){ - icon = IconProp.Announcement; - } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.SubscriberNotificationSent + ) { + icon = IconProp.Notification; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.PrivateNote){ - icon = IconProp.Lock; - } + if ( + incidentFeed.incidentFeedEventType === IncidentFeedEventType.PublicNote + ) { + icon = IconProp.Announcement; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OwnerUserAdded){ - icon = IconProp.User; - } + if ( + incidentFeed.incidentFeedEventType === IncidentFeedEventType.PrivateNote + ) { + icon = IconProp.Lock; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OwnerTeamAdded){ - icon = IconProp.Team; - } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.OwnerUserAdded + ) { + icon = IconProp.User; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.RemediationNotes){ - icon = IconProp.Announcement; - } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.OwnerTeamAdded + ) { + icon = IconProp.Team; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.RootCause){ - icon = IconProp.Cube; - } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.RemediationNotes + ) { + icon = IconProp.Announcement; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OwnerUserRemoved){ - icon = IconProp.Close; - } + if ( + incidentFeed.incidentFeedEventType === IncidentFeedEventType.RootCause + ) { + icon = IconProp.Cube; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OwnerTeamRemoved){ - icon = IconProp.Close; - } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.OwnerUserRemoved + ) { + icon = IconProp.Close; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OnCallNotification){ - icon = IconProp.Alert; - } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.OwnerTeamRemoved + ) { + icon = IconProp.Close; + } - if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OnCallPolicy){ - icon = IconProp.Call; - } + if ( + incidentFeed.incidentFeedEventType === + IncidentFeedEventType.OnCallNotification + ) { + icon = IconProp.Alert; + } - return { - key: incidentFeed.id!.toString(), - textInMarkdown: incidentFeed.feedInfoInMarkdown || "", - moreTextInMarkdown: incidentFeed.moreInformationInMarkdown || "", - user: incidentFeed.user, - itemDateTime: incidentFeed.postedAt || incidentFeed.createdAt!, - color: incidentFeed.displayColor || Gray500, - icon: icon, - }; + if ( + incidentFeed.incidentFeedEventType === IncidentFeedEventType.OnCallPolicy + ) { + icon = IconProp.Call; } + return { + key: incidentFeed.id!.toString(), + textInMarkdown: incidentFeed.feedInfoInMarkdown || "", + moreTextInMarkdown: incidentFeed.moreInformationInMarkdown || "", + user: incidentFeed.user, + itemDateTime: incidentFeed.postedAt || incidentFeed.createdAt!, + color: incidentFeed.displayColor || Gray500, + icon: icon, + }; + }; + + const fetchItems = async () => { + setError(""); + setIsLoading(true); + try { + const incidentFeeds: ListResult = await ModelAPI.getList({ + modelType: IncidentFeed, + query: { + incidentId: props.incidentId!, + }, + select: { + moreInformationInMarkdown: true, + feedInfoInMarkdown: true, + displayColor: true, + createdAt: true, + user: { + name: true, + email: true, + profilePictureId: true, + }, + incidentFeedEventType: true, + postedAt: true, + }, + skip: 0, + sort: { + postedAt: SortOrder.Ascending, + }, + limit: LIMIT_PER_PROJECT, + }); + + setFeedItems(getFeedItemsFromIncidentFeeds(incidentFeeds.data)); + } catch (err) { + setError(API.getFriendlyMessage(err)); + } - const fetchItems = async () => { - setError(""); - setIsLoading(true); - try { + setIsLoading(false); + }; + useEffect(() => { + if (!props.incidentId) { + return; + } - const incidentFeeds: ListResult = await ModelAPI.getList({ - modelType: IncidentFeed, - query: { - incidentId: props.incidentId!, - }, - select: { - moreInformationInMarkdown: true, - feedInfoInMarkdown: true, - displayColor: true, - createdAt: true, - user: { - name: true, - email: true, - profilePictureId: true, - }, - incidentFeedEventType: true, - postedAt: true, - }, - skip: 0, - sort: { - postedAt: SortOrder.Ascending - }, - limit: LIMIT_PER_PROJECT - }); - - setFeedItems(getFeedItemsFromIncidentFeeds(incidentFeeds.data)); - - } catch (err) { - setError(API.getFriendlyMessage(err)); - } - - setIsLoading(false); - - } - - useEffect(() => { - - if (!props.incidentId) { - return; - } - - fetchItems().catch((err) => { - setError(API.getFriendlyMessage(err)); - }); - - }, [props.incidentId]); - - - return ( - { - await fetchItems(); - } - } - ]} - > -
    - {isLoading && } - {error && } - {!isLoading && !error && } -
    -
    - ); + fetchItems().catch((err) => { + setError(API.getFriendlyMessage(err)); + }); + }, [props.incidentId]); + + return ( + { + await fetchItems(); + }, + }, + ]} + > +
    + {isLoading && } + {error && } + {!isLoading && !error && ( + + )} +
    +
    + ); }; export default IncidentFeedElement; diff --git a/Dashboard/src/Components/User/User.tsx b/Dashboard/src/Components/User/User.tsx index 1bf4d64170..dedb245b5c 100644 --- a/Dashboard/src/Components/User/User.tsx +++ b/Dashboard/src/Components/User/User.tsx @@ -69,7 +69,9 @@ const UserElement: FunctionComponent = ( {props.user?.profilePictureId && ( {user["name"]?.toString() )} diff --git a/Dashboard/src/Pages/Incidents/View/Index.tsx b/Dashboard/src/Pages/Incidents/View/Index.tsx index e1b78a32f5..73c9a89090 100644 --- a/Dashboard/src/Pages/Incidents/View/Index.tsx +++ b/Dashboard/src/Pages/Incidents/View/Index.tsx @@ -770,10 +770,7 @@ const IncidentView: FunctionComponent< )} - - - - + ); };