Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c62242

Browse files
committed
Don't show deployment wide method
1 parent4956409 commit1c62242

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
importEmailIconfrom"@mui/icons-material/EmailOutlined";
2-
importDeploymentIconfrom"@mui/icons-material/LanguageOutlined";
32
importWebhookIconfrom"@mui/icons-material/WebhookOutlined";
43

5-
exportconstmethodIcons:Record<string,typeofEmailIcon>={
6-
"":DeploymentIcon,
4+
// TODO: This should be provided by the auto generated types from codersdk
5+
constnotificationMethods=["smtp","webhook"]asconst;
6+
7+
exporttypeNotificationMethod=(typeofnotificationMethods)[number];
8+
9+
exportconstmethodIcons:Record<NotificationMethod,typeofEmailIcon>={
710
smtp:EmailIcon,
811
webhook:WebhookIcon,
912
};
1013

11-
constmethodLabels:Record<string,string>={
12-
"":"Default",
14+
exportconstmethodLabels:Record<NotificationMethod,string>={
1315
smtp:"SMTP",
1416
webhook:"Webhook",
1517
};
1618

17-
exportconstmethodLabel=(method:string,defaultMethod?:string)=>{
18-
returnmethod===""&&defaultMethod
19-
?`${methodLabels[method]} -${methodLabels[defaultMethod]}`
20-
:methodLabels[method];
19+
exportconstcastNotificationMethod=(value:string)=>{
20+
if(notificationMethods.includes(valueasNotificationMethod)){
21+
returnvalueasNotificationMethod;
22+
}
23+
24+
thrownewError(
25+
`Invalid notification method:${value}. Accepted values:${notificationMethods.join(
26+
", ",
27+
)}`,
28+
);
2129
};

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,30 @@ import { displaySuccess } from "components/GlobalSnackbar/utils";
2222
import{Loader}from"components/Loader/Loader";
2323
import{Stack}from"components/Stack/Stack";
2424
import{useClipboard}from"hooks";
25-
import{methodIcons,methodLabel}from"modules/notifications/utils";
25+
import{
26+
castNotificationMethod,
27+
methodIcons,
28+
methodLabels,
29+
typeNotificationMethod,
30+
}from"modules/notifications/utils";
2631
import{Section}from"pages/UserSettingsPage/Section";
2732
import{useDeploySettings}from"../DeploySettingsLayout";
2833

2934
typeMethodToggleGroupProps={
3035
templateId:string;
31-
value:string;
32-
available:readonlystring[];
33-
defaultMethod:string;
36+
options:NotificationMethod[];
37+
value:NotificationMethod;
3438
};
3539

3640
constMethodToggleGroup:FC<MethodToggleGroupProps>=({
3741
value,
38-
available,
42+
options,
3943
templateId,
40-
defaultMethod,
4144
})=>{
4245
constqueryClient=useQueryClient();
4346
constupdateMethodMutation=useMutation(
4447
updateNotificationTemplateMethod(templateId,queryClient),
4548
);
46-
constoptions=["", ...available];
4749

4850
return(
4951
<ToggleButtonGroup
@@ -61,7 +63,7 @@ const MethodToggleGroup: FC<MethodToggleGroupProps> = ({
6163
>
6264
{options.map((method)=>{
6365
constIcon=methodIcons[method];
64-
constlabel=methodLabel(method,defaultMethod);
66+
constlabel=methodLabels[method];
6567
return(
6668
<Tooltipkey={method}title={label}>
6769
<ToggleButton
@@ -105,7 +107,7 @@ export const NotificationsPage: FC = () => {
105107

106108
return(
107109
<Section
108-
title="Notification Targets"
110+
title="Notifications"
109111
description="Control delivery methods for notifications. Settings applied to this deployment."
110112
layout="fluid"
111113
>
@@ -131,6 +133,13 @@ export const NotificationsPage: FC = () => {
131133
</ListItem>
132134

133135
{templates.map((tpl)=>{
136+
constvalue=castNotificationMethod(
137+
tpl.method||dispatchMethods.data.default,
138+
);
139+
constoptions=dispatchMethods.data.available.map(
140+
castNotificationMethod,
141+
);
142+
134143
return(
135144
<Fragmentkey={tpl.id}>
136145
<ListItem>
@@ -139,10 +148,9 @@ export const NotificationsPage: FC = () => {
139148
primary={tpl.name}
140149
/>
141150
<MethodToggleGroup
142-
defaultMethod={dispatchMethods.data.default}
143151
templateId={tpl.id}
144-
available={dispatchMethods.data.available}
145-
value={tpl.method}
152+
options={options}
153+
value={value}
146154
/>
147155
</ListItem>
148156
<Dividercss={styles.divider}/>

‎site/src/pages/UserSettingsPage/NotificationsPage/NotificationsPage.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import { displaySuccess } from "components/GlobalSnackbar/utils";
2424
import{Loader}from"components/Loader/Loader";
2525
import{Stack}from"components/Stack/Stack";
2626
import{useAuthenticated}from"contexts/auth/RequireAuth";
27-
import{methodIcons,methodLabel}from"modules/notifications/utils";
27+
import{
28+
castNotificationMethod,
29+
methodIcons,
30+
methodLabels,
31+
}from"modules/notifications/utils";
2832
import{Section}from"../Section";
2933

3034
typePreferenceSwitchProps={
@@ -129,11 +133,11 @@ export const NotificationsPage: FC = () => {
129133
/>
130134
</ListItem>
131135
{templates.map((tmpl)=>{
132-
constIcon=methodIcons[tmpl.method];
133-
constlabel=methodLabel(
134-
tmpl.method,
135-
dispatchMethods.data.default,
136+
constmethod=castNotificationMethod(
137+
tmpl.method||dispatchMethods.data.default,
136138
);
139+
constIcon=methodIcons[method];
140+
constlabel=methodLabels[method];
137141

138142
return(
139143
<Fragmentkey={tmpl.id}>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp