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
fix(calendar): expand the team out of office list from +N more (#9194)
gbirman094722eea77a
diff --git a/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx b/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsxindex 2c8c187cd9..f866491a15 100644--- a/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx+++ b/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx@@ -11,9 +11,10 @@ import {useQueries,useQueryClient,} from '@tanstack/solid-query';+import userEvent from '@testing-library/user-event';import { addDays, format } from 'date-fns';import { createSignal } from 'solid-js';-import { afterEach, describe, expect, it, vi } from 'vitest';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { TeamOooUpcomingList } from './CalendarSidebar';const requests = vi.hoisted(() => ({@@ -24,7 +25,10 @@ vi.mock('@core/context/user', () => ({useUserId: () => () => 'macro|[email protected]',}));vi.mock('@core/user', () => ({- getDisplayName: () => 'Jackson Kustec',+ getDisplayName: (id: string) =>+ id === 'macro|[email protected]'+ ? 'Jackson Kustec'+ : `Teammate ${id.slice('macro|teammate-'.length, id.indexOf('@'))}`,tryMacroId: (id: string) => id,}));vi.mock('@core/component/UserIcon', () => ({@@ -44,12 +48,24 @@ vi.mock('@queries/calendar/team-ooo', () => ({}));const [selectedEvent, setSelectedEvent] = createSignal<CalendarEvent>();-const selectEvent = vi.fn((event: CalendarEvent, _anchor: HTMLElement) =>- setSelectedEvent(event)-);+const [selectedEventAnchor, setSelectedEventAnchor] =+ createSignal<HTMLElement>();+const selectEvent = vi.fn((event: CalendarEvent, anchor: HTMLElement) => {+ setSelectedEvent(event);+ setSelectedEventAnchor(anchor);+});+const closeEventDetails = vi.fn(() => {+ setSelectedEvent(undefined);+ setSelectedEventAnchor(undefined);+});vi.mock('@app/features/calendar/components/CalendarViewContext', () => ({- useCalendarView: () => ({ selectedEvent, selectEvent }),+ useCalendarView: () => ({+ selectedEvent,+ selectedEventAnchor,+ selectEvent,+ closeEventDetails,+ }),}));vi.mock('@app/features/calendar/components/CalendarPagerContext', () => ({useCalendarPager: () => ({ gotoDate: vi.fn() }),@@ -58,42 +74,62 @@ vi.mock('@app/components/view-shell', () => ({useViewShell: () => ({ aside: { isOverlay: () => false } }),}));-function teamOooItems(): TeamOutOfOfficeItem[] {- const day = format(addDays(new Date(), 28), 'yyyy-MM-dd');- const nextDay = format(addDays(new Date(), 29), 'yyyy-MM-dd');- return [- {- eventId: 'ooo-1',+/** One all-day absence per person, on consecutive days four weeks out. */+function teamOooItems(count = 1): TeamOutOfOfficeItem[] {+ return Array.from({ length: count }, (_, index) => {+ const day = format(addDays(new Date(), 28 + index), 'yyyy-MM-dd');+ const nextDay = format(addDays(new Date(), 29 + index), 'yyyy-MM-dd');+ return {+ eventId: `ooo-${index + 1}`,occurrenceKey: day,- ownerId: 'macro|[email protected]',+ ownerId:+ index === 0+ ? 'macro|[email protected]'+ : `macro|teammate-${index + 1}@macro.com`,time: { kind: 'allDay', startDate: day, endDate: nextDay },- },- ];+ };+ });+}++function renderList() {+ const client = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ let refetch!: () => Promise<unknown>;+ function Harness() {+ const queryClient = useQueryClient();+ refetch = () => queryClient.refetchQueries({ queryKey: ['team-ooo'] });+ return <TeamOooUpcomingList />;+ }+ render(() => (+ <QueryClientProvider client={client}>+ <Harness />+ </QueryClientProvider>+ ));+ return { refetch: () => refetch() };}+const rows = () =>+ screen.queryAllByRole('button', { name: /^(Jackson Kustec|Teammate \d+)/ });+const toggle = () =>+ screen.queryByRole('button', { name: /more$|^Show less$/ });++const scrollIntoView = vi.fn();+beforeEach(() => {+ Element.prototype.scrollIntoView = scrollIntoView;+});+afterEach(() => {cleanup();setSelectedEvent(undefined);+ setSelectedEventAnchor(undefined);vi.clearAllMocks();});describe('TeamOooUpcomingList', () => {it('keeps the selected row attached when the poll refetches', async () => {requests.teamOoo.mockImplementation(async () => teamOooItems());- const client = new QueryClient({- defaultOptions: { queries: { retry: false } },- });- let refetch!: () => Promise<unknown>;- function Harness() {- const queryClient = useQueryClient();- refetch = () => queryClient.refetchQueries({ queryKey: ['team-ooo'] });- return <TeamOooUpcomingList />;- }- render(() => (- <QueryClientProvider client={client}>- <Harness />- </QueryClientProvider>- ));+ const { refetch } = renderList();fireEvent.click(await screen.findByRole('button', { name: /Jackson/ }));const anchor = selectEvent.mock.calls[0][1];@@ -106,4 +142,124 @@ describe('TeamOooUpcomingList', () => {expect(screen.getByRole('button', { name: /Jackson/ })).toBe(anchor);expect(anchor.isConnected).toBe(true);});++ it('shows ten rows and the rest behind a "+N more" toggle', async () => {+ requests.teamOoo.mockImplementation(async () => teamOooItems(15));+ renderList();++ await screen.findByRole('button', { name: /Jackson/ });++ expect(rows()).toHaveLength(10);+ expect(toggle()?.textContent).toBe('+5 more');+ expect(toggle()?.getAttribute('aria-expanded')).toBe('false');+ });++ it('expands to every row and collapses again', async () => {+ const user = userEvent.setup();+ requests.teamOoo.mockImplementation(async () => teamOooItems(15));+ renderList();+ await screen.findByRole('button', { name: /Jackson/ });+ const control = toggle();+ if (!control) throw new Error('missing "+N more" toggle');++ await user.click(control);++ expect(rows()).toHaveLength(15);+ expect(toggle()).toBe(control);+ expect(control.textContent).toBe('Show less');+ expect(control.getAttribute('aria-expanded')).toBe('true');+ expect(scrollIntoView.mock.contexts.at(-1)).toBe(control);++ await user.click(control);++ expect(rows()).toHaveLength(10);+ expect(control.textContent).toBe('+5 more');+ expect(control.getAttribute('aria-expanded')).toBe('false');+ expect(document.activeElement).toBe(control);+ });++ it('opens a row past the tenth from the expanded list', async () => {+ const user = userEvent.setup();+ requests.teamOoo.mockImplementation(async () => teamOooItems(15));+ renderList();+ await screen.findByRole('button', { name: /Jackson/ });++ await user.click(screen.getByRole('button', { name: '+5 more' }));+ const row = screen.getByRole('button', { name: /^Teammate 14/ });+ await user.click(row);++ expect(selectEvent).toHaveBeenCalledTimes(1);+ expect(selectEvent.mock.calls[0][1]).toBe(row);+ expect(row.getAttribute('aria-current')).toBe('true');+ });++ it('closes the details when Show less removes their row', async () => {+ const user = userEvent.setup();+ requests.teamOoo.mockImplementation(async () => teamOooItems(15));+ renderList();+ await screen.findByRole('button', { name: /Jackson/ });+ await user.click(screen.getByRole('button', { name: '+5 more' }));+ fireEvent.click(screen.getByRole('button', { name: /^Teammate 14/ }));++ screen.getByRole('button', { name: 'Show less' }).focus();+ await user.keyboard('{Enter}');++ expect(rows()).toHaveLength(10);+ expect(closeEventDetails).toHaveBeenCalledTimes(1);+ });++ it('keeps the details open when Show less keeps their row', async () => {+ const user = userEvent.setup();+ requests.teamOoo.mockImplementation(async () => teamOooItems(15));+ renderList();+ await user.click(await screen.findByRole('button', { name: '+5 more' }));+ fireEvent.click(screen.getByRole('button', { name: /^Teammate 3/ }));++ screen.getByRole('button', { name: 'Show less' }).focus();+ await user.keyboard('{Enter}');++ expect(rows()).toHaveLength(10);+ expect(closeEventDetails).not.toHaveBeenCalled();+ });++ it('stays expanded when the poll refetches', async () => {+ const user = userEvent.setup();+ requests.teamOoo.mockImplementation(async () => teamOooItems(15));+ const { refetch } = renderList();+ await screen.findByRole('button', { name: /Jackson/ });+ await user.click(screen.getByRole('button', { name: '+5 more' }));++ await refetch();++ expect(rows()).toHaveLength(15);+ expect(toggle()?.textContent).toBe('Show less');+ });++ it('follows count changes and keeps the expanded choice', async () => {+ const user = userEvent.setup();+ let count = 15;+ requests.teamOoo.mockImplementation(async () => teamOooItems(count));+ const { refetch } = renderList();+ await screen.findByRole('button', { name: /Jackson/ });+ await user.click(screen.getByRole('button', { name: '+5 more' }));++ count = 10;+ await refetch();++ expect(rows()).toHaveLength(10);+ expect(toggle()).toBeNull();++ count = 12;+ await refetch();++ expect(rows()).toHaveLength(12);+ expect(toggle()?.textContent).toBe('Show less');++ await user.click(screen.getByRole('button', { name: 'Show less' }));+ count = 13;+ await refetch();++ expect(rows()).toHaveLength(10);+ expect(toggle()?.textContent).toBe('+3 more');+ });});diff --git a/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx b/apps/web/src/features/calendar-view/components/CalendarSidebar.tsxindex c27a041caa..c889c47995 100644--- a/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx+++ b/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx@@ -24,7 +24,7 @@ import CaretDownIcon from '@icon/system/regular/caret-down.svg';import PlusIcon from '@icon/system/regular/plus.svg';import CloseIcon from '@icon/system/regular/x.svg';import { Key } from '@solid-primitives/keyed';-import { Checkbox, cn, Calendar as MiniCalendar } from '@ui';+import { Button, Checkbox, cn, Calendar as MiniCalendar } from '@ui';import { tourTarget } from '@ui/components/Tour';import { format } from 'date-fns';import {@@ -167,6 +167,25 @@ export function TeamOooUpcomingList() {const calendarView = useCalendarView();const isActive = (window: TeamOooWindow) =>calendarView.selectedEvent()?.id === window.event.id;+ // The choice outlives count changes: a list that shrinks to the cap and grows+ // again comes back the way the person left it.+ const [expanded, setExpanded] = createSignal(false);+ const hiddenCount = () => windows().length - UPCOMING_SHOWN_MAX;+ const shownWindows = () =>+ expanded() ? windows() : windows().slice(0, UPCOMING_SHOWN_MAX);+ let rowList: HTMLDivElement | undefined;+ const toggleExpanded = (toggle: HTMLElement) => {+ const anchor = calendarView.selectedEventAnchor();+ const anchoredToRow = anchor !== undefined && rowList?.contains(anchor);+ setExpanded((value) => !value);+ // Show less can remove the row an open card is anchored to; a pointer+ // press closes the card as an outside interaction, Enter does not.+ if (anchoredToRow && !anchor.isConnected) calendarView.closeEventDetails();+ // The section is last in the sidebar, so the longer list pushes this+ // focused control below the fold. Its margin keeps the sidebar's bottom+ // inset below it.+ toggle.scrollIntoView({ block: 'nearest' });+ };return (<div class="flex flex-col gap-0.5">@@ -185,56 +204,67 @@ export function TeamOooUpcomingList() {</span></Match><Match when={windows().length > 0}>- <Key- each={windows().slice(0, UPCOMING_SHOWN_MAX)}- by={(window) => window.event.id}+ <div+ ref={rowList}+ class={cn(+ 'flex flex-col gap-0.5',+ expanded() && hiddenCount() > 0 && 'max-h-120 overflow-y-auto'+ )}>- {(window) => (- <button- type="button"- class={cn(- 'flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-xs',- isActive(window()) ? 'bg-active' : 'hover:bg-hover'- )}- aria-current={isActive(window()) ? 'true' : undefined}- onClick={(event) => {- calendarPager.gotoDate(window().start);- calendarView.selectEvent(- window().event,- event.currentTarget,- 'agenda'- );- if (shell.aside.isOverlay()) shell.aside.collapse();- }}- >- <UserIcon- id={window().ownerId}- size="md"- suppressClick- showTooltip={false}- />- <span class="flex min-w-0 flex-1 flex-col">- <span class="flex w-full items-baseline gap-2">- <span class="min-w-0 flex-1 truncate text-ink">- {window().name}- </span>- <span class="shrink-0 text-ink-muted">- {windowDateLabel(window())}+ <Key each={shownWindows()} by={(window) => window.event.id}>+ {(window) => (+ <button+ type="button"+ class={cn(+ 'flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-xs',+ isActive(window()) ? 'bg-active' : 'hover:bg-hover'+ )}+ aria-current={isActive(window()) ? 'true' : undefined}+ onClick={(event) => {+ calendarPager.gotoDate(window().start);+ calendarView.selectEvent(+ window().event,+ event.currentTarget,+ 'agenda'+ );+ if (shell.aside.isOverlay()) shell.aside.collapse();+ }}+ >+ <UserIcon+ id={window().ownerId}+ size="md"+ suppressClick+ showTooltip={false}+ />+ <span class="flex min-w-0 flex-1 flex-col">+ <span class="flex w-full items-baseline gap-2">+ <span class="min-w-0 flex-1 truncate text-ink">+ {window().name}+ </span>+ <span class="shrink-0 text-ink-muted">+ {windowDateLabel(window())}+ </span></span>+ <Show when={window().title}>+ <span class="w-full truncate text-ink-muted">+ {window().title}+ </span>+ </Show></span>- <Show when={window().title}>- <span class="w-full truncate text-ink-muted">- {window().title}- </span>- </Show>- </span>- </button>- )}- </Key>- <Show when={windows().length > UPCOMING_SHOWN_MAX}>- <span class="px-2 py-1 text-xs text-ink-muted">- +{windows().length - UPCOMING_SHOWN_MAX} more- </span>+ </button>+ )}+ </Key>+ </div>+ <Show when={hiddenCount() > 0}>+ <Button+ variant="ghost"+ size="xs"+ class="self-start scroll-mb-(--sidebar-content-inset)"+ aria-expanded={expanded()}+ onClick={(event) => toggleExpanded(event.currentTarget)}+ >+ {expanded() ? 'Show less' : `+${hiddenCount()} more`}+ </Button></Show></Match></Switch>diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.mdindex a1516ec087..c2e8296317 100644--- a/docs/agent-guide/calendar.md+++ b/docs/agent-guide/calendar.md@@ -782,8 +782,11 @@ overlay the grid as read-only chips titled `<name>: <event title>`. The sidebar'`Team out of office` section (shown only when the user belongs to a team with other members)is a collapsible list of the next 90 days of teammate absences. The checkbox in its headershows or hides the overlay (the list itself always shows); clicking a row navigates the grid-to that date. Coverage depends on each teammate having connected their own calendar and using-Google's out-of-office event type.+to that date. The list shows ten rows and a `+N more` button that expands it to every row,+scrolling inside a bounded height, with `Show less` to collapse it again. The choice survives+the poll and count changes; when ten or fewer rows remain, the button hides. Reopening the+narrow-pane overlay sidebar starts collapsed, as its section toggles do. Coverage depends on+each teammate having connected their own calendar and using Google's out-of-office event type.The grid's pages and the list read the overlay from shared fixed 91-day windows,each fetched once and refreshed by one 30-second poll while the tab is focused, so