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): keep the team OOO card anchored across refetches (#8152)

gbirman9e41ba4dc2a0
diff --git a/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx b/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx
new file mode 100644
index 0000000000..278e3c245a
--- /dev/null
+++ b/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx
@@ -0,0 +1,97 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import type { CalendarEvent } from '@app/features/calendar/types';
+import type { TeamOutOfOfficeItem } from '@service-storage/generated/schemas/teamOutOfOfficeItem';
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import {
+ QueryClient,
+ QueryClientProvider,
+ useQuery,
+ useQueryClient,
+} from '@tanstack/solid-query';
+import { createSignal } from 'solid-js';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { TeamOooUpcomingList } from './CalendarSidebar';
+
+const requests = vi.hoisted(() => ({
+ teamOoo: vi.fn<() => Promise<TeamOutOfOfficeItem[]>>(),
+}));
+
+vi.mock('@core/context/user', () => ({
+ useUserId: () => () => 'macro|[email protected]',
+}));
+vi.mock('@core/user', () => ({
+ getDisplayName: () => 'Jackson Kustec',
+ tryMacroId: (id: string) => id,
+}));
+vi.mock('@core/component/UserIcon', () => ({
+ UserIcon: () => <span />,
+}));
+vi.mock('@queries/calendar/team-ooo', () => ({
+ useTeamOutOfOfficeQuery: () =>
+ useQuery(() => ({ queryKey: ['team-ooo'], queryFn: requests.teamOoo })),
+}));
+
+const [selectedEvent, setSelectedEvent] = createSignal<CalendarEvent>();
+const selectEvent = vi.fn((event: CalendarEvent, _anchor: HTMLElement) =>
+ setSelectedEvent(event)
+);
+
+vi.mock('@app/features/calendar/components/CalendarViewContext', () => ({
+ useCalendarView: () => ({ selectedEvent, selectEvent }),
+}));
+vi.mock('@app/features/calendar/components/CalendarPagerContext', () => ({
+ useCalendarPager: () => ({ gotoDate: vi.fn() }),
+}));
+vi.mock('@app/components/view-shell', () => ({
+ useViewShell: () => ({ aside: { isOverlay: () => false } }),
+}));
+
+function teamOooItems(): TeamOutOfOfficeItem[] {
+ return [
+ {
+ eventId: 'ooo-1',
+ occurrenceKey: '2026-11-20',
+ ownerId: 'macro|[email protected]',
+ time: { kind: 'allDay', startDate: '2026-11-20', endDate: '2026-11-21' },
+ },
+ ];
+}
+
+afterEach(() => {
+ cleanup();
+ setSelectedEvent(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>
+ ));
+
+ fireEvent.click(await screen.findByRole('button', { name: /Jackson/ }));
+ const anchor = selectEvent.mock.calls[0][1];
+ expect(anchor.getAttribute('aria-current')).toBe('true');
+
+ await refetch();
+
+ expect(requests.teamOoo).toHaveBeenCalledTimes(2);
+ expect(screen.getByRole('button', { name: /Jackson/ })).toBe(anchor);
+ expect(anchor.isConnected).toBe(true);
+ });
+});
diff --git a/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx b/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx
index 44139a3d31..3fd08a4b1f 100644
--- a/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx
+++ b/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx
@@ -21,6 +21,7 @@ import { isTouchDevice } from '@core/mobile/isTouchDevice';
import CaretDownIcon from '@phosphor/caret-down.svg';
import PlusIcon from '@phosphor/plus.svg';
import CloseIcon from '@phosphor/x.svg';
+import { Key } from '@solid-primitives/keyed';
import { Checkbox, cn, Calendar as MiniCalendar } from '@ui';
import { tourTarget } from '@ui/components/Tour';
import { format } from 'date-fns';
@@ -153,7 +154,7 @@ function TeamOooSkeleton() {
);
}
-function TeamOooUpcomingList() {
+export function TeamOooUpcomingList() {
const calendarPager = useCalendarPager();
const shell = useViewShell();
const upcoming = useUpcomingTeamOoo();
@@ -179,19 +180,22 @@ function TeamOooUpcomingList() {
</span>
</Match>
<Match when={windows().length > 0}>
- <For each={windows().slice(0, UPCOMING_SHOWN_MAX)}>
+ <Key
+ each={windows().slice(0, UPCOMING_SHOWN_MAX)}
+ 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'
+ isActive(window()) ? 'bg-active' : 'hover:bg-hover'
)}
- aria-current={isActive(window) ? 'true' : undefined}
+ aria-current={isActive(window()) ? 'true' : undefined}
onClick={(event) => {
- calendarPager.gotoDate(window.start);
+ calendarPager.gotoDate(window().start);
calendarView.selectEvent(
- window.event,
+ window().event,
event.currentTarget,
'agenda'
);
@@ -199,7 +203,7 @@ function TeamOooUpcomingList() {
}}
>
<UserIcon
- id={window.ownerId}
+ id={window().ownerId}
size="md"
suppressClick
showTooltip={false}
@@ -207,21 +211,21 @@ function TeamOooUpcomingList() {
<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}
+ {window().name}
</span>
<span class="shrink-0 text-ink-muted">
- {windowDateLabel(window)}
+ {windowDateLabel(window())}
</span>
</span>
- <Show when={window.title}>
+ <Show when={window().title}>
<span class="w-full truncate text-ink-muted">
- {window.title}
+ {window().title}
</span>
</Show>
</span>
</button>
)}
- </For>
+ </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