refactor: Update Cookie.ts to accept string as key parameter

This commit modifies the Cookie.ts file to update the setItem method signature. The key parameter now accepts both CookieName and string types, allowing for more flexibility when setting cookies. This change improves the usability and versatility of the Cookie utility class.
This commit is contained in:
Simon Larsen
2024-06-18 13:33:09 +01:00
parent 082d800c34
commit d8dff468ab
6 changed files with 85 additions and 68 deletions

View File

@@ -10,7 +10,7 @@ import Navigation from "CommonUI/src/Utils/Navigation";
import UserUtil from "CommonUI/src/Utils/User";
import User from "Model/Models/User";
import React, { ReactElement, useState } from "react";
import ProjectSSO from "Model/Models/ProjectSSO";
import ProjectSSO from "Model/Models/ProjectSso";
import PageLoader from "CommonUI/src/Components/Loader/PageLoader";
import API from "CommonUI/src/Utils/API/API";
import BasicForm from "CommonUI/src/Components/Forms/BasicForm";

View File

@@ -11,8 +11,10 @@
{{> DetailBoxStart this }}
{{> DetailBoxField title="Monitor Name:" text=monitorName }}
{{> DetailBoxField title="New Status: " text=currentStatus }}
{{#ifNotCond rootCause ""}}
{{> DetailBoxField title="Root Cause: " text="" }}
{{> DetailBoxField title="" text=rootCause }}
{{/ifNotCond}}
{{> DetailBoxField title="Status changed at: " text="" }}
{{> DetailBoxField title="" text=statusChangedAt }}
{{> DetailBoxField title="Description: " text="" }}

View File

@@ -1,7 +1,7 @@
{{#if title}}
<p
style="Margin:0;font-size:16px;font-family:'inter','helvetica neue',helvetica,arial,sans-serif;line-height:30px;color:#424761">
<strong>{{{title}}} </strong>{{{text}}} </span></p>
<p style="Margin:0;font-size:16px;font-family:'inter','helvetica neue',helvetica,arial,sans-serif;line-height:30px;color:#424761">
{{#if title}}
<strong>{{{title}}} </strong>{{{text}}} </span>
{{else}}
{{{text}}}
{{/if}}
{{/if}}
</p>

View File

@@ -12,6 +12,7 @@ import IncidentService from "CommonServer/Services/IncidentService";
import ProjectService from "CommonServer/Services/ProjectService";
import UserNotificationSettingService from "CommonServer/Services/UserNotificationSettingService";
import Markdown, { MarkdownContentType } from "CommonServer/Types/Markdown";
import logger from "CommonServer/Utils/Logger";
import Incident from "Model/Models/Incident";
import Monitor from "Model/Models/Monitor";
import User from "Model/Models/User";
@@ -38,6 +39,7 @@ RunCron(
project: {
name: true,
},
remediationNotes: true,
currentIncidentState: {
name: true,
},
@@ -83,67 +85,81 @@ RunCron(
}
for (const user of owners) {
const vars: Dictionary<string> = {
incidentTitle: incident.title!,
projectName: incident.project!.name!,
currentState: incident.currentIncidentState!.name!,
incidentDescription: await Markdown.convertToHTML(
incident.description! || "",
MarkdownContentType.Email,
),
resourcesAffected:
incident
.monitors!.map((monitor: Monitor) => {
return monitor.name!;
})
.join(", ") || "None",
incidentSeverity: incident.incidentSeverity!.name!,
declaredAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones({
date: incidentIdentifiedDate,
timezones: user.timezone ? [user.timezone] : [],
}),
remediationNotes: incident.remediationNotes || "",
rootCause:
incident.rootCause || "No root cause identified for this incident",
incidentViewLink: (
await IncidentService.getIncidentLinkInDashboard(
incident.projectId!,
incident.id!,
)
).toString(),
};
try {
const vars: Dictionary<string> = {
incidentTitle: incident.title!,
projectName: incident.project!.name!,
currentState: incident.currentIncidentState!.name!,
incidentDescription: await Markdown.convertToHTML(
incident.description! || "",
MarkdownContentType.Email,
),
resourcesAffected:
incident
.monitors!.map((monitor: Monitor) => {
return monitor.name!;
})
.join(", ") || "None",
incidentSeverity: incident.incidentSeverity!.name!,
declaredAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones(
{
date: incidentIdentifiedDate,
timezones: user.timezone ? [user.timezone] : [],
},
),
remediationNotes:
(await Markdown.convertToHTML(
incident.remediationNotes! || "",
MarkdownContentType.Email,
)) || "",
rootCause:
incident.rootCause ||
"No root cause identified for this incident",
incidentViewLink: (
await IncidentService.getIncidentLinkInDashboard(
incident.projectId!,
incident.id!,
)
).toString(),
};
if (doesResourceHasOwners === true) {
vars["isOwner"] = "true";
if (doesResourceHasOwners === true) {
vars["isOwner"] = "true";
}
const emailMessage: EmailEnvelope = {
templateType: EmailTemplateType.IncidentOwnerResourceCreated,
vars: vars,
subject: "[New Incident] " + incident.title!,
};
const sms: SMSMessage = {
message: `This is a message from OneUptime. New incident created: ${incident.title}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`,
};
const callMessage: CallRequestMessage = {
data: [
{
sayMessage: `This is a message from OneUptime. New incident created: ${incident.title}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good bye.`,
},
],
};
await UserNotificationSettingService.sendUserNotification({
userId: user.id!,
projectId: incident.projectId!,
emailEnvelope: emailMessage,
smsMessage: sms,
callRequestMessage: callMessage,
eventType:
NotificationSettingEventType.SEND_INCIDENT_CREATED_OWNER_NOTIFICATION,
});
} catch (e) {
logger.error(
"Error in sending incident created resource notification",
);
logger.error(e);
}
const emailMessage: EmailEnvelope = {
templateType: EmailTemplateType.IncidentOwnerResourceCreated,
vars: vars,
subject: "[Incident] " + incident.title!,
};
const sms: SMSMessage = {
message: `This is a message from OneUptime. New incident created: ${incident.title}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`,
};
const callMessage: CallRequestMessage = {
data: [
{
sayMessage: `This is a message from OneUptime. New incident created: ${incident.title}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good bye.`,
},
],
};
await UserNotificationSettingService.sendUserNotification({
userId: user.id!,
projectId: incident.projectId!,
emailEnvelope: emailMessage,
smsMessage: sms,
callRequestMessage: callMessage,
eventType:
NotificationSettingEventType.SEND_INCIDENT_CREATED_OWNER_NOTIFICATION,
});
}
}
},

View File

@@ -106,8 +106,7 @@ RunCron(
monitor.id!,
)
).toString(),
rootCause:
monitorStatusTimeline.rootCause || "No root cause identified.",
rootCause: monitorStatusTimeline.rootCause || "",
};
if (doesResourceHasOwners === true) {

View File

@@ -10,7 +10,7 @@ import CookieName from "Common/Types/CookieName";
export default class Cookie {
public static setItem(
key: CookieName,
key: CookieName | string,
value: JSONValue | Email | URL,
options?:
| {