Skip to content

Commit d97dd82

Browse files
committed
Apply a few Michaels suggestions
1 parent 341f550 commit d97dd82

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

site/src/api/queries/notifications.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const updateUserNotificationPreferences = (
3838
id,
3939
disabled,
4040
updated_at: new Date().toISOString(),
41-
}) as NotificationPreference,
41+
}) satisfies NotificationPreference,
4242
),
4343
);
4444
},
@@ -65,7 +65,7 @@ export const systemNotificationTemplates = () => {
6565
export function selectTemplatesByGroup(
6666
data: NotificationTemplate[],
6767
): Record<string, NotificationTemplate[]> {
68-
return data.reduce(
68+
const grouped = data.reduce(
6969
(acc, tpl) => {
7070
if (!acc[tpl.group]) {
7171
acc[tpl.group] = [];
@@ -75,6 +75,20 @@ export function selectTemplatesByGroup(
7575
},
7676
{} as Record<string, NotificationTemplate[]>,
7777
);
78+
79+
// Sort templates within each group
80+
for (const group in grouped) {
81+
grouped[group].sort((a, b) => a.name.localeCompare(b.name));
82+
}
83+
84+
// Sort groups by name
85+
const sortedGroups = Object.keys(grouped).sort((a, b) => a.localeCompare(b));
86+
const sortedGrouped: Record<string, NotificationTemplate[]> = {};
87+
for (const group of sortedGroups) {
88+
sortedGrouped[group] = grouped[group];
89+
}
90+
91+
return sortedGrouped;
7892
}
7993

8094
export const notificationDispatchMethodsKey = [

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const EventsView: FC<EventsViewProps> = ({
190190
deploymentValues,
191191
}) => {
192192
return (
193-
<Stack spacing={3}>
193+
<Stack spacing={4}>
194194
{availableMethods.includes("smtp") &&
195195
deploymentValues.notifications?.webhook.endpoint === "" && (
196196
<Alert severity="warning">
@@ -218,8 +218,9 @@ const EventsView: FC<EventsViewProps> = ({
218218
<ListItemText css={styles.listItemText} primary={group} />
219219
</ListItem>
220220

221-
{templates.map((tpl) => {
221+
{templates.map((tpl, i) => {
222222
const value = castNotificationMethod(tpl.method || defaultMethod);
223+
const isLastItem = i === templates.length - 1;
223224

224225
return (
225226
<Fragment key={tpl.id}>
@@ -234,7 +235,7 @@ const EventsView: FC<EventsViewProps> = ({
234235
value={value}
235236
/>
236237
</ListItem>
237-
<Divider css={styles.divider} />
238+
{!isLastItem && <Divider />}
238239
</Fragment>
239240
);
240241
})}
@@ -281,9 +282,4 @@ const styles = {
281282
fontSize: "inherit",
282283
},
283284
}),
284-
divider: {
285-
"&:last-child": {
286-
display: "none",
287-
},
288-
},
289285
} as Record<string, Interpolation<Theme>>;

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const NotificationsPage: FC = () => {
102102
layout="fluid"
103103
>
104104
{ready ? (
105-
<Stack spacing={3}>
105+
<Stack spacing={4}>
106106
{Object.entries(templatesByGroup.data).map(([group, templates]) => {
107107
const allDisabled = templates.some((tpl) => {
108108
return disabledPreferences.data[tpl.id] === true;
@@ -138,12 +138,13 @@ export const NotificationsPage: FC = () => {
138138
}}
139139
/>
140140
</ListItem>
141-
{templates.map((tmpl) => {
141+
{templates.map((tmpl, i) => {
142142
const method = castNotificationMethod(
143143
tmpl.method || dispatchMethods.data.default,
144144
);
145145
const Icon = methodIcons[method];
146146
const label = methodLabels[method];
147+
const isLastItem = i === templates.length - 1;
147148

148149
return (
149150
<Fragment key={tmpl.id}>
@@ -177,7 +178,7 @@ export const NotificationsPage: FC = () => {
177178
</Tooltip>
178179
</ListItemIcon>
179180
</ListItem>
180-
<Divider css={styles.divider} />
181+
{!isLastItem && <Divider />}
181182
</Fragment>
182183
);
183184
})}
@@ -230,9 +231,4 @@ const styles = {
230231
fontSize: "inherit",
231232
},
232233
}),
233-
divider: {
234-
"&:last-child": {
235-
display: "none",
236-
},
237-
},
238234
} as Record<string, Interpolation<Theme>>;

0 commit comments

Comments
 (0)