Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calendar): open team out of office rows on their grid chip (#9199)

gbirmanadc8ed941827
diff --git a/apps/web/src/features/calendar-view/calendar-focus-target.test.tsx b/apps/web/src/features/calendar-view/calendar-focus-target.test.tsx
new file mode 100644
index 0000000000..a729c3c3f6
--- /dev/null
+++ b/apps/web/src/features/calendar-view/calendar-focus-target.test.tsx
@@ -0,0 +1,152 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import { cleanup, render } from '@solidjs/testing-library';
+import { createSignal } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import {
+ CalendarFocusContextProvider,
+ type CalendarFocusTarget,
+ OCCURRENCE_FOCUS_TIMEOUT_MS,
+ useCalendarFocus,
+} from './calendar-focus-target';
+
+const OCCURRENCE = {
+ eventId: 'ooo-1',
+ occurrenceKey: '2026-11-19',
+ date: new Date(2026, 10, 19),
+};
+
+function renderFocus() {
+ const [navigation, setNavigation] = createSignal<CalendarFocusTarget>();
+ let focus!: ReturnType<typeof useCalendarFocus>;
+ function Probe() {
+ focus = useCalendarFocus();
+ return null;
+ }
+ const view = render(() => (
+ <CalendarFocusContextProvider target={navigation}>
+ <Probe />
+ </CalendarFocusContextProvider>
+ ));
+ return { focus: () => focus, setNavigation, unmount: view.unmount };
+}
+
+function navigationTarget(requestId: number): CalendarFocusTarget {
+ return {
+ eventId: 'meeting',
+ occurrenceKey: '2026-11-20T15:00:00Z',
+ date: new Date(2026, 10, 20),
+ requestId,
+ requestedAt: Date.now(),
+ };
+}
+
+beforeEach(() => {
+ vi.useFakeTimers();
+});
+
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+});
+
+describe('CalendarFocusContext occurrence requests', () => {
+ it('stays pending until the page consumes it, without falling back', () => {
+ const { focus } = renderFocus();
+ const onTimeout = vi.fn();
+
+ focus().focusOccurrence(OCCURRENCE, onTimeout);
+ const target = focus().pendingTarget();
+
+ expect(target).toMatchObject(OCCURRENCE);
+ focus().consume(target?.requestId ?? 0);
+ expect(focus().pendingTarget()).toBeUndefined();
+
+ vi.advanceTimersByTime(OCCURRENCE_FOCUS_TIMEOUT_MS);
+ expect(onTimeout).not.toHaveBeenCalled();
+ });
+
+ it('falls back once when no page renders the occurrence in time', () => {
+ const { focus } = renderFocus();
+ const onTimeout = vi.fn();
+
+ focus().focusOccurrence(OCCURRENCE, onTimeout);
+ vi.advanceTimersByTime(OCCURRENCE_FOCUS_TIMEOUT_MS - 1);
+ expect(onTimeout).not.toHaveBeenCalled();
+
+ vi.advanceTimersByTime(1);
+ expect(onTimeout).toHaveBeenCalledTimes(1);
+ expect(focus().pendingTarget()).toBeUndefined();
+
+ vi.advanceTimersByTime(OCCURRENCE_FOCUS_TIMEOUT_MS);
+ expect(onTimeout).toHaveBeenCalledTimes(1);
+ });
+
+ it('replaces an earlier occurrence request and its fallback', () => {
+ const { focus } = renderFocus();
+ const first = vi.fn();
+ const second = vi.fn();
+
+ focus().focusOccurrence(OCCURRENCE, first);
+ focus().focusOccurrence(
+ { ...OCCURRENCE, occurrenceKey: '2026-11-20' },
+ second
+ );
+ vi.advanceTimersByTime(OCCURRENCE_FOCUS_TIMEOUT_MS);
+
+ expect(first).not.toHaveBeenCalled();
+ expect(second).toHaveBeenCalledTimes(1);
+ });
+
+ it('yields to a newer navigation request without falling back', () => {
+ const { focus, setNavigation } = renderFocus();
+ const onTimeout = vi.fn();
+
+ focus().focusOccurrence(OCCURRENCE, onTimeout);
+ vi.advanceTimersByTime(10);
+ const navigation = navigationTarget(7);
+ setNavigation(navigation);
+
+ expect(focus().pendingTarget()).toBe(navigation);
+ vi.advanceTimersByTime(OCCURRENCE_FOCUS_TIMEOUT_MS);
+ expect(onTimeout).not.toHaveBeenCalled();
+ });
+
+ it('supersedes a navigation request that has not landed', () => {
+ const { focus, setNavigation } = renderFocus();
+ setNavigation(navigationTarget(3));
+ vi.advanceTimersByTime(10);
+
+ focus().focusOccurrence(OCCURRENCE, vi.fn());
+ const target = focus().pendingTarget();
+ expect(target).toMatchObject(OCCURRENCE);
+
+ focus().consume(target?.requestId ?? 0);
+ expect(focus().pendingTarget()).toBeUndefined();
+ });
+
+ it('drops a cancelled request without falling back', () => {
+ const { focus } = renderFocus();
+ const onTimeout = vi.fn();
+
+ focus().focusOccurrence(OCCURRENCE, onTimeout);
+ focus().cancelOccurrence();
+
+ expect(focus().pendingTarget()).toBeUndefined();
+ vi.advanceTimersByTime(OCCURRENCE_FOCUS_TIMEOUT_MS);
+ expect(onTimeout).not.toHaveBeenCalled();
+ });
+
+ it('never falls back after the calendar unmounts', () => {
+ const { focus, unmount } = renderFocus();
+ const onTimeout = vi.fn();
+
+ focus().focusOccurrence(OCCURRENCE, onTimeout);
+ unmount();
+ vi.advanceTimersByTime(OCCURRENCE_FOCUS_TIMEOUT_MS);
+
+ expect(onTimeout).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/web/src/features/calendar-view/calendar-focus-target.ts b/apps/web/src/features/calendar-view/calendar-focus-target.ts
index 5d601f9c01..f1236571e7 100644
--- a/apps/web/src/features/calendar-view/calendar-focus-target.ts
+++ b/apps/web/src/features/calendar-view/calendar-focus-target.ts
@@ -1,7 +1,10 @@
import { createAssertedContextProvider } from '@core/context/createContext';
+import { debounce } from '@core/util/debounce';
import { type Accessor, createSignal, type ParentProps } from 'solid-js';
const FOCUS_TARGET_TTL_MS = 15_000;
+/** How long an in-calendar request waits for its chip before falling back. */
+export const OCCURRENCE_FOCUS_TIMEOUT_MS = 2_000;
/** A request for one calendar view instance to focus a rendered occurrence. */
export interface CalendarFocusTarget {
@@ -17,6 +20,12 @@ export interface CalendarFocusTarget {
requestedAt: number;
}
+/** An occurrence to focus from inside the calendar, such as a sidebar row. */
+export type CalendarFocusOccurrence = Pick<
+ CalendarFocusTarget,
+ 'eventId' | 'occurrenceKey' | 'date'
+>;
+
/** The grid's composite view-model id for a focus target. */
export function calendarFocusTargetId(target: CalendarFocusTarget): string {
return JSON.stringify([target.eventId, target.occurrenceKey]);
@@ -32,19 +41,78 @@ export const [CalendarFocusContextProvider, useCalendarFocus] =
'CalendarFocusContext',
(props: CalendarFocusContextProps) => {
const [consumedRequestId, setConsumedRequestId] = createSignal<number>();
+ // In-calendar requests count down from -1, so their ids never meet the
+ // navigation requests' ids.
+ const [occurrenceTarget, setOccurrenceTarget] =
+ createSignal<CalendarFocusTarget>();
+ let nextOccurrenceRequestId = -1;
+ let fallback: (() => void) | undefined;
+
+ const navigationTarget = () => {
+ const target = props.target?.();
+ if (
+ !target ||
+ target.requestId === consumedRequestId() ||
+ Date.now() - target.requestedAt > FOCUS_TARGET_TTL_MS
+ ) {
+ return undefined;
+ }
+ return target;
+ };
+ const supersededByNavigation = (occurrence: CalendarFocusTarget) => {
+ const navigation = props.target?.();
+ return (
+ navigation !== undefined &&
+ navigation.requestedAt > occurrence.requestedAt
+ );
+ };
+ const expireOccurrence = debounce(() => {
+ const occurrence = occurrenceTarget();
+ const open = fallback;
+ fallback = undefined;
+ setOccurrenceTarget(undefined);
+ if (occurrence && !supersededByNavigation(occurrence)) open?.();
+ }, OCCURRENCE_FOCUS_TIMEOUT_MS);
+ const dropOccurrence = () => {
+ expireOccurrence.clear();
+ fallback = undefined;
+ setOccurrenceTarget(undefined);
+ };
+
return {
pendingTarget: () => {
- const target = props.target?.();
- if (
- !target ||
- target.requestId === consumedRequestId() ||
- Date.now() - target.requestedAt > FOCUS_TARGET_TTL_MS
- ) {
- return undefined;
+ const occurrence = occurrenceTarget();
+ if (occurrence && !supersededByNavigation(occurrence)) {
+ return occurrence;
}
- return target;
+ return navigationTarget();
+ },
+ consume: (requestId: number) => {
+ if (occurrenceTarget()?.requestId === requestId) dropOccurrence();
+ else setConsumedRequestId(requestId);
+ },
+ /** Drops a pending in-calendar request without its fallback. */
+ cancelOccurrence: dropOccurrence,
+ /**
+ * Pages to an occurrence and opens its details on its chip, as a
+ * navigation request does. Calls `onTimeout` instead when no page
+ * renders the chip in time, for example when it is filtered out.
+ */
+ focusOccurrence: (
+ occurrence: CalendarFocusOccurrence,
+ onTimeout: () => void
+ ) => {
+ // The newer request wins over a navigation that has not landed yet.
+ const navigation = props.target?.();
+ if (navigation) setConsumedRequestId(navigation.requestId);
+ fallback = onTimeout;
+ setOccurrenceTarget({
+ ...occurrence,
+ requestId: nextOccurrenceRequestId--,
+ requestedAt: Date.now(),
+ });
+ expireOccurrence();
},
- consume: (requestId: number) => setConsumedRequestId(requestId),
};
}
);
diff --git a/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx b/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx
index f866491a15..de3d87817d 100644
--- a/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx
+++ b/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx
@@ -2,7 +2,10 @@
* @vitest-environment jsdom
*/
-import type { CalendarEvent } from '@app/features/calendar/types';
+import {
+ type CalendarEvent,
+ TEAM_OOO_SOURCE_ID,
+} from '@app/features/calendar/types';
import type { TeamOutOfOfficeItem } from '@service-storage/generated/schemas/teamOutOfOfficeItem';
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
import {
@@ -15,6 +18,7 @@ import userEvent from '@testing-library/user-event';
import { addDays, format } from 'date-fns';
import { createSignal } from 'solid-js';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { CalendarFocusOccurrence } from '../calendar-focus-target';
import { TeamOooUpcomingList } from './CalendarSidebar';
const requests = vi.hoisted(() => ({
@@ -50,10 +54,16 @@ vi.mock('@queries/calendar/team-ooo', () => ({
const [selectedEvent, setSelectedEvent] = createSignal<CalendarEvent>();
const [selectedEventAnchor, setSelectedEventAnchor] =
createSignal<HTMLElement>();
-const selectEvent = vi.fn((event: CalendarEvent, anchor: HTMLElement) => {
- setSelectedEvent(event);
- setSelectedEventAnchor(anchor);
-});
+const [overlayVisible, setOverlayVisible] = createSignal(false);
+const selectEvent = vi.fn(
+ (event: CalendarEvent, anchor: HTMLElement, _origin?: 'grid' | 'agenda') => {
+ setSelectedEvent(event);
+ setSelectedEventAnchor(anchor);
+ }
+);
+const gotoDate = vi.fn<(date: Date) => void>();
+const focusOccurrence =
+ vi.fn<(occurrence: CalendarFocusOccurrence, onTimeout: () => void) => void>();
const closeEventDetails = vi.fn(() => {
setSelectedEvent(undefined);
setSelectedEventAnchor(undefined);
@@ -65,10 +75,15 @@ vi.mock('@app/features/calendar/components/CalendarViewContext', () => ({
selectedEventAnchor,
selectEvent,
closeEventDetails,
+ isSourceVisible: (sourceId: string) =>
+ sourceId === TEAM_OOO_SOURCE_ID ? overlayVisible() : true,
}),
}));
vi.mock('@app/features/calendar/components/CalendarPagerContext', () => ({
- useCalendarPager: () => ({ gotoDate: vi.fn() }),
+ useCalendarPager: () => ({ gotoDate }),
+}));
+vi.mock('../calendar-focus-target', () => ({
+ useCalendarFocus: () => ({ focusOccurrence }),
}));
vi.mock('@app/components/view-shell', () => ({
useViewShell: () => ({ aside: { isOverlay: () => false } }),
@@ -123,6 +138,7 @@ afterEach(() => {
cleanup();
setSelectedEvent(undefined);
setSelectedEventAnchor(undefined);
+ setOverlayVisible(false);
vi.clearAllMocks();
});
@@ -262,4 +278,53 @@ describe('TeamOooUpcomingList', () => {
expect(rows()).toHaveLength(10);
expect(toggle()?.textContent).toBe('+3 more');
});
+
+ it('opens on the grid chip when the overlay shows the absence', async () => {
+ requests.teamOoo.mockImplementation(async () => teamOooItems());
+ setOverlayVisible(true);
+ renderList();
+
+ fireEvent.click(await screen.findByRole('button', { name: /Jackson/ }));
+
+ const [item] = teamOooItems();
+ expect(focusOccurrence).toHaveBeenCalledTimes(1);
+ expect(focusOccurrence.mock.calls[0][0]).toMatchObject({
+ eventId: item.eventId,
+ occurrenceKey: item.occurrenceKey,
+ });
+ expect(gotoDate).toHaveBeenCalledWith(
+ focusOccurrence.mock.calls[0][0].date
+ );
+ expect(selectEvent).not.toHaveBeenCalled();
+ });
+
+ it('falls back to the row when the chip never renders', async () => {
+ requests.teamOoo.mockImplementation(async () => teamOooItems());
+ setOverlayVisible(true);
+ renderList();
+ const row = await screen.findByRole('button', { name: /Jackson/ });
+ fireEvent.click(row);
+
+ const [, onTimeout] = focusOccurrence.mock.calls[0];
+ onTimeout();
+
+ expect(selectEvent).toHaveBeenCalledTimes(1);
+ expect(selectEvent.mock.calls[0][1]).toBe(row);
+ expect(selectEvent.mock.calls[0][2]).toBe('agenda');
+ expect(row.getAttribute('aria-current')).toBe('true');
+ });
+
+ it('opens on the row when the overlay is hidden', async () => {
+ requests.teamOoo.mockImplementation(async () => teamOooItems());
+ renderList();
+ const row = await screen.findByRole('button', { name: /Jackson/ });
+
+ fireEvent.click(row);
+
+ expect(focusOccurrence).not.toHaveBeenCalled();
+ expect(gotoDate).toHaveBeenCalledTimes(1);
+ expect(selectEvent).toHaveBeenCalledTimes(1);
+ expect(selectEvent.mock.calls[0][1]).toBe(row);
+ expect(selectEvent.mock.calls[0][2]).toBe('agenda');
+ });
});
diff --git a/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx b/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx
index c889c47995..3c2dac2252 100644
--- a/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx
+++ b/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx
@@ -38,6 +38,7 @@ import {
Switch,
} from 'solid-js';
import { CalendarCallSidebar } from '../calendar-call-sidebar';
+import { useCalendarFocus } from '../calendar-focus-target';
import { CALENDAR_TOUR } from '../tour';
import {
CalendarCreateBookingLinkItem,
@@ -165,8 +166,30 @@ export function TeamOooUpcomingList() {
const upcoming = useUpcomingTeamOoo();
const windows = upcoming.windows;
const calendarView = useCalendarView();
+ const calendarFocus = useCalendarFocus();
const isActive = (window: TeamOooWindow) =>
calendarView.selectedEvent()?.id === window.event.id;
+ const openWindow = (window: TeamOooWindow, row: HTMLElement) => {
+ const openOnRow = () =>
+ calendarView.selectEvent(window.event, row, 'agenda');
+ calendarPager.gotoDate(window.start);
+ // With the overlay on, the absence also renders on the grid: open it on
+ // its chip once the page shows it, as a navigation request does, so the
+ // card never opens on the row and then jumps to the chip.
+ if (calendarView.isSourceVisible(TEAM_OOO_SOURCE_ID)) {
+ calendarFocus.focusOccurrence(
+ {
+ eventId: window.eventId,
+ occurrenceKey: window.occurrenceKey,
+ date: window.start,
+ },
+ openOnRow
+ );
+ } else {
+ openOnRow();
+ }
+ if (shell.aside.isOverlay()) shell.aside.collapse();
+ };
// 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);
@@ -220,15 +243,7 @@ export function TeamOooUpcomingList() {
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();
- }}
+ onClick={(event) => openWindow(window(), event.currentTarget)}
>
<UserIcon
id={window().ownerId}
diff --git a/apps/web/src/features/calendar-view/components/Page.tsx b/apps/web/src/features/calendar-view/components/Page.tsx
index 8ef8c90d97..9cccea29e2 100644
--- a/apps/web/src/features/calendar-view/components/Page.tsx
+++ b/apps/web/src/features/calendar-view/components/Page.tsx
@@ -361,6 +361,9 @@ export function Page(props: {
onEventSelect: (event, element) => {
if (isActive()) calendarView.selectEvent(event, element);
},
+ onSelectedEventMount: (event, element) => {
+ if (isActive()) calendarView.reanchorSelectedEvent(event, element);
+ },
}}
eventTimeChangePending={updateEventTime.isPending}
onDatesSet={handleDatesSet}
diff --git a/apps/web/src/features/calendar/components/CalendarGrid.tsx b/apps/web/src/features/calendar/components/CalendarGrid.tsx
index 16a49965c9..808a86b509 100644
--- a/apps/web/src/features/calendar/components/CalendarGrid.tsx
+++ b/apps/web/src/features/calendar/components/CalendarGrid.tsx
@@ -98,6 +98,8 @@ export interface CalendarGridSelection {
eventId?: string;
onDateSelect?: (selection: DateSelectArg) => void;
onEventSelect?: (event: CalendarEvent, element: HTMLElement) => void;
+ /** The selected event's chip mounted, replacing the element it had. */
+ onSelectedEventMount?: (event: CalendarEvent, element: HTMLElement) => void;
}
export interface CalendarGridProps {
@@ -312,7 +314,7 @@ export function CalendarGrid(props: CalendarGridProps) {
const selectedId = props.selection.eventId;
if (selectedId !== undefined && occurrenceIds.includes(selectedId)) {
const selected = eventByRenderId(selectedId);
- if (selected) props.selection.onEventSelect?.(selected, el);
+ if (selected) props.selection.onSelectedEventMount?.(selected, el);
}
notifyChipMount();
}}
diff --git a/apps/web/src/features/calendar/components/CalendarViewContext.test.tsx b/apps/web/src/features/calendar/components/CalendarViewContext.test.tsx
new file mode 100644
index 0000000000..3ee9bff649
--- /dev/null
+++ b/apps/web/src/features/calendar/components/CalendarViewContext.test.tsx
@@ -0,0 +1,146 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import {
+ CalendarFocusContextProvider,
+ OCCURRENCE_FOCUS_TIMEOUT_MS,
+ useCalendarFocus,
+} from '@app/features/calendar-view/calendar-focus-target';
+import { cleanup, render } from '@solidjs/testing-library';
+import { createRoot } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { CalendarEvent } from '../types';
+import {
+ CalendarViewContextProvider,
+ createCalendarEventSelection,
+ useCalendarView,
+} from './CalendarViewContext';
+
+const teamReset = vi.hoisted(() => ({ fire: () => {} }));
+
+vi.mock('@queries/calendar/team-cache', () => ({
+ subscribeToTeamCalendarReset: (onReset: () => void) => {
+ teamReset.fire = onReset;
+ return () => {};
+ },
+}));
+vi.mock('../hooks/use-calendar-sources', () => ({
+ useCalendarSources: () => ({
+ sources: () => [],
+ sourceById: () => new Map(),
+ sourcesReady: () => true,
+ }),
+}));
+vi.mock('../utils/preferences', () => ({
+ useCalendarPreferences: () => [{ hiddenSourceIds: [] }, vi.fn()],
+}));
+
+const EVENT = { id: 'ooo', eventId: 'ooo-1' } as CalendarEvent;
+const OCCURRENCE = {
+ eventId: 'ooo-2',
+ occurrenceKey: '2026-11-19',
+ date: new Date(2026, 10, 19),
+};
+
+function withSelection(
+ run: (selection: ReturnType<typeof createCalendarEventSelection>) => void
+) {
+ createRoot((dispose) => {
+ run(createCalendarEventSelection());
+ dispose();
+ });
+}
+
+function renderContexts() {
+ let focus!: ReturnType<typeof useCalendarFocus>;
+ let view!: ReturnType<typeof useCalendarView>;
+ function Probe() {
+ focus = useCalendarFocus();
+ view = useCalendarView();
+ return null;
+ }
+ render(() => (
+ <CalendarFocusContextProvider>
+ <CalendarViewContextProvider>
+ <Probe />
+ </CalendarViewContextProvider>
+ </CalendarFocusContextProvider>
+ ));
+ return { focus: () => focus, view: () => view };
+}
+
+describe('createCalendarEventSelection', () => {
+ it('keeps a list selection on its row when the chip mounts', () => {
+ withSelection((selection) => {
+ const row = document.createElement('button');
+ const chip = document.createElement('a');
+
+ selection.select(EVENT, row, 'agenda');
+ selection.reanchor(EVENT, chip);
+
+ expect(selection.anchor()).toBe(row);
+ expect(selection.origin()).toBe('agenda');
+ });
+ });
+
+ it('moves a grid selection to the chip that replaced its own', () => {
+ withSelection((selection) => {
+ const chip = document.createElement('a');
+ const remounted = document.createElement('a');
+
+ selection.select(EVENT, chip);
+ selection.reanchor(EVENT, remounted);
+
+ expect(selection.anchor()).toBe(remounted);
+ });
+ });
+});
+
+describe('CalendarViewContext with a row waiting for its chip', () => {
+ beforeEach(() => {
+ vi.useFakeTimers();
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+ });
+
+ it('lets a newer selection cancel the waiting row', () => {
+ const { focus, view } = renderContexts();
+ const onTimeout = vi.fn();
+ const chip = document.createElement('a');
+
+ focus().focusOccurrence(OCCURRENCE, onTimeout);
+ view().selectEvent(EVENT, chip);
+
+ expect(focus().pendingTarget()).toBeUndefined();
+ vi.advanceTimersByTime(OCCURRENCE_FOCUS_TIMEOUT_MS);
+ expect(onTimeout).not.toHaveBeenCalled();
+ expect(view().selectedEventAnchor()).toBe(chip);
+ });
+
+ it('drops the waiting row when team data resets', () => {
+ const { focus } = renderContexts();
+ const onTimeout = vi.fn();
+
+ focus().focusOccurrence(OCCURRENCE, onTimeout);
+ teamReset.fire();
+
+ expect(focus().pendingTarget()).toBeUndefined();
+ vi.advanceTimersByTime(OCCURRENCE_FOCUS_TIMEOUT_MS);
+ expect(onTimeout).not.toHaveBeenCalled();
+ });
+
+ it('keeps the row waiting when an open card only changes anchor', () => {
+ const { focus, view } = renderContexts();
+ const chip = document.createElement('a');
+ view().selectEvent(EVENT, chip);
+
+ focus().focusOccurrence(OCCURRENCE, vi.fn());
+ view().reanchorSelectedEvent(EVENT, document.createElement('a'));
+
+ expect(focus().pendingTarget()).toMatchObject(OCCURRENCE);
+ });
+});
diff --git a/apps/web/src/features/calendar/components/CalendarViewContext.tsx b/apps/web/src/features/calendar/components/CalendarViewContext.tsx
index 022837aede..99571347d7 100644
--- a/apps/web/src/features/calendar/components/CalendarViewContext.tsx
+++ b/apps/web/src/features/calendar/components/CalendarViewContext.tsx
@@ -1,3 +1,4 @@
+import { useCalendarFocus } from '@app/features/calendar-view/calendar-focus-target';
import { createAssertedContextProvider } from '@core/context/createContext';
import { subscribeToTeamCalendarReset } from '@queries/calendar/team-cache';
import {
@@ -33,7 +34,7 @@ type CalendarViewContextProps = ParentProps<{
onFocusedEventIdChange?: (eventId: string | undefined) => void;
}>;
-function createCalendarEventSelection(
+export function createCalendarEventSelection(
onFocusedEventIdChange?: (eventId: string | undefined) => void
) {
const [event, setEvent] = createSignal<CalendarEvent>();
@@ -66,8 +67,13 @@ function createCalendarEventSelection(
const refresh = (nextEvent: CalendarEvent) => {
if (event()?.id === nextEvent.id) setEvent(nextEvent);
};
+ // A grid selection follows its chip when the grid replaces it. A list
+ // selection stays on its row, so a chip mounting late never moves it.
+ const reanchor = (nextEvent: CalendarEvent, nextAnchor: HTMLElement) => {
+ if (origin() === 'grid') select(nextEvent, nextAnchor);
+ };
- return { anchor, close, event, origin, refresh, select };
+ return { anchor, close, event, origin, reanchor, refresh, select };
}
export const [CalendarViewContextProvider, useCalendarView] =
@@ -88,9 +94,16 @@ export const [CalendarViewContextProvider, useCalendarView] =
const selection = createCalendarEventSelection(
props.onFocusedEventIdChange
);
+ const calendarFocus = useCalendarFocus();
+ // A selection made while a row waits for its chip wins over that row.
+ const selectEvent: typeof selection.select = (...args) => {
+ calendarFocus.cancelOccurrence();
+ selection.select(...args);
+ };
// A revoked OOO agenda entry can lie outside every mounted viewport.
// Close detached selections synchronously when authorization resets data.
const unsubscribeTeamReset = subscribeToTeamCalendarReset(() => {
+ calendarFocus.cancelOccurrence();
const selected = selection.event();
if (
selected?.teamProjection ||
@@ -213,7 +226,8 @@ export const [CalendarViewContextProvider, useCalendarView] =
setTimeFormat: (timeFormat: CalendarTimeFormat) =>
setPreferences('timeFormat', timeFormat),
closeEventDetails,
- selectEvent: selection.select,
+ selectEvent,
+ reanchorSelectedEvent: selection.reanchor,
refreshSelectedEvent: selection.refresh,
refreshSelectedEventFromPage,
};
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index c2e8296317..d4da70be00 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -342,7 +342,11 @@ is feature-gated and lists teammates with 24px avatars; its header has the same
14px checkbox before the title, which shows or hides the grid overlay and is saved
with the calendar visibility preferences. The teammate rows have no checkboxes and
stay listed while the overlay is hidden. Clicking a teammate's row navigates to that
-date, opens read-only event details, and marks the row active. The left-aligned
+date, opens read-only event details, and marks the row active. With the overlay shown,
+the details wait for the event's chip and open on it, scrolled into view, the way a
+search result or notification opens; if the chip has not rendered after two seconds
+they open beside the row instead. With the overlay hidden they open beside the row.
+A card opened beside a row stays there when the event's chip mounts later. The left-aligned
`Settings` control with a gear icon fills the sidebar footer; booking management
lives in the `Booking links` dropdown rather than a separate footer shortcut.
An account checkbox toggles its calendars together in one update. The checkbox