Skip to content

Commit

Permalink
refactor: clean up state initialization and formatting in IncidentFee…
Browse files Browse the repository at this point in the history
…d component
  • Loading branch information
simlarsen committed Jan 16, 2025
1 parent ce69383 commit 8be022e
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 113 deletions.
1 change: 0 additions & 1 deletion Common/Server/Services/IncidentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ ${onUpdate.updateBy.data.rootCause || "No root cause provided."}
});
}


if (onUpdate.updateBy.data.description) {
// add incident feed.
const createdByUserId: ObjectID | undefined | null =
Expand Down
222 changes: 110 additions & 112 deletions Dashboard/src/Components/Incident/IncidentFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ const IncidentFeedElement: FunctionComponent<ComponentProps> = (
const [error, setError] = React.useState<string | undefined>(undefined);
const [feedItems, setFeedItems] = React.useState<FeedItemProps[]>([]);

const [showPublicNoteModal, setShowPublicNoteModal] = React.useState<boolean>(
false,
);

const [showPrivateNoteModal, setShowPrivateNoteModal] = React.useState<boolean>(
false,
);
const [showPublicNoteModal, setShowPublicNoteModal] =
React.useState<boolean>(false);

const [showPrivateNoteModal, setShowPrivateNoteModal] =
React.useState<boolean>(false);

type GetFeedItemsFromIncidentFeeds = (
incidentFeeds: IncidentFeed[],
Expand Down Expand Up @@ -237,16 +234,16 @@ const IncidentFeedElement: FunctionComponent<ComponentProps> = (
buttonStyle: ButtonStyleType.NORMAL,
icon: IconProp.Team,
onClick: () => {
setShowPublicNoteModal(true);
}
setShowPublicNoteModal(true);
},
},
{
title: "Add Private Note",
buttonStyle: ButtonStyleType.NORMAL,
icon: IconProp.Lock,
onClick: () => {
setShowPrivateNoteModal(true);
}
setShowPrivateNoteModal(true);
},
},
{
title: "Refresh",
Expand All @@ -268,111 +265,112 @@ const IncidentFeedElement: FunctionComponent<ComponentProps> = (
/>
)}
{showPublicNoteModal && (
<ModelFormModal
modelType={IncidentPublicNote}
name={"create-incidentt-public-note"}
title={"Add Public Note to this Incident"}
description={
"Add a public note to this incident. This note will be visible to all subscribers of this incident and will show up on the status page."
}
onClose={() => {
setShowPublicNoteModal(false);
}}
submitButtonText="Save"
onBeforeCreate={async (model: IncidentPublicNote) => {
model.incidentId = props.incidentId!;
return model;
}}
onSuccess={() => {
setShowPublicNoteModal(false);
fetchItems().catch((err: unknown) => {
setError(API.getFriendlyMessage(err as Exception));
});
}}
formProps={{
name: "create-scheduled-maintenance-state-timeline",
modelType: IncidentPublicNote,
id: "create-scheduled-maintenance-state-timeline",
fields: [
{
field: {
note: true,
<ModelFormModal
modelType={IncidentPublicNote}
name={"create-incidentt-public-note"}
title={"Add Public Note to this Incident"}
description={
"Add a public note to this incident. This note will be visible to all subscribers of this incident and will show up on the status page."
}
onClose={() => {
setShowPublicNoteModal(false);
}}
submitButtonText="Save"
onBeforeCreate={async (model: IncidentPublicNote) => {
model.incidentId = props.incidentId!;
return model;
}}
onSuccess={() => {
setShowPublicNoteModal(false);
fetchItems().catch((err: unknown) => {
setError(API.getFriendlyMessage(err as Exception));
});
}}
formProps={{
name: "create-scheduled-maintenance-state-timeline",
modelType: IncidentPublicNote,
id: "create-scheduled-maintenance-state-timeline",
fields: [
{
field: {
note: true,
},
fieldType: FormFieldSchemaType.Markdown,
description:
"Post a public note about this state change to the status page.",
title: "Public Note",
required: true,
},
fieldType: FormFieldSchemaType.Markdown,
description:
"Post a public note about this state change to the status page.",
title: "Public Note",
required: true,
},
{
field: {
postedAt: true,
{
field: {
postedAt: true,
},
fieldType: FormFieldSchemaType.DateTime,
description:
"The date and time this note was posted. By default, it will be the current date and time.",
title: "Posted At",
required: true,
defaultValue: OneUptimeDate.getCurrentDate(),
},
fieldType: FormFieldSchemaType.DateTime,
description:
"The date and time this note was posted. By default, it will be the current date and time.",
title: "Posted At",
required: true,
defaultValue: OneUptimeDate.getCurrentDate(),
},
{
field: {
shouldStatusPageSubscribersBeNotifiedOnNoteCreated: true,
{
field: {
shouldStatusPageSubscribersBeNotifiedOnNoteCreated: true,
},
fieldType: FormFieldSchemaType.Checkbox,
description:
"Should status page subscribers be notified when this note is posted?",
title: "Notify Status Page Subscribers",
required: false,
defaultValue: true,
},
fieldType: FormFieldSchemaType.Checkbox,
description: "Should status page subscribers be notified when this note is posted?",
title: "Notify Status Page Subscribers",
required: false,
defaultValue: true,
},
],
formType: FormType.Create,
}}
/>
)}

{showPrivateNoteModal && (
<ModelFormModal
modelType={IncidentInternalNote}
name={"create-incidentt-internal-note"}
title={"Add Private Note to this Incident"}
description={
"Add a private note to this incident. This note will be visible only to the team members of this incident."
}
onClose={() => {
setShowPrivateNoteModal(false);
}}
submitButtonText="Save"
onBeforeCreate={async (model: IncidentInternalNote) => {
model.incidentId = props.incidentId!;
return model;
}}
onSuccess={() => {
setShowPrivateNoteModal(false);
fetchItems().catch((err: unknown) => {
setError(API.getFriendlyMessage(err as Exception));
});
}}
formProps={{
name: "create-incident-internal-note",
modelType: IncidentInternalNote,
id: "create-incident-internal-note",
fields: [
{
field: {
note: true,
],
formType: FormType.Create,
}}
/>
)}

{showPrivateNoteModal && (
<ModelFormModal
modelType={IncidentInternalNote}
name={"create-incidentt-internal-note"}
title={"Add Private Note to this Incident"}
description={
"Add a private note to this incident. This note will be visible only to the team members of this incident."
}
onClose={() => {
setShowPrivateNoteModal(false);
}}
submitButtonText="Save"
onBeforeCreate={async (model: IncidentInternalNote) => {
model.incidentId = props.incidentId!;
return model;
}}
onSuccess={() => {
setShowPrivateNoteModal(false);
fetchItems().catch((err: unknown) => {
setError(API.getFriendlyMessage(err as Exception));
});
}}
formProps={{
name: "create-incident-internal-note",
modelType: IncidentInternalNote,
id: "create-incident-internal-note",
fields: [
{
field: {
note: true,
},
fieldType: FormFieldSchemaType.Markdown,
description:
"Post a private note about this incident. This note will be visible only to the team members of this incident.",
title: "Private Note",
required: true,
},
fieldType: FormFieldSchemaType.Markdown,
description:
"Post a private note about this incident. This note will be visible only to the team members of this incident.",
title: "Private Note",
required: true,
}
],
formType: FormType.Create,
}}
/>
)}
],
formType: FormType.Create,
}}
/>
)}
</div>
</Card>
);
Expand Down

0 comments on commit 8be022e

Please sign in to comment.