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 calendar picker rows across calendar list refetches (#8942)

teod366c303c5b8
diff --git a/.agents/rules/web/data.md b/.agents/rules/web/data.md
index 752d240acd..aec3fc17fb 100644
--- a/.agents/rules/web/data.md
+++ b/.agents/rules/web/data.md
@@ -80,7 +80,9 @@ Examples: [session query factory](../../../apps/web/src/lib/queries/agent-sessio
- **FE-49** Refetches and optimistic updates never wipe local state (drafts,
anchors, selections), and a refetch started before a mutation can't overwrite
its result. Optimistic rollback state lives in `onMutate`; temporary ids are
- never openable.
+ never openable. Solid Query returns new objects on every refetch, so a query
+ that polls or refetches under open lists and pickers sets `reconcile: 'id'`;
+ otherwise rows remount and drop focus.
- **FE-50** Scope invalidation to what changed, but update every reader of it.
Query keys hold exactly the fetch inputs.
- **FE-58** With the GraphQL normalized cache, a mutation never refetches the
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.calendar-refetch.test.tsx b/apps/web/src/features/calendar/components/composer/EventForm.calendar-refetch.test.tsx
new file mode 100644
index 0000000000..3c4610818b
--- /dev/null
+++ b/apps/web/src/features/calendar/components/composer/EventForm.calendar-refetch.test.tsx
@@ -0,0 +1,171 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import type { VisibleCalendar } from '@queries/calendar/calendars';
+import { calendarKeys } from '@queries/calendar/keys';
+import { cleanup, render, screen, waitFor } from '@solidjs/testing-library';
+import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';
+import userEvent from '@testing-library/user-event';
+import { ok } from 'neverthrow';
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+import { useEventEditor } from '../../hooks/use-event-editor';
+import { createCalendarEventFormController } from './create-calendar-event-form-controller';
+import { EventForm } from './EventForm';
+
+const mocks = vi.hoisted(() => ({ listCalendars: vi.fn() }));
+
+vi.mock('@service-email/client', () => ({
+ emailClient: { listCalendars: mocks.listCalendars },
+}));
+vi.mock('@queries/calendar/graphql/flag', () => ({
+ useGraphqlCalendarHost: () => () => undefined,
+}));
+vi.mock('@core/user', () => ({
+ useContacts: () => () => [],
+ recipientEntityMapper: () => (value: unknown) => value,
+}));
+vi.mock('@components/app/split-layout/split-router/mention-links', () => ({
+ useMacroMentionLinkResolver: () => () => undefined,
+}));
+vi.mock(
+ '@core/component/LexicalMarkdown/component/core/MarkdownTextarea',
+ () => ({ MarkdownTextarea: () => null })
+);
+vi.mock('@property/editors/selectors/PropertyEntitySelector', () => ({
+ PropertyEntitySelector: () => document.createElement('input'),
+}));
+
+class ObserverStub {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+}
+
+const GOOGLE_CAPABILITIES = {
+ conferenceProvider: 'google_meet',
+ removeConference: true,
+ autoDecline: true,
+ emailReminders: true,
+ customRecurrence: true,
+ resetRsvp: true,
+ guestPolicy: true,
+} as const;
+
+/** The list as the server sends it: new objects on every response. */
+function serverCalendars(): VisibleCalendar[] {
+ const google = (id: string, name: string, isPrimary: boolean) => ({
+ provider: 'google' as const,
+ capabilities: { ...GOOGLE_CAPABILITIES },
+ id,
+ emailLinkId: 'gmail-link',
+ emailAddress: '[email protected]',
+ name,
+ color: '#4285f4',
+ isPrimary,
+ isWritable: true,
+ isSubscription: false,
+ defaultReminders: [{ method: 'popup' as const, minutes: 10 }],
+ });
+ return [
+ google('google-primary', '[email protected]', true),
+ google('google-shared', '[email protected]', false),
+ google('google-vacation', 'Vacation', false),
+ {
+ provider: 'outlook',
+ capabilities: {
+ conferenceProvider: 'microsoft_teams',
+ removeConference: false,
+ autoDecline: true,
+ emailReminders: false,
+ customRecurrence: false,
+ resetRsvp: false,
+ guestPolicy: false,
+ },
+ id: 'outlook-primary',
+ emailLinkId: 'outlook-link',
+ emailAddress: '[email protected]',
+ name: 'Calendar',
+ color: '#0078d4',
+ isPrimary: true,
+ isWritable: true,
+ isSubscription: false,
+ defaultReminders: [],
+ },
+ ];
+}
+
+function NewEventForm() {
+ const editor = useEventEditor({
+ event: () => undefined,
+ onSaved: vi.fn(),
+ macroCallsEnabled: () => true,
+ });
+ const controller = createCalendarEventFormController({
+ initialValue: {
+ title: '',
+ allDay: false,
+ start: '2030-01-01T12:00',
+ end: '2030-01-01T13:00',
+ recurrenceLines: [],
+ guests: '',
+ location: '',
+ description: '',
+ conference: 'macro',
+ },
+ calendarOptions: editor.calendarOptions,
+ guestOptions: editor.guestOptions,
+ });
+ return (
+ <EventForm
+ controller={controller}
+ macroCallsEnabled
+ pending={false}
+ onCancel={vi.fn()}
+ onSubmit={editor.save}
+ />
+ );
+}
+
+let client: QueryClient;
+
+beforeEach(() => {
+ Element.prototype.scrollIntoView = vi.fn();
+ vi.stubGlobal('ResizeObserver', ObserverStub);
+ vi.stubGlobal('IntersectionObserver', ObserverStub);
+ vi.stubGlobal('scrollTo', vi.fn() as unknown as typeof window.scrollTo);
+ mocks.listCalendars.mockImplementation(async () =>
+ ok({ calendars: serverCalendars() })
+ );
+ client = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+});
+
+afterEach(() => {
+ cleanup();
+ client.clear();
+ vi.unstubAllGlobals();
+});
+
+it('chooses the Outlook calendar from the keyboard after the calendar list refetches', async () => {
+ const user = userEvent.setup();
+ render(() => (
+ <QueryClientProvider client={client}>
+ <NewEventForm />
+ </QueryClientProvider>
+ ));
+ const trigger = screen.getByLabelText('Calendar');
+ await waitFor(() => expect(trigger.textContent).toContain('[email protected]'));
+
+ await user.click(trigger);
+ await screen.findByRole('listbox');
+ await client.refetchQueries({
+ queryKey: calendarKeys.visibleCalendars.queryKey,
+ });
+ expect(mocks.listCalendars).toHaveBeenCalledTimes(2);
+
+ await user.keyboard('{ArrowDown}{ArrowDown}{ArrowDown}{Enter}');
+
+ expect(trigger.textContent).toContain('[email protected]');
+});
diff --git a/apps/web/src/lib/queries/calendar/calendars.ts b/apps/web/src/lib/queries/calendar/calendars.ts
index e89de1120c..ea9ed55c8f 100644
--- a/apps/web/src/lib/queries/calendar/calendars.ts
+++ b/apps/web/src/lib/queries/calendar/calendars.ts
@@ -71,6 +71,7 @@ function cachedVisibleCalendarsQueryOptions(host: CacheHost, enabled: boolean) {
networkMode: 'offlineFirst' as const,
enabled,
placeholderData: keepPreviousData,
+ reconcile: 'id' as const,
};
}
@@ -82,6 +83,9 @@ function visibleCalendarsQueryOptions(enabled: boolean) {
refetchInterval: outlookCalendarRefetchInterval,
enabled,
placeholderData: keepPreviousData,
+ // Polls return new objects for unchanged calendars. Without reconciling,
+ // an open calendar picker rebuilds its rows and loses keyboard focus.
+ reconcile: 'id' as const,
};
}