Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(calendar): fold the calendar side list into per-account groups (#6179)
gbirmand5127e9f0082
diff --git a/.sqlx/query-a719bf46d870e38584b8bb521f731b94a10967f9d9c657f930096dcd1ecdc6a7.json b/.sqlx/query-009679f4874d10c31d6588e31dc40bc82c4f6288ed4971117be3aa4dcc1c64b6.jsonsimilarity index 50%rename from .sqlx/query-a719bf46d870e38584b8bb521f731b94a10967f9d9c657f930096dcd1ecdc6a7.jsonrename to .sqlx/query-009679f4874d10c31d6588e31dc40bc82c4f6288ed4971117be3aa4dcc1c64b6.jsonindex b8f0d61d1e..c79d249b36 100644--- a/.sqlx/query-a719bf46d870e38584b8bb521f731b94a10967f9d9c657f930096dcd1ecdc6a7.json+++ b/.sqlx/query-009679f4874d10c31d6588e31dc40bc82c4f6288ed4971117be3aa4dcc1c64b6.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n calendar.id,\n link.id AS email_link_id,\n link.email_address,\n calendar.name,\n calendar.color,\n calendar.is_primary,\n calendar.access_role,\n calendar.default_reminders\n FROM email_links link\n JOIN calendar_accounts account ON account.email_link_id = link.id\n JOIN calendars calendar ON calendar.account_id = account.id\n WHERE NOT calendar.is_deleted\n AND account.sync_status <> 'disabled'\n AND (\n link.macro_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links delegation\n WHERE delegation.link_id = link.id\n AND delegation.primary_macro_id = $1\n )\n )\n ORDER BY\n (link.macro_id = $1) DESC,\n link.is_primary DESC,\n link.created_at ASC,\n calendar.is_primary DESC,\n (calendar.access_role IN ('owner', 'writer')) DESC,\n calendar.name ASC\n ",+ "query": "\n SELECT\n calendar.id,\n link.id AS email_link_id,\n link.email_address,\n calendar.name,\n calendar.color,\n calendar.is_primary,\n calendar.access_role,\n calendar.provider_calendar_id,\n calendar.default_reminders\n FROM email_links link\n JOIN calendar_accounts account ON account.email_link_id = link.id\n JOIN calendars calendar ON calendar.account_id = account.id\n WHERE NOT calendar.is_deleted\n AND account.sync_status <> 'disabled'\n AND (\n link.macro_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links delegation\n WHERE delegation.link_id = link.id\n AND delegation.primary_macro_id = $1\n )\n )\n ORDER BY\n (link.macro_id = $1) DESC,\n link.is_primary DESC,\n link.created_at ASC,\n calendar.is_primary DESC,\n (calendar.access_role IN ('owner', 'writer')) DESC,\n calendar.name ASC\n ","describe": {"columns": [{@@ -40,6 +40,11 @@},{"ordinal": 7,+ "name": "provider_calendar_id",+ "type_info": "Text"+ },+ {+ "ordinal": 8,"name": "default_reminders","type_info": "Jsonb"}@@ -57,8 +62,9 @@true,false,true,+ false,false]},- "hash": "a719bf46d870e38584b8bb521f731b94a10967f9d9c657f930096dcd1ecdc6a7"+ "hash": "009679f4874d10c31d6588e31dc40bc82c4f6288ed4971117be3aa4dcc1c64b6"}diff --git a/apps/web/src/components/app/app-sidebar/calendar-sidebar-preview.tsx b/apps/web/src/components/app/app-sidebar/calendar-sidebar-preview.tsxindex e85f87be93..26c4ca6f47 100644--- a/apps/web/src/components/app/app-sidebar/calendar-sidebar-preview.tsx+++ b/apps/web/src/components/app/app-sidebar/calendar-sidebar-preview.tsx@@ -12,6 +12,7 @@ import type {CalendarTimeFormat,} from '@app/features/calendar/types';import { parseLocalDate } from '@app/features/calendar/utils/calendar-date';+import { groupCalendarSourcesByAccount } from '@app/features/calendar/utils/calendar-source-groups';import {formatCalendarTime,getDefaultCalendarTimeFormat,@@ -26,6 +27,7 @@ import CaretRightIcon from '@phosphor/caret-right.svg';import CheckIcon from '@phosphor/check.svg';import GearIcon from '@phosphor/gear.svg';import PlusIcon from '@phosphor/plus.svg';+import RssIcon from '@phosphor/rss.svg';import VideoCameraIcon from '@phosphor/video-camera.svg';import XIcon from '@phosphor/x.svg';import type { CalendarOccurrenceQueryRange } from '@queries/calendar/occurrences';@@ -350,28 +352,58 @@ function PreviewContent(props: { dropdownMount?: HTMLElement }) {depth={4}class="max-h-52 w-56 overflow-y-auto">- <Dropdown.Group>- <For each={sources()}>- {(source) => (+ <For each={groupCalendarSourcesByAccount(sources())}>+ {(group) => (+ <Dropdown.Group><Dropdown.CheckboxItem- checked={isSourceVisible(source.id)}+ checked={group.calendars.every((source) =>+ isSourceVisible(source.id)+ )}closeOnSelect={false}- onChange={(visible) =>- setSourceVisibility(source.id, visible)- }+ onChange={(visible) => {+ for (const source of group.calendars) {+ setSourceVisibility(source.id, visible);+ }+ }}>- <span- aria-hidden="true"- class="size-2.5 shrink-0 rounded-sm"- style={{ 'background-color': source.color }}- />- <span class="min-w-0 flex-1 truncate">- {source.name}+ <span class="min-w-0 flex-1 truncate font-medium">+ {group.emailAddress}</span></Dropdown.CheckboxItem>- )}- </For>- </Dropdown.Group>+ <For each={group.calendars}>+ {(source) => (+ <Dropdown.CheckboxItem+ checked={isSourceVisible(source.id)}+ closeOnSelect={false}+ onChange={(visible) =>+ setSourceVisibility(source.id, visible)+ }+ >+ <span+ aria-hidden="true"+ class="size-2.5 shrink-0 rounded-sm"+ style={{ 'background-color': source.color }}+ />+ <span class="min-w-0 flex-1 truncate">+ {source.name}+ </span>+ <Show when={source.isSubscription}>+ <span+ title="Subscription calendar"+ class="flex shrink-0 text-ink-muted"+ >+ <RssIcon+ class="size-3"+ aria-label="Subscription calendar"+ />+ </span>+ </Show>+ </Dropdown.CheckboxItem>+ )}+ </For>+ </Dropdown.Group>+ )}+ </For></Dropdown.SubContent></Dropdown.Sub>diff --git a/apps/web/src/features/calendar/components/CalendarSettingsDropdown.tsx b/apps/web/src/features/calendar/components/CalendarSettingsDropdown.tsxindex 266c4b89ef..47590df8ca 100644--- a/apps/web/src/features/calendar/components/CalendarSettingsDropdown.tsx+++ b/apps/web/src/features/calendar/components/CalendarSettingsDropdown.tsx@@ -7,6 +7,7 @@ import CaretRightIcon from '@phosphor/caret-right.svg';import CheckIcon from '@phosphor/check.svg';import GearIcon from '@phosphor/gear.svg';import PlusIcon from '@phosphor/plus.svg';+import RssIcon from '@phosphor/rss.svg';import { Button, Checkbox, Dropdown } from '@ui';import { createMemo, createSignal, For, Show } from 'solid-js';import { match } from 'ts-pattern';@@ -15,6 +16,10 @@ import {useCalendarAccounts,} from '../hooks/use-calendar-accounts';import type { CalendarTimeFormat, CalendarWeekStart } from '../types';+import {+ type CalendarAccountGroup,+ groupCalendarSourcesByAccount,+} from '../utils/calendar-source-groups';import { useCalendarView } from './CalendarViewContext';import { MobilePeriodControls } from './PeriodSelector';import {@@ -68,6 +73,22 @@ function createCalendarSettingsControls(isNarrow: () => boolean) {calendarView.setSourceVisibility(sourceId, visible);};+ // The account header checkbox shows or hides every calendar in the group.+ const changeAccountVisibility = (+ group: CalendarAccountGroup,+ visible: boolean+ ) => {+ calendarView.closeEventDetails();+ for (const source of group.calendars) {+ calendarView.setSourceVisibility(source.id, visible);+ }+ };+ const isAccountVisible = (group: CalendarAccountGroup) =>+ group.calendars.every((source) => calendarView.isSourceVisible(source.id));+ const isAccountPartiallyVisible = (group: CalendarAccountGroup) =>+ !isAccountVisible(group) &&+ group.calendars.some((source) => calendarView.isSourceVisible(source.id));+const changeShowWeekends = (showWeekends: boolean) => {calendarView.closeEventDetails();calendarView.setShowWeekends(showWeekends);@@ -117,6 +138,9 @@ function createCalendarSettingsControls(isNarrow: () => boolean) {weekStartLabel,timeFormatLabel,changeSourceVisibility,+ changeAccountVisibility,+ isAccountVisible,+ isAccountPartiallyVisible,changeShowWeekends,changeWeekStartsOn,changeTimeFormat,@@ -151,27 +175,52 @@ function DesktopCalendarSettings(props: {</Dropdown.Trigger><Dropdown.Content class="w-60 max-w-[calc(100vw-1rem)]"><Show when={controls.showCalendarVisibility()}>- <Dropdown.Group>- <Dropdown.GroupLabel>Calendars</Dropdown.GroupLabel>- <For each={calendarView.sources()}>- {(source) => (+ <For each={groupCalendarSourcesByAccount(calendarView.sources())}>+ {(group) => (+ <Dropdown.Group><Dropdown.CheckboxItem- checked={calendarView.isSourceVisible(source.id)}+ checked={controls.isAccountVisible(group)}closeOnSelect={false}onChange={(checked) =>- controls.changeSourceVisibility(source.id, checked)+ controls.changeAccountVisibility(group, checked)}>- <span- aria-hidden="true"- class="size-2.5 shrink-0 rounded-sm"- style={{ 'background-color': source.color }}- />- <span class="min-w-0 flex-1 truncate">{source.name}</span>+ <span class="min-w-0 flex-1 truncate font-medium">+ {group.emailAddress}+ </span></Dropdown.CheckboxItem>- )}- </For>- </Dropdown.Group>+ <For each={group.calendars}>+ {(source) => (+ <Dropdown.CheckboxItem+ checked={calendarView.isSourceVisible(source.id)}+ closeOnSelect={false}+ onChange={(checked) =>+ controls.changeSourceVisibility(source.id, checked)+ }+ >+ <span+ aria-hidden="true"+ class="size-2.5 shrink-0 rounded-sm"+ style={{ 'background-color': source.color }}+ />+ <span class="min-w-0 flex-1 truncate">{source.name}</span>+ <Show when={source.isSubscription}>+ <span+ title="Subscription calendar"+ class="flex shrink-0 text-ink-muted"+ >+ <RssIcon+ class="size-3"+ aria-label="Subscription calendar"+ />+ </span>+ </Show>+ </Dropdown.CheckboxItem>+ )}+ </For>+ </Dropdown.Group>+ )}+ </For></Show><Dropdown.Group>@@ -336,30 +385,61 @@ function MobileCalendarSettings(props: { controls: CalendarSettingsControls }) {<MobilePeriodControls onSelect={() => setOpen(false)} /><Show when={controls.showCalendarVisibility()}>- <MobileDrawer.Label>Calendars</MobileDrawer.Label>- <MobileDrawer.Section class="flex shrink-0 flex-col">- <For each={calendarView.sources()}>- {(source) => (- <Checkbox- checked={calendarView.isSourceVisible(source.id)}- onChange={(checked) =>- controls.changeSourceVisibility(source.id, checked)- }- class={DRAWER_ROW_CLASS}- >- <Checkbox.Label class="flex min-w-0 flex-1 items-center gap-2">- <span- aria-hidden="true"- class="size-2.5 shrink-0 rounded-sm"- style={{ 'background-color': source.color }}- />- <span class="min-w-0 flex-1 truncate">{source.name}</span>- </Checkbox.Label>- <Checkbox.Control />- </Checkbox>- )}- </For>- </MobileDrawer.Section>+ <For each={groupCalendarSourcesByAccount(calendarView.sources())}>+ {(group, index) => (+ <div class={index() > 0 ? 'pt-4' : undefined}>+ <MobileDrawer.Section class="flex shrink-0 flex-col">+ <Checkbox+ checked={controls.isAccountVisible(group)}+ indeterminate={controls.isAccountPartiallyVisible(group)}+ onChange={(checked) =>+ controls.changeAccountVisibility(group, checked)+ }+ class={DRAWER_ROW_CLASS}+ >+ <Checkbox.Label class="min-w-0 flex-1 truncate font-medium">+ {group.emailAddress}+ </Checkbox.Label>+ <Checkbox.Control />+ </Checkbox>+ <For each={group.calendars}>+ {(source) => (+ <Checkbox+ checked={calendarView.isSourceVisible(source.id)}+ onChange={(checked) =>+ controls.changeSourceVisibility(source.id, checked)+ }+ class={DRAWER_ROW_CLASS}+ >+ <Checkbox.Label class="flex min-w-0 flex-1 items-center gap-2">+ <span+ aria-hidden="true"+ class="size-2.5 shrink-0 rounded-sm"+ style={{ 'background-color': source.color }}+ />+ <span class="min-w-0 flex-1 truncate">+ {source.name}+ </span>+ <Show when={source.isSubscription}>+ <span+ title="Subscription calendar"+ class="flex shrink-0 text-ink-muted"+ >+ <RssIcon+ class="size-4"+ aria-label="Subscription calendar"+ />+ </span>+ </Show>+ </Checkbox.Label>+ <Checkbox.Control />+ </Checkbox>+ )}+ </For>+ </MobileDrawer.Section>+ </div>+ )}+ </For><div class="mt-4" /></Show>diff --git a/apps/web/src/features/calendar/components/SourceControls.test.tsx b/apps/web/src/features/calendar/components/SourceControls.test.tsxindex 54a132899a..46fe0fdf4b 100644--- a/apps/web/src/features/calendar/components/SourceControls.test.tsx+++ b/apps/web/src/features/calendar/components/SourceControls.test.tsx@@ -2,44 +2,119 @@* @vitest-environment jsdom*/-import { fireEvent, render } from '@solidjs/testing-library';+import { fireEvent, render, within } from '@solidjs/testing-library';import { createSignal } from 'solid-js';import { describe, expect, it, vi } from 'vitest';+import type { CalendarSource } from '../types';import { SourceControls } from './SourceControls';+const SOURCES: CalendarSource[] = [+ {+ id: 'gab-primary',+ name: '[email protected]',+ color: '#ff0000',+ emailAddress: '[email protected]',+ emailLinkId: 'link-gab',+ isPrimary: true,+ },+ {+ id: 'gab-holidays',+ name: 'Holidays in United States',+ color: '#00ff00',+ emailAddress: '[email protected]',+ emailLinkId: 'link-gab',+ isSubscription: true,+ },+ {+ id: 'test-primary',+ name: '[email protected]',+ color: '#0000ff',+ emailAddress: '[email protected]',+ emailLinkId: 'link-test',+ isPrimary: true,+ },+];+function renderControls() {const onVisibilityChange = vi.fn<(id: string, visible: boolean) => void>();- const [visible, setVisible] = createSignal(true);- const { container } = render(() => (+ const [hidden, setHidden] = createSignal<ReadonlySet<string>>(new Set());+ const result = render(() => (<SourceControls- sources={[{ id: 'cal-1', name: '[email protected]', color: '#ff0000' }]}- isVisible={() => visible()}- onVisibilityChange={(id, next) => {- onVisibilityChange(id, next);- setVisible(next);+ sources={SOURCES}+ isVisible={(id) => !hidden().has(id)}+ onVisibilityChange={(id, visible) => {+ onVisibilityChange(id, visible);+ setHidden((current) => {+ const next = new Set(current);+ if (visible) next.delete(id);+ else next.add(id);+ return next;+ });}}/>));- const query = (selector: string) => {- const element = container.querySelector(selector);- if (!element) throw new Error(`missing ${selector}`);- return element;+ const expandAccount = (email: string) =>+ fireEvent.click(result.getByRole('button', { name: `Expand ${email}` }));+ const headerFor = (email: string) => {+ // Works whether the group is currently collapsed or expanded.+ const caret =+ result.queryByRole('button', { name: `Collapse ${email}` }) ??+ result.getByRole('button', { name: `Expand ${email}` });+ const header = caret.parentElement;+ if (!header) throw new Error(`missing header for ${email}`);+ return header;};- return { query, onVisibilityChange, visible };+ return { ...result, onVisibilityChange, headerFor, expandAccount };}describe('SourceControls', () => {- it('toggles when the source name is clicked', () => {- const { query, onVisibilityChange, visible } = renderControls();- fireEvent.click(query('label'));- expect(onVisibilityChange).toHaveBeenCalledWith('cal-1', false);- expect(visible()).toBe(false);+ it('folds each account collapsed by default', () => {+ const { getByRole, queryByText } = renderControls();+ // Every account renders a collapse control, but its calendars stay hidden.+ expect(getByRole('button', { name: 'Expand [email protected]' })).toBeTruthy();+ expect(+ getByRole('button', { name: 'Expand [email protected]' })+ ).toBeTruthy();+ expect(queryByText('Holidays in United States')).toBeNull();+ });++ it('reveals an account calendars once expanded', () => {+ const { expandAccount, getByText } = renderControls();+ expandAccount('[email protected]');+ expect(getByText('Holidays in United States')).toBeTruthy();+ });++ it('toggles a single calendar when its row is clicked', () => {+ const { expandAccount, getByText, onVisibilityChange } = renderControls();+ expandAccount('[email protected]');+ fireEvent.click(getByText('Holidays in United States'));+ expect(onVisibilityChange).toHaveBeenCalledWith('gab-holidays', false);+ });++ it('toggles every calendar in an account from its header checkbox', () => {+ const { headerFor, onVisibilityChange } = renderControls();+ // The header checkbox works while the group is still folded.+ fireEvent.click(+ within(headerFor('[email protected]')).getByText('[email protected]')+ );+ expect(onVisibilityChange).toHaveBeenCalledWith('gab-primary', false);+ expect(onVisibilityChange).toHaveBeenCalledWith('gab-holidays', false);+ });++ it('marks a subscription calendar with an indicator', () => {+ const { expandAccount, container } = renderControls();+ expandAccount('[email protected]');+ const indicators = container.querySelectorAll(+ '[title="Subscription calendar"]'+ );+ expect(indicators).toHaveLength(1);});- it('toggles when the checkbox control is clicked', () => {- const { query, onVisibilityChange, visible } = renderControls();- fireEvent.click(query('[id$="-control"]'));- expect(onVisibilityChange).toHaveBeenCalledWith('cal-1', false);- expect(visible()).toBe(false);+ it('collapses an account again to hide its calendars', () => {+ const { expandAccount, getByRole, queryByText } = renderControls();+ expandAccount('[email protected]');+ expect(queryByText('Holidays in United States')).toBeTruthy();+ fireEvent.click(getByRole('button', { name: 'Collapse [email protected]' }));+ expect(queryByText('Holidays in United States')).toBeNull();});});diff --git a/apps/web/src/features/calendar/components/SourceControls.tsx b/apps/web/src/features/calendar/components/SourceControls.tsxindex d32d8fd683..2bc268bcbc 100644--- a/apps/web/src/features/calendar/components/SourceControls.tsx+++ b/apps/web/src/features/calendar/components/SourceControls.tsx@@ -1,6 +1,9 @@+import CaretRightIcon from '@phosphor/caret-right.svg';+import RssIcon from '@phosphor/rss.svg';import { Checkbox } from '@ui';-import { For } from 'solid-js';+import { createSignal, For, Show } from 'solid-js';import type { CalendarSource } from '../types';+import { groupCalendarSourcesByAccount } from '../utils/calendar-source-groups';interface SourceControlsProps {sources: CalendarSource[];@@ -8,28 +11,113 @@ interface SourceControlsProps {onVisibilityChange: (sourceId: string, visible: boolean) => void;}-/** Controls which calendar sources are visible in the calendar. */+/**+ * Controls which calendar sources are visible, folded under a collapsible+ * header per connected account. The header checkbox shows or hides all of the+ * account's calendars at once.+ */export function SourceControls(props: SourceControlsProps) {+ const groups = () => groupCalendarSourcesByAccount(props.sources);+ // Accounts start folded; expanding one only reveals its calendars, which+ // stay visible on the grid whether or not the group is expanded.+ const [expandedKeys, setExpandedKeys] = createSignal<ReadonlySet<string>>(+ new Set()+ );+ const toggleExpanded = (key: string) =>+ setExpandedKeys((current) => {+ const next = new Set(current);+ if (next.has(key)) next.delete(key);+ else next.add(key);+ return next;+ });+return (<div class="flex flex-col gap-0.5">- <For each={props.sources}>- {(source) => (- <Checkbox- checked={props.isVisible(source.id)}- onChange={(checked) => props.onVisibilityChange(source.id, checked)}- class="flex w-full items-center rounded-lg px-2 py-1.5 text-xs text-ink hover:bg-hover"- >- <Checkbox.Label class="flex min-w-0 flex-1 items-center gap-2">- <span- aria-hidden="true"- class="size-2.5 shrink-0 rounded-sm"- style={{ 'background-color': source.color }}- />- <span class="min-w-0 flex-1 truncate">{source.name}</span>- </Checkbox.Label>- <Checkbox.Control />- </Checkbox>- )}+ <For each={groups()}>+ {(group) => {+ const visibleCount = () =>+ group.calendars.filter((calendar) => props.isVisible(calendar.id))+ .length;+ const allVisible = () => visibleCount() === group.calendars.length;+ const someVisible = () => visibleCount() > 0 && !allVisible();+ const expanded = () => expandedKeys().has(group.key);+ const setGroupVisible = (visible: boolean) => {+ for (const calendar of group.calendars) {+ props.onVisibilityChange(calendar.id, visible);+ }+ };++ return (+ <div class="flex flex-col">+ <div class="flex w-full items-center rounded-lg pr-2 text-xs text-ink hover:bg-hover">+ <button+ type="button"+ class="flex shrink-0 items-center justify-center rounded-md p-1 text-ink-muted hover:text-ink"+ aria-label={+ expanded()+ ? `Collapse ${group.emailAddress}`+ : `Expand ${group.emailAddress}`+ }+ aria-expanded={expanded()}+ onClick={() => toggleExpanded(group.key)}+ >+ <CaretRightIcon+ class="size-3 transition-transform duration-90"+ classList={{ 'rotate-90': expanded() }}+ />+ </button>+ <Checkbox+ checked={allVisible()}+ indeterminate={someVisible()}+ onChange={setGroupVisible}+ class="flex min-w-0 flex-1 items-center py-1.5"+ >+ <Checkbox.Label class="min-w-0 flex-1 truncate font-medium">+ {group.emailAddress}+ </Checkbox.Label>+ <Checkbox.Control />+ </Checkbox>+ </div>++ <Show when={expanded()}>+ <For each={group.calendars}>+ {(source) => (+ <Checkbox+ checked={props.isVisible(source.id)}+ onChange={(checked) =>+ props.onVisibilityChange(source.id, checked)+ }+ class="flex w-full items-center rounded-lg py-1.5 pr-2 pl-7 text-xs text-ink hover:bg-hover"+ >+ <Checkbox.Label class="flex min-w-0 flex-1 items-center gap-2">+ <span+ aria-hidden="true"+ class="size-2.5 shrink-0 rounded-sm"+ style={{ 'background-color': source.color }}+ />+ <span class="min-w-0 flex-1 truncate">+ {source.name}+ </span>+ <Show when={source.isSubscription}>+ <span+ title="Subscription calendar"+ class="flex shrink-0 text-ink-muted"+ >+ <RssIcon+ class="size-3"+ aria-label="Subscription calendar"+ />+ </span>+ </Show>+ </Checkbox.Label>+ <Checkbox.Control />+ </Checkbox>+ )}+ </For>+ </Show>+ </div>+ );+ }}</For></div>);diff --git a/apps/web/src/features/calendar/hooks/use-calendar-sources.ts b/apps/web/src/features/calendar/hooks/use-calendar-sources.tsindex ab87c230a7..346d66355c 100644--- a/apps/web/src/features/calendar/hooks/use-calendar-sources.ts+++ b/apps/web/src/features/calendar/hooks/use-calendar-sources.ts@@ -2,12 +2,8 @@ import { useVisibleCalendarsQuery } from '@queries/calendar/calendars';import { createMemo } from 'solid-js';import type { CalendarSource } from '../types';import { DEFAULT_CALENDAR_SOURCE } from '../types';-import {- calendarDisplayLabel,- spansMultipleInboxes,-} from '../utils/calendar-label';-/** Query-backed calendar sources with presentation labels and colors. */+/** Query-backed calendar sources with presentation colors, grouped by account. */export function useCalendarSources() {const calendarsQuery = useVisibleCalendarsQuery();const sources = createMemo<CalendarSource[]>(() => {@@ -16,13 +12,14 @@ export function useCalendarSources() {return [DEFAULT_CALENDAR_SOURCE];}- const spansInboxes = spansMultipleInboxes(calendars);return calendars.map((calendar) => ({id: calendar.id,- name: calendarDisplayLabel(calendar, spansInboxes),+ name: calendar.name,color: calendar.color ?? DEFAULT_CALENDAR_SOURCE.color,emailAddress: calendar.emailAddress,+ emailLinkId: calendar.emailLinkId,isPrimary: calendar.isPrimary,+ isSubscription: calendar.isSubscription,}));});const sourceById = createMemo(diff --git a/apps/web/src/features/calendar/types.ts b/apps/web/src/features/calendar/types.tsindex 526ec3a06e..a355e05701 100644--- a/apps/web/src/features/calendar/types.ts+++ b/apps/web/src/features/calendar/types.ts@@ -31,8 +31,12 @@ export interface CalendarSource {color: string;/** Connected inbox address, when the source came from a visible calendar. */emailAddress?: string;+ /** Connected inbox link that syncs this calendar, for grouping by account. */+ emailLinkId?: string;/** Whether this source is its connected inbox's primary calendar. */isPrimary?: boolean;+ /** Whether this is a subscribed system calendar (holidays, birthdays). */+ isSubscription?: boolean;}/** Calendar occurrence data, independent from FullCalendar. */diff --git a/apps/web/src/features/calendar/utils/calendar-source-groups.test.ts b/apps/web/src/features/calendar/utils/calendar-source-groups.test.tsnew file mode 100644index 0000000000..e9d6c35064--- /dev/null+++ b/apps/web/src/features/calendar/utils/calendar-source-groups.test.ts@@ -0,0 +1,53 @@+import { describe, expect, it } from 'vitest';+import type { CalendarSource } from '../types';+import { groupCalendarSourcesByAccount } from './calendar-source-groups';++const source = (overrides: Partial<CalendarSource>): CalendarSource => ({+ id: 'cal',+ name: 'Calendar',+ color: '#000',+ ...overrides,+});++describe('groupCalendarSourcesByAccount', () => {+ it('folds calendars into one group per account, keeping source order', () => {+ const groups = groupCalendarSourcesByAccount([+ source({ id: 'a1', emailLinkId: 'link-a', emailAddress: '[email protected]' }),+ source({ id: 'b1', emailLinkId: 'link-b', emailAddress: '[email protected]' }),+ source({ id: 'a2', emailLinkId: 'link-a', emailAddress: '[email protected]' }),+ ]);++ expect(groups).toHaveLength(2);+ expect(groups[0]?.emailAddress).toBe('[email protected]');+ expect(groups[0]?.calendars.map((c) => c.id)).toEqual(['a1', 'a2']);+ expect(groups[1]?.emailAddress).toBe('[email protected]');+ expect(groups[1]?.calendars.map((c) => c.id)).toEqual(['b1']);+ });++ it('groups by email link even when addresses collide', () => {+ const groups = groupCalendarSourcesByAccount([+ source({+ id: 'own',+ emailLinkId: 'link-own',+ emailAddress: '[email protected]',+ }),+ source({+ id: 'delegated',+ emailLinkId: 'link-delegated',+ emailAddress: '[email protected]',+ }),+ ]);++ expect(groups.map((g) => g.key)).toEqual(['link-own', 'link-delegated']);+ });++ it('falls back to the source name for a group without an address', () => {+ const groups = groupCalendarSourcesByAccount([+ source({ id: 'calendar', name: 'Calendar' }),+ ]);++ expect(groups).toHaveLength(1);+ expect(groups[0]?.key).toBe('calendar');+ expect(groups[0]?.emailAddress).toBe('Calendar');+ });+});diff --git a/apps/web/src/features/calendar/utils/calendar-source-groups.ts b/apps/web/src/features/calendar/utils/calendar-source-groups.tsnew file mode 100644index 0000000000..b7220d212d--- /dev/null+++ b/apps/web/src/features/calendar/utils/calendar-source-groups.ts@@ -0,0 +1,40 @@+import type { CalendarSource } from '../types';++/** A connected account and the calendars synced from it, for folded pickers. */+export interface CalendarAccountGroup {+ /** Stable grouping key — the inbox link, falling back to its address. */+ key: string;+ /** Connected inbox address shown as the group header. */+ emailAddress: string;+ /** The account's calendars, in the order the source list presented them. */+ calendars: CalendarSource[];+}++/**+ * Folds a flat calendar source list into per-account groups, preserving the+ * source order so primaries and writable calendars stay first within an+ * account and the query's account ordering is kept.+ */+export function groupCalendarSourcesByAccount(+ sources: readonly CalendarSource[]+): CalendarAccountGroup[] {+ const groups: CalendarAccountGroup[] = [];+ const byKey = new Map<string, CalendarAccountGroup>();++ for (const source of sources) {+ const key = source.emailLinkId ?? source.emailAddress ?? source.id;+ let group = byKey.get(key);+ if (!group) {+ group = {+ key,+ emailAddress: source.emailAddress ?? source.name,+ calendars: [],+ };+ byKey.set(key, group);+ groups.push(group);+ }+ group.calendars.push(source);+ }++ return groups;+}diff --git a/apps/web/src/lib/service-clients/service-email/generated/schemas/visibleCalendar.ts b/apps/web/src/lib/service-clients/service-email/generated/schemas/visibleCalendar.tsindex 1042f55b34..13f5946bb5 100644--- a/apps/web/src/lib/service-clients/service-email/generated/schemas/visibleCalendar.ts+++ b/apps/web/src/lib/service-clients/service-email/generated/schemas/visibleCalendar.ts@@ -24,6 +24,9 @@ export interface VisibleCalendar {id: string;/** Whether this is its account's primary calendar. */isPrimary: boolean;+ /** Whether this is one of Google's shared system calendars (holidays,+birthdays) the account subscribes to rather than one a person maintains. */+ isSubscription: boolean;/** Whether the grant can create and modify events on this calendar. */isWritable: boolean;/** Provider display name. */diff --git a/apps/web/src/lib/service-clients/service-email/openapi.json b/apps/web/src/lib/service-clients/service-email/openapi.jsonindex 7fffc2f2bf..6c820b6d9a 100644--- a/apps/web/src/lib/service-clients/service-email/openapi.json+++ b/apps/web/src/lib/service-clients/service-email/openapi.json@@ -6433,6 +6433,7 @@"name","isPrimary","isWritable",+ "isSubscription","defaultReminders"],"properties": {@@ -6465,6 +6466,10 @@"type": "boolean","description": "Whether this is its account's primary calendar."},+ "isSubscription": {+ "type": "boolean",+ "description": "Whether this is one of Google's shared system calendars (holidays,\nbirthdays) the account subscribes to rather than one a person maintains."+ },"isWritable": {"type": "boolean","description": "Whether the grant can create and modify events on this calendar."diff --git a/crates/calendar_events/src/domain/models.rs b/crates/calendar_events/src/domain/models.rsindex 6d30875e7b..138b39643f 100644--- a/crates/calendar_events/src/domain/models.rs+++ b/crates/calendar_events/src/domain/models.rs@@ -1036,6 +1036,9 @@ pub struct VisibleCalendar {pub is_primary: bool,/// Whether the grant can create and modify events on this calendar.pub is_writable: bool,+ /// Whether this is one of Google's shared system calendars (holidays,+ /// birthdays) the account subscribes to rather than one a person maintains.+ pub is_subscription: bool,/// Default reminders applied to events that keep `useDefault`.pub default_reminders: Vec<EventReminderOverride>,}diff --git a/crates/calendar_events/src/inbound/toolset/test.rs b/crates/calendar_events/src/inbound/toolset/test.rsindex f92c2f3c37..aa312c285f 100644--- a/crates/calendar_events/src/inbound/toolset/test.rs+++ b/crates/calendar_events/src/inbound/toolset/test.rs@@ -848,6 +848,7 @@ async fn list_calendars_maps_visible_calendars() {color: None,is_primary: true,is_writable: true,+ is_subscription: false,default_reminders: Vec::new(),}]),..Default::default()diff --git a/crates/calendar_events/src/outbound/pg.rs b/crates/calendar_events/src/outbound/pg.rsindex 8fc767f3e8..4ebd0fad2f 100644--- a/crates/calendar_events/src/outbound/pg.rs+++ b/crates/calendar_events/src/outbound/pg.rs@@ -22,7 +22,7 @@ use crate::domain::{EventReminders, EventStart, EventStatus, EventTime, EventTransparency, EventType,EventVisibility, GOOGLE_CALENDAR_SCOPES, GoogleCalendarSyncSnapshot, GoogleScopeSet,GoogleWatchChannel, OccurrenceRange, ProviderCalendar, StoredGoogleCalendar,- TeamOutOfOffice, VisibleCalendar,+ TeamOutOfOffice, VisibleCalendar, is_system_calendar,},ports::{CalendarBackfillRepository, CalendarEventChange, CalendarEventWrite,@@ -1818,6 +1818,7 @@ impl CalendarRepository for PgCalendarRepository {calendar.color,calendar.is_primary,calendar.access_role,+ calendar.provider_calendar_id,calendar.default_remindersFROM email_links linkJOIN calendar_accounts account ON account.email_link_id = link.id@@ -1856,6 +1857,7 @@ impl CalendarRepository for PgCalendarRepository {color: row.color,is_primary: row.is_primary,is_writable: matches!(row.access_role.as_deref(), Some("owner" | "writer")),+ is_subscription: is_system_calendar(&row.provider_calendar_id),default_reminders: serde_json::from_value(row.default_reminders).inspect_err(|e| {tracing::error!(error = ?e, calendar_id = %row.id, "malformed calendar default_reminders json");diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.mdindex e33d94cfb5..3f7edfd47a 100644--- a/docs/AGENT_GUIDE/surfaces.md+++ b/docs/AGENT_GUIDE/surfaces.md@@ -38,6 +38,12 @@ section listing each connected account with a per-account `Enable` (grant calend`Turn off` action, plus `Connect another account` to connect a new Google account(email + calendar).+The side panel's `Calendars` section folds each connected account into a collapsible+group: a caret plus the account address header with a checkbox that shows or hides all of+that account's calendars at once, and the account's calendars listed beneath it (color dot,+name, per-calendar checkbox). Subscribed system calendars (Google holidays, birthdays)+carry a small RSS icon.+Teammates' Google Calendar out-of-office events overlay the grid as read-only chips titled`<name>: <event title>`. The side panel's `Team out of office` section (shown only when theuser belongs to a team with other members) has a checkbox in its header row toggling thediff --git a/packages/sdk/generated/email/types.gen.ts b/packages/sdk/generated/email/types.gen.tsindex ca15e8907a..95881a5e69 100644--- a/packages/sdk/generated/email/types.gen.ts+++ b/packages/sdk/generated/email/types.gen.ts@@ -1605,6 +1605,11 @@ export type VisibleCalendar = {* Whether this is its account's primary calendar.*/isPrimary: boolean;+ /**+ * Whether this is one of Google's shared system calendars (holidays,+ * birthdays) the account subscribes to rather than one a person maintains.+ */+ isSubscription: boolean;/*** Whether the grant can create and modify events on this calendar.*/diff --git a/packages/sdk/specs/email.json b/packages/sdk/specs/email.jsonindex 7fffc2f2bf..6c820b6d9a 100644--- a/packages/sdk/specs/email.json+++ b/packages/sdk/specs/email.json@@ -6433,6 +6433,7 @@"name","isPrimary","isWritable",+ "isSubscription","defaultReminders"],"properties": {@@ -6465,6 +6466,10 @@"type": "boolean","description": "Whether this is its account's primary calendar."},+ "isSubscription": {+ "type": "boolean",+ "description": "Whether this is one of Google's shared system calendars (holidays,\nbirthdays) the account subscribes to rather than one a person maintains."+ },"isWritable": {"type": "boolean","description": "Whether the grant can create and modify events on this calendar."