Skip to content

Commit 20ccc3f

Browse files
committed
Only show alert if templates has the method enabled
1 parent 8ac097c commit 20ccc3f

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

site/src/pages/DeploySettingsPage/NotificationsPage/NotificationEvents.stories.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ import { API } from "api/api";
44
import type { DeploymentValues } from "api/typesGenerated";
55
import { baseMeta } from "./storybookUtils";
66
import { NotificationEvents } from "./NotificationEvents";
7+
import { selectTemplatesByGroup } from "api/queries/notifications";
8+
import { MockNotificationTemplates } from "testHelpers/entities";
79

810
const meta: Meta<typeof NotificationEvents> = {
911
title: "pages/DeploymentSettings/NotificationsPage/NotificationEvents",
1012
component: NotificationEvents,
13+
args: {
14+
defaultMethod: "smtp",
15+
availableMethods: ["smtp", "webhook"],
16+
templatesByGroup: selectTemplatesByGroup(MockNotificationTemplates),
17+
deploymentValues: baseMeta.parameters.deploymentValues
18+
},
1119
...baseMeta,
1220
};
1321

@@ -16,7 +24,7 @@ export default meta;
1624
type Story = StoryObj<typeof NotificationEvents>;
1725

1826
export const NoEmailSmarthost: Story = {
19-
parameters: {
27+
args: {
2028
deploymentValues: {
2129
notifications: {
2230
webhook: {
@@ -31,7 +39,7 @@ export const NoEmailSmarthost: Story = {
3139
};
3240

3341
export const NoWebhookEndpoint: Story = {
34-
parameters: {
42+
args: {
3543
deploymentValues: {
3644
notifications: {
3745
webhook: {

site/src/pages/DeploySettingsPage/NotificationsPage/NotificationEvents.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ export const NotificationEvents: FC<NotificationEventsProps> = ({
3939
templatesByGroup,
4040
deploymentValues,
4141
}) => {
42+
const hasWebhookNotifications = Object.values(templatesByGroup).flat().some(t => t.method === "webhook")
43+
const hasEmailNotifications = Object.values(templatesByGroup).flat().some(t => t.method === "smtp")
44+
4245
return (
4346
<Stack spacing={4}>
44-
{availableMethods.includes("smtp") &&
47+
{hasWebhookNotifications &&
4548
deploymentValues.notifications?.webhook.endpoint === "" && (
4649
<Alert
4750
severity="warning"
@@ -63,7 +66,7 @@ export const NotificationEvents: FC<NotificationEventsProps> = ({
6366
</Alert>
6467
)}
6568

66-
{availableMethods.includes("smtp") &&
69+
{hasEmailNotifications &&
6770
deploymentValues.notifications?.email.smarthost === "" && (
6871
<Alert
6972
severity="warning"

site/src/pages/DeploySettingsPage/NotificationsPage/NotificationsPage.stories.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { Meta, StoryObj } from "@storybook/react";
22
import { userEvent, within } from "@storybook/test";
33
import { NotificationsPage } from "./NotificationsPage";
44
import { baseMeta } from "./storybookUtils";
5+
import { notificationDispatchMethodsKey, systemNotificationTemplatesKey } from "api/queries/notifications";
6+
import { MockNotificationMethodsResponse, MockNotificationTemplates } from "testHelpers/entities";
57

68
const meta: Meta<typeof NotificationsPage> = {
79
title: "pages/DeploymentSettings/NotificationsPage",
@@ -13,6 +15,33 @@ export default meta;
1315

1416
type Story = StoryObj<typeof NotificationsPage>;
1517

18+
export const LoadingTemplates: Story = {
19+
parameters: {
20+
queries: [
21+
{
22+
key: systemNotificationTemplatesKey,
23+
data: undefined,
24+
},
25+
{
26+
key: notificationDispatchMethodsKey,
27+
data: MockNotificationMethodsResponse,
28+
},
29+
]
30+
}
31+
};
32+
33+
export const LoadingDispatchMethods: Story = {
34+
parameters: {
35+
queries: [
36+
{ key: systemNotificationTemplatesKey, data: MockNotificationTemplates },
37+
{
38+
key: notificationDispatchMethodsKey,
39+
data: undefined,
40+
},
41+
]
42+
}
43+
};
44+
1645
export const Events: Story = {};
1746

1847
export const Settings: Story = {

site/src/pages/DeploySettingsPage/NotificationsPage/storybookUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import type { NotificationsPage } from "./NotificationsPage";
1919

2020
// Extracted from a real API response
21-
const mockedOptions: SerpentOption[] = [
21+
export const mockNotificationsDeploymentOptions: SerpentOption[] = [
2222
{
2323
name: "Notifications: Dispatch Timeout",
2424
description:
@@ -195,7 +195,7 @@ export const baseMeta = {
195195
],
196196
user: MockUser,
197197
permissions: { viewDeploymentValues: true },
198-
deploymentOptions: mockedOptions,
198+
deploymentOptions: mockNotificationsDeploymentOptions,
199199
deploymentValues: {
200200
notifications: {
201201
webhook: {

0 commit comments

Comments
 (0)