feat: Collapsible notification setting groups (#14653)

* feat: Group notification settings into sections with group toggles

* fix: Restore unsaved notification settings when a save fails

* feat: Collapsible notification groups with summaries
This commit is contained in:
Tom Moor authored and GitHub committed 2026-11-19 22:07:56 -05:00
1 parent a241788c3a
commit dbc1e84ec9
4 files changed
+395 -169

No files matched your search

+3 -2
View File
@@ -45,7 +45,7 @@ export function Collapsible({
<StyledExpandedIcon aria-hidden="true" />
{label}
</StyledTrigger>
<StyledContent>{children}</StyledContent>
<CollapsibleContent>{children}</CollapsibleContent>
</RadixCollapsible.Root>
);
}
@@ -77,7 +77,8 @@ const StyledTrigger = styled(RadixCollapsible.Trigger)`
}
`;
const StyledContent = styled(RadixCollapsible.Content)`
/** An animated Radix Collapsible content panel. */
export const CollapsibleContent = styled(RadixCollapsible.Content)`
overflow: hidden;
&[data-state="open"] {
+273 -148
View File
@@ -20,6 +20,7 @@ import * as React from "react";
import { useTranslation, Trans } from "react-i18next";
import { toast } from "sonner";
import { NotificationEventType } from "@shared/types";
import { errToString } from "@shared/utils/error";
import Heading from "~/components/Heading";
import Notice from "~/components/Notice";
import Scene from "~/components/Scene";
@@ -29,147 +30,221 @@ import useCurrentUser from "~/hooks/useCurrentUser";
import { client } from "~/utils/ApiClient";
import isCloudHosted from "~/utils/isCloudHosted";
import SettingRow from "./components/SettingRow";
import { SettingsSection } from "./components/SettingsSection";
interface NotificationOption {
/** The event types that the option controls. */
events: NotificationEventType[];
/** The icon for the option. */
icon: React.ReactNode;
/** The label for the option. */
title: string;
/** The description for the option. */
description: string;
}
interface NotificationGroup {
/** A stable key for the group. */
id: string;
/** The section heading. */
title: string;
/** A summary of the notification types in the group. */
description: string;
/** Whether the group is shown. Defaults to true. */
visible?: boolean;
/** The options in the group. */
options: NotificationOption[];
}
function Notifications() {
const user = useCurrentUser();
const { t } = useTranslation();
const options = [
const groups: NotificationGroup[] = [
{
events: [NotificationEventType.PublishDocument],
icon: <PublishIcon />,
title: t("Document published"),
id: "documents",
title: t("Documents"),
description: t(
"Receive a notification whenever a new document is published"
"Documents that are published, updated, or shared with you, and access requests"
),
},
{
events: [NotificationEventType.UpdateDocument],
icon: <EditIcon />,
title: t("Document updated"),
description: t(
"Receive a notification when a document you are subscribed to is edited"
),
},
{
events: [NotificationEventType.CreateComment],
icon: <CommentIcon />,
title: t("Comment posted"),
description: t(
"Receive a notification when a document you are subscribed to or a thread you participated in receives a comment"
),
},
{
events: [
NotificationEventType.MentionedInComment,
NotificationEventType.MentionedInDocument,
options: [
{
events: [NotificationEventType.PublishDocument],
icon: <PublishIcon />,
title: t("Document published"),
description: t(
"Receive a notification whenever a new document is published"
),
},
{
events: [NotificationEventType.UpdateDocument],
icon: <EditIcon />,
title: t("Document updated"),
description: t(
"Receive a notification when a document you are subscribed to is edited"
),
},
{
events: [NotificationEventType.AddUserToDocument],
icon: <DocumentIcon />,
title: t("Invited to document"),
description: t(
"Receive a notification when a document is shared with you"
),
},
{
events: [NotificationEventType.RequestDocumentAccess],
icon: <CheckboxIcon checked />,
title: t("Document access requested"),
description: t(
"Receive a notification when a user requests access to a document you manage"
),
},
],
icon: <EmailIcon />,
title: t("Mentioned"),
description: t(
"Receive a notification when someone mentions you in a document or comment"
),
},
{
events: [
NotificationEventType.GroupMentionedInDocument,
NotificationEventType.GroupMentionedInComment,
id: "collections",
title: t("Collections"),
description: t("New collections and access to collections"),
options: [
{
events: [NotificationEventType.CreateCollection],
icon: <CollectionIcon />,
title: t("Collection created"),
description: t(
"Receive a notification whenever a new collection is created"
),
},
{
events: [NotificationEventType.AddUserToCollection],
icon: <CollectionIcon />,
title: t("Invited to collection"),
description: t(
"Receive a notification when you are given access to a collection"
),
},
],
icon: <GroupIcon />,
title: t("Group mentions"),
description: t(
"Receive a notification when someone mentions a group you are a member of in a document or comment"
),
},
{
events: [NotificationEventType.ResolveComment],
icon: <DoneIcon />,
title: t("Resolved"),
id: "comments",
title: t("Comments and mentions"),
description: t(
"Receive a notification when a comment thread you were involved in is resolved"
"New comments, mentions of you or your groups, resolved threads, and reactions"
),
options: [
{
events: [NotificationEventType.CreateComment],
icon: <CommentIcon />,
title: t("Comment posted"),
description: t(
"Receive a notification when a document you are subscribed to or a thread you participated in receives a comment"
),
},
{
events: [
NotificationEventType.MentionedInComment,
NotificationEventType.MentionedInDocument,
],
icon: <EmailIcon />,
title: t("Mentioned"),
description: t(
"Receive a notification when someone mentions you in a document or comment"
),
},
{
events: [
NotificationEventType.GroupMentionedInDocument,
NotificationEventType.GroupMentionedInComment,
],
icon: <GroupIcon />,
title: t("Group mentions"),
description: t(
"Receive a notification when someone mentions a group you are a member of in a document or comment"
),
},
{
events: [NotificationEventType.ResolveComment],
icon: <DoneIcon />,
title: t("Resolved"),
description: t(
"Receive a notification when a comment thread you were involved in is resolved"
),
},
{
events: [NotificationEventType.ReactionsCreate],
icon: <SmileyIcon />,
title: t("Reaction added"),
description: t(
"Receive a notification when someone reacts to your comment"
),
},
],
},
{
events: [NotificationEventType.ReactionsCreate],
icon: <SmileyIcon />,
title: t("Reaction added"),
id: "workspace",
title: t("Workspace"),
description: t(
"Receive a notification when someone reacts to your comment"
"Group membership, accepted invites, and completed exports"
),
options: [
{
events: [NotificationEventType.AddUserToGroup],
icon: <GroupIcon />,
title: t("Group membership"),
description: t(
"Receive a notification when you are added to or removed from a group"
),
},
{
events: [NotificationEventType.InviteAccepted],
icon: <UserIcon />,
title: t("Invite accepted"),
description: t(
"Receive a notification when someone you invited creates an account"
),
},
{
events: [NotificationEventType.ExportCompleted],
icon: <CheckboxIcon checked />,
title: t("Export completed"),
description: t(
"Receive a notification when an export you requested has been completed"
),
},
],
},
{
events: [NotificationEventType.CreateCollection],
icon: <CollectionIcon />,
title: t("Collection created"),
id: "product",
title: t("Product updates"),
description: t(
"Receive a notification whenever a new collection is created"
"Tips on getting started and announcements of new features"
),
},
{
events: [NotificationEventType.InviteAccepted],
icon: <UserIcon />,
title: t("Invite accepted"),
description: t(
"Receive a notification when someone you invited creates an account"
),
},
{
events: [NotificationEventType.AddUserToDocument],
icon: <DocumentIcon />,
title: t("Invited to document"),
description: t(
"Receive a notification when a document is shared with you"
),
},
{
events: [NotificationEventType.AddUserToCollection],
icon: <CollectionIcon />,
title: t("Invited to collection"),
description: t(
"Receive a notification when you are given access to a collection"
),
},
{
events: [NotificationEventType.AddUserToGroup],
icon: <GroupIcon />,
title: t("Group membership"),
description: t(
"Receive a notification when you are added to or removed from a group"
),
},
{
events: [NotificationEventType.ExportCompleted],
icon: <CheckboxIcon checked />,
title: t("Export completed"),
description: t(
"Receive a notification when an export you requested has been completed"
),
},
{
events: [NotificationEventType.RequestDocumentAccess],
icon: <CheckboxIcon checked />,
title: t("Document access requested"),
description: t(
"Receive a notification when a user requests access to a document you manage"
),
},
{
visible: isCloudHosted,
icon: <AcademicCapIcon />,
events: [NotificationEventType.Onboarding],
title: t("Getting started"),
description: t("Tips on getting started with features and functionality"),
},
{
visible: isCloudHosted,
icon: <StarredIcon />,
events: [NotificationEventType.Features],
title: t("New features"),
description: t("Receive an email when new features of note are added"),
options: [
{
icon: <AcademicCapIcon />,
events: [NotificationEventType.Onboarding],
title: t("Getting started"),
description: t(
"Tips on getting started with features and functionality"
),
},
{
icon: <StarredIcon />,
events: [NotificationEventType.Features],
title: t("New features"),
description: t(
"Receive an email when new features of note are added"
),
},
],
},
];
const visibleOptions = options.filter((o) => o.visible !== false);
const visibleGroups = groups.filter((group) => group.visible !== false);
const visibleEvents = visibleGroups.flatMap((group) =>
group.options.flatMap((option) => option.events)
);
const showSuccessMessage = debounce(() => {
toast.success(t("Notifications saved"));
@@ -177,11 +252,40 @@ function Notifications() {
const handleChange = React.useCallback(
(eventTypes: NotificationEventType[]) => async (checked: boolean) => {
// Sequential, as each request saves the full settings object.
for (const eventType of eventTypes) {
await user.setNotificationEventType(eventType, checked);
const changed = eventTypes.filter(
(eventType) => user.subscribedToEventType(eventType) !== checked
);
// Update all switches at once, before the requests complete.
runInAction(() => {
const updated = { ...user.notificationSettings };
for (const eventType of changed) {
updated[eventType] = checked;
}
user.notificationSettings = updated;
});
const unsaved = new Set(changed);
try {
// Sequential, as each request saves the full settings object.
for (const eventType of changed) {
await user.setNotificationEventType(eventType, checked);
unsaved.delete(eventType);
}
showSuccessMessage();
} catch (err) {
toast.error(errToString(err));
// Restore the events that were not saved.
runInAction(() => {
const updated = { ...user.notificationSettings };
for (const eventType of unsaved) {
updated[eventType] = !checked;
}
user.notificationSettings = updated;
});
}
showSuccessMessage();
},
[user, showSuccessMessage]
);
@@ -190,10 +294,8 @@ function Notifications() {
async (checked: boolean) => {
runInAction(() => {
const updated = { ...user.notificationSettings };
for (const option of visibleOptions) {
for (const eventType of option.events) {
updated[eventType] = checked;
}
for (const eventType of visibleEvents) {
updated[eventType] = checked;
}
user.notificationSettings = updated;
});
@@ -204,12 +306,13 @@ function Notifications() {
);
showSuccessMessage();
},
[user, visibleOptions, showSuccessMessage]
[user, visibleEvents, showSuccessMessage]
);
const allEnabled = visibleOptions.every((o) =>
o.events.every((eventType) => user.subscribedToEventType(eventType))
);
const isSubscribed = (eventTypes: NotificationEventType[]) =>
eventTypes.every((eventType) => user.subscribedToEventType(eventType));
const allEnabled = isSubscribed(visibleEvents);
const showSuccessNotice = window.location.search === "?success";
@@ -241,33 +344,55 @@ function Notifications() {
/>
</SettingRow>
{options.map((option) => {
const [name] = option.events;
const checked = option.events.every((eventType) =>
user.subscribedToEventType(eventType)
);
{visibleGroups.map((group) => {
const groupEvents = group.options.flatMap((option) => option.events);
const groupChecked = isSubscribed(groupEvents);
const isMixed =
!groupChecked &&
groupEvents.some((eventType) =>
user.subscribedToEventType(eventType)
);
return (
<SettingRow
key={name}
visible={option.visible}
label={option.title}
name={name}
description={
<Text size="small" type="secondary">
{option.description}
</Text>
<SettingsSection
key={group.id}
title={group.title}
description={group.description}
collapsible
defaultOpen={isMixed}
action={
<Switch
aria-label={group.title}
checked={groupChecked}
onChange={handleChange(groupEvents)}
/>
}
compact
>
<Switch
key={name}
id={name}
name={name}
checked={checked}
onChange={handleChange(option.events)}
/>
</SettingRow>
{group.options.map((option) => {
const [name] = option.events;
return (
<SettingRow
key={name}
label={option.title}
name={name}
description={
<Text size="small" type="secondary">
{option.description}
</Text>
}
compact
>
<Switch
id={name}
name={name}
checked={isSubscribed(option.events)}
onChange={handleChange(option.events)}
/>
</SettingRow>
);
})}
</SettingsSection>
);
})}
</Scene>
@@ -1,7 +1,11 @@
import * as RadixCollapsible from "@radix-ui/react-collapsible";
import { ExpandedIcon } from "outline-icons";
import { transparentize } from "polished";
import * as React from "react";
import styled, { css } from "styled-components";
import { s } from "@shared/styles";
import { breakpoint } from "@shared/styles/breakpoint";
import { CollapsibleContent } from "~/components/Collapsible";
import Text from "~/components/Text";
interface Props {
@@ -9,6 +13,12 @@ interface Props {
title: React.ReactNode;
/** Optional text shown below the heading. */
description?: React.ReactNode;
/** An optional control shown on the right of the heading. */
action?: React.ReactNode;
/** Whether a click on the heading shows or hides the rows. */
collapsible?: boolean;
/** Whether a collapsible section is open on first render. Defaults to true. */
defaultOpen?: boolean;
/** Whether the section holds destructive actions. */
danger?: boolean;
/** The rows in the section, usually SettingRow components. */
@@ -24,21 +34,53 @@ interface Props {
export function SettingsSection({
title,
description,
action,
collapsible,
defaultOpen = true,
danger,
children,
}: Props) {
const titleId = React.useId();
const descriptionNode = description && (
<Description as="p" type="secondary">
{description}
</Description>
);
const rows = <Rows $danger={danger}>{children}</Rows>;
if (!collapsible) {
return (
<Section aria-labelledby={titleId}>
<Header>
<HeaderText>
<Title id={titleId}>{title}</Title>
{descriptionNode}
</HeaderText>
{action}
</Header>
{rows}
</Section>
);
}
return (
<Section aria-labelledby={titleId}>
<Title id={titleId}>{title}</Title>
{description && (
<Description as="p" type="secondary">
{description}
</Description>
)}
<Rows $danger={danger}>{children}</Rows>
</Section>
<RadixCollapsible.Root asChild defaultOpen={defaultOpen}>
<Section aria-labelledby={titleId}>
<Header>
<HeaderText>
<Title>
<Trigger id={titleId}>
{title}
<DisclosureIcon aria-hidden="true" />
</Trigger>
</Title>
{descriptionNode}
</HeaderText>
{action}
</Header>
<Content>{rows}</Content>
</Section>
</RadixCollapsible.Root>
);
}
@@ -48,6 +90,23 @@ const Section = styled.section`
${breakpoint("tablet")`
margin-top: 48px;
`}
/* Less space after a collapsed section. */
&[data-state="closed"] + & {
margin-top: 24px;
}
`;
const Header = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
`;
const HeaderText = styled.div`
flex: 1;
min-width: 0;
`;
const Title = styled.h2`
@@ -56,6 +115,40 @@ const Title = styled.h2`
margin: 0;
`;
const DisclosureIcon = styled(ExpandedIcon)`
flex-shrink: 0;
color: ${s("textTertiary")};
transition: transform 150ms ease-out;
`;
const Trigger = styled(RadixCollapsible.Trigger)`
display: inline-flex;
align-items: center;
gap: 2px;
padding: 0;
border: 0;
background: none;
color: inherit;
font: inherit;
cursor: var(--pointer);
&:hover ${DisclosureIcon} {
color: ${s("textSecondary")};
}
&[data-state="closed"] ${DisclosureIcon} {
transform: rotate(-90deg);
}
[dir="rtl"] &[data-state="closed"] ${DisclosureIcon} {
transform: rotate(90deg);
}
`;
const Content = styled(CollapsibleContent)`
padding-inline-start: 8px;
`;
const Description = styled(Text)`
margin: 4px 0 8px;
`;
+17 -10
View File
@@ -1520,9 +1520,21 @@
"Quickly transfer your existing documents, pages, and files from other tools and services into {{appName}}. You can also drag and drop any HTML, Markdown, and text documents directly into Collections in the app.": "Quickly transfer your existing documents, pages, and files from other tools and services into {{appName}}. You can also drag and drop any HTML, Markdown, and text documents directly into Collections in the app.",
"Recent imports": "Recent imports",
"Configure a variety of integrations with third-party services.": "Configure a variety of integrations with third-party services.",
"Documents that are published, updated, or shared with you, and access requests": "Documents that are published, updated, or shared with you, and access requests",
"Receive a notification whenever a new document is published": "Receive a notification whenever a new document is published",
"Document updated": "Document updated",
"Receive a notification when a document you are subscribed to is edited": "Receive a notification when a document you are subscribed to is edited",
"Invited to document": "Invited to document",
"Receive a notification when a document is shared with you": "Receive a notification when a document is shared with you",
"Document access requested": "Document access requested",
"Receive a notification when a user requests access to a document you manage": "Receive a notification when a user requests access to a document you manage",
"New collections and access to collections": "New collections and access to collections",
"Collection created": "Collection created",
"Receive a notification whenever a new collection is created": "Receive a notification whenever a new collection is created",
"Invited to collection": "Invited to collection",
"Receive a notification when you are given access to a collection": "Receive a notification when you are given access to a collection",
"Comments and mentions": "Comments and mentions",
"New comments, mentions of you or your groups, resolved threads, and reactions": "New comments, mentions of you or your groups, resolved threads, and reactions",
"Comment posted": "Comment posted",
"Receive a notification when a document you are subscribed to or a thread you participated in receives a comment": "Receive a notification when a document you are subscribed to or a thread you participated in receives a comment",
"Mentioned": "Mentioned",
@@ -1532,20 +1544,15 @@
"Receive a notification when a comment thread you were involved in is resolved": "Receive a notification when a comment thread you were involved in is resolved",
"Reaction added": "Reaction added",
"Receive a notification when someone reacts to your comment": "Receive a notification when someone reacts to your comment",
"Collection created": "Collection created",
"Receive a notification whenever a new collection is created": "Receive a notification whenever a new collection is created",
"Invite accepted": "Invite accepted",
"Receive a notification when someone you invited creates an account": "Receive a notification when someone you invited creates an account",
"Invited to document": "Invited to document",
"Receive a notification when a document is shared with you": "Receive a notification when a document is shared with you",
"Invited to collection": "Invited to collection",
"Receive a notification when you are given access to a collection": "Receive a notification when you are given access to a collection",
"Group membership, accepted invites, and completed exports": "Group membership, accepted invites, and completed exports",
"Group membership": "Group membership",
"Receive a notification when you are added to or removed from a group": "Receive a notification when you are added to or removed from a group",
"Invite accepted": "Invite accepted",
"Receive a notification when someone you invited creates an account": "Receive a notification when someone you invited creates an account",
"Export completed": "Export completed",
"Receive a notification when an export you requested has been completed": "Receive a notification when an export you requested has been completed",
"Document access requested": "Document access requested",
"Receive a notification when a user requests access to a document you manage": "Receive a notification when a user requests access to a document you manage",
"Product updates": "Product updates",
"Tips on getting started and announcements of new features": "Tips on getting started and announcements of new features",
"Getting started": "Getting started",
"Tips on getting started with features and functionality": "Tips on getting started with features and functionality",
"New features": "New features",