feat: Add disableCreate prop to MonitorTable component

This commit is contained in:
Simon Larsen
2024-07-03 17:26:33 +01:00
parent 9866919873
commit 94c50b980a
6 changed files with 49 additions and 12 deletions

View File

@@ -538,7 +538,7 @@ export class Service extends DatabaseService<Model> {
// notify owners that no probe is enabled.
this.notifyOwnersWhenNoProbeIsEnabled({
await this.notifyOwnersWhenNoProbeIsEnabled({
monitorId: monitorId,
isNoProbesEnabled: true,
});
@@ -556,7 +556,7 @@ export class Service extends DatabaseService<Model> {
// notify owners that probes are now enabled.
this.notifyOwnersWhenNoProbeIsEnabled({
await this.notifyOwnersWhenNoProbeIsEnabled({
monitorId: monitorId,
isNoProbesEnabled: false,
});
@@ -566,12 +566,15 @@ export class Service extends DatabaseService<Model> {
(monitorProbe: MonitorProbe) => {
return (
monitorProbe.probe?.connectionStatus ===
ProbeConnectionStatus.Disconnected
ProbeConnectionStatus.Disconnected && monitorProbe.isEnabled
);
},
);
if (disconnectedProbes.length === probesForMonitor.length) {
if (
disconnectedProbes.length === enabledProbes.length &&
enabledProbes.length > 0
) {
if (!monitor.isAllProbesDisconnectedFromThisMonitor) {
// all probes are disconnected.
await this.updateOneById({
@@ -584,7 +587,7 @@ export class Service extends DatabaseService<Model> {
},
});
this.notifyOwnersProbesDisconnected({
await this.notifyOwnersProbesDisconnected({
monitorId: monitorId,
isProbeDisconnected: true,
});
@@ -600,7 +603,7 @@ export class Service extends DatabaseService<Model> {
},
});
this.notifyOwnersProbesDisconnected({
await this.notifyOwnersProbesDisconnected({
monitorId: monitorId,
isProbeDisconnected: false,
});
@@ -635,9 +638,20 @@ export class Service extends DatabaseService<Model> {
return;
}
const monitorId: ObjectID = monitor.id;
let doesResourceHasOwners: boolean = true;
const owners: Array<User> = await this.findOwners(monitorId);
let owners: Array<User> = await this.findOwners(monitor.id!);
if (owners.length === 0) {
doesResourceHasOwners = false;
// find project owners.
owners = await ProjectService.getOwners(monitor.projectId!);
}
if (owners.length === 0) {
return;
}
const title: string = data.isNoProbesEnabled
? "No Probes Enabled. This monitor is not being monitored"
@@ -650,7 +664,7 @@ export class Service extends DatabaseService<Model> {
const vars: Dictionary<string> = {
title: title,
monitorName: monitor.name!,
currentStatus: status,
currentStatus: enabledStatus,
projectName: monitor.project!.name!,
monitorDescription: await Markdown.convertToHTML(
monitor.description! || "",
@@ -661,6 +675,10 @@ export class Service extends DatabaseService<Model> {
).toString(),
};
if (doesResourceHasOwners === true) {
vars["isOwner"] = "true";
}
for (const owner of owners) {
// send email to the owner.
@@ -722,9 +740,20 @@ export class Service extends DatabaseService<Model> {
return;
}
const monitorId: ObjectID = monitor.id;
let doesResourceHasOwners: boolean = true;
const owners: Array<User> = await this.findOwners(monitorId);
let owners: Array<User> = await this.findOwners(monitor.id!);
if (owners.length === 0) {
doesResourceHasOwners = false;
// find project owners.
owners = await ProjectService.getOwners(monitor.projectId!);
}
if (owners.length === 0) {
return;
}
const status: string = data.isProbeDisconnected
? "Disconnected"
@@ -744,6 +773,10 @@ export class Service extends DatabaseService<Model> {
).toString(),
};
if (doesResourceHasOwners === true) {
vars["isOwner"] = "true";
}
for (const owner of owners) {
// send email to the owner.

View File

@@ -41,6 +41,7 @@ export interface ComponentProps {
noItemsMessage?: string | undefined;
title?: string | undefined;
description?: string | undefined;
disableCreate?: boolean | undefined;
}
const MonitorsTable: FunctionComponent<ComponentProps> = (
@@ -171,7 +172,7 @@ const MonitorsTable: FunctionComponent<ComponentProps> = (
isDeleteable={false}
showViewIdButton={true}
isEditable={false}
isCreateable={true}
isCreateable={!props.disableCreate}
isViewable={true}
query={props.query || {}}
createEditModalWidth={ModalWidth.Large}

View File

@@ -9,6 +9,7 @@ const DisabledMonitors: FunctionComponent = (): ReactElement => {
projectId: DashboardNavigation.getProjectId()?.toString(),
disableActiveMonitoring: true,
}}
disableCreate={true}
noItemsMessage="No disabled monitors. All monitors in active state."
title="Disabled Monitors"
description="Here is a list of all the monitors which are in disabled state."

View File

@@ -9,6 +9,7 @@ const DisabledMonitors: FunctionComponent = (): ReactElement => {
projectId: DashboardNavigation.getProjectId()?.toString(),
isNoProbeEnabledOnThisMonitor: true,
}}
disableCreate={true}
noItemsMessage="No monitors with disabled probes. All your monitors are being monitored."
title="Monitors with all probes disabled"
description="Here is a list of all the monitors where all probes are disabled. These monitors are not being monitored."

View File

@@ -9,6 +9,7 @@ const DisabledMonitors: FunctionComponent = (): ReactElement => {
projectId: DashboardNavigation.getProjectId()?.toString(),
isAllProbesDisconnectedFromThisMonitor: true,
}}
disableCreate={true}
noItemsMessage="No monitors with disconnected probes. All your monitors are being monitored."
title="Monitors with all probes disconnected"
description="Here is a list of all the monitors where all probes are disconnected. These monitors are not being monitored."