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 guest editors whole when the event sits low (#9058)

gbirman247b1397bab1
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index bd665bc29b..c48db0cc0d 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -43,10 +43,14 @@ beside a scrolling editor whose selection runs past its visible bottom
Event details placement has a backend-free browser regression: the desktop
popover stays beside its event when join requests arrive after it opens, and
-slides into a short window; the phone drawer shows late requests:
+slides into a short window; the phone drawer shows late requests. The same
+suite covers the Add guests and Forward invitation editors (the real
+`EventGuests` over a stand-in contact picker) on desktop and phone:
`bunx playwright test --config src/features/calendar-view/browser-test/playwright.config.ts`.
Keep the popover's `flip` limited to `left-start`: an end fallback re-places it
-above the event whenever a late section changes its height.
+above the event whenever a late section changes its height. Keep the guest
+editors' `overlap`: without it their height follows the room below the button,
+so they never overflow, never flip, and squeeze the chosen people to nothing.
The desktop app's local runtime setup (find an agent, connect, create the
agent, retry, open a session) has a backend-free browser regression over a
diff --git a/apps/web/src/features/calendar-view/browser-test/event-details.browser.e2e.ts b/apps/web/src/features/calendar-view/browser-test/event-details.browser.e2e.ts
index 36a7c21027..c77e63b4f1 100644
--- a/apps/web/src/features/calendar-view/browser-test/event-details.browser.e2e.ts
+++ b/apps/web/src/features/calendar-view/browser-test/event-details.browser.e2e.ts
@@ -2,6 +2,27 @@ import { expect, type Page, test } from '@playwright/test';
const deliverJoinRequests = (page: Page) =>
page.evaluate(() => window.calendarPreview.deliverJoinRequests());
+const deliverContacts = (page: Page) =>
+ page.evaluate(() => window.calendarPreview.deliverContacts());
+
+// The two guest editors in the attendees header share one popover (a sheet
+// on phones): Add guests for whoever may invite, Forward invitation for a
+// guest who may not.
+const GUEST_EDITORS = [
+ {
+ kind: 'add',
+ label: 'Add guests',
+ added: 'New guests',
+ action: 'Send invitations',
+ },
+ {
+ kind: 'forward',
+ label: 'Forward invitation',
+ added: 'Forward to',
+ action: 'Forward',
+ },
+] as const;
+type GuestEditor = (typeof GUEST_EDITORS)[number];
async function openDetails(page: Page, query: string) {
await page.goto(`/?${query}`);
@@ -25,6 +46,49 @@ async function box(locator: ReturnType<Page['getByRole']>) {
return { ...rect, bottom: rect.y + rect.height };
}
+async function openGuestEditor(page: Page, editor: GuestEditor, query: string) {
+ const { anchor, details } = await openDetails(
+ page,
+ `guests=${editor.kind}&${query}`
+ );
+ const trigger = details.getByRole('button', {
+ name: editor.label,
+ exact: true,
+ });
+ await trigger.click();
+ const dialog = page.getByRole('dialog', { name: editor.label });
+ await expect(dialog).toBeVisible();
+ return { anchor, trigger, dialog };
+}
+
+/** Picks two people, then checks the picker, both of them and the action are fully visible. */
+async function expectGuestEditorUsable(
+ page: Page,
+ editor: GuestEditor,
+ dialog: ReturnType<Page['getByRole']>
+) {
+ for (const name of ['Avery Park', 'Blake Chen']) {
+ await dialog.getByRole('option', { name }).click();
+ }
+ const added = dialog
+ .getByRole('list', { name: editor.added })
+ .getByRole('listitem');
+ await expect(added).toHaveCount(2);
+ await expect(dialog.getByPlaceholder('Add guests...')).toBeInViewport({
+ ratio: 1,
+ });
+ for (const row of await added.all()) {
+ await expect(row).toBeInViewport({ ratio: 1 });
+ }
+ await expect(
+ dialog.getByRole('button', { name: editor.action, exact: true })
+ ).toBeInViewport({ ratio: 1 });
+ const viewport = page.viewportSize();
+ const editorBox = await box(dialog);
+ expect(editorBox.y).toBeGreaterThanOrEqual(0);
+ expect(editorBox.bottom).toBeLessThanOrEqual(viewport?.height ?? 0);
+}
+
test.describe('desktop popover', () => {
test.skip(({ isMobile }) => isMobile, 'The phone shows a drawer');
@@ -97,6 +161,88 @@ test.describe('desktop popover', () => {
});
});
+test.describe('desktop guest editors', () => {
+ test.skip(({ isMobile }) => isMobile, 'The phone shows a sheet');
+
+ for (const editor of GUEST_EDITORS) {
+ test.describe(editor.label, () => {
+ test.describe('tall window', () => {
+ test.use({ viewport: { width: 1280, height: 1000 } });
+
+ test('moves above its button instead of squeezing when contacts arrive after it opens', async ({
+ page,
+ }) => {
+ // Measure the editor before and after its suggestions arrive, and
+ // where its button sits relative to the event.
+ const measured = await openGuestEditor(page, editor, 'contacts=late');
+ const empty = (await box(measured.dialog)).height;
+ await deliverContacts(page);
+ await expect
+ .poll(async () => (await box(measured.dialog)).height)
+ .toBeGreaterThan(empty + 100);
+ const full = (await box(measured.dialog)).height;
+ const buttonBottom =
+ (await box(measured.trigger)).bottom -
+ (await box(measured.anchor)).y;
+
+ // Put the event where the editor fits below its button until the
+ // suggestions arrive, with room above for the whole editor.
+ const room = Math.round((empty + full) / 2);
+ const top = Math.round(1000 - 8 - 4 - room - buttonBottom);
+ const { anchor, trigger, dialog } = await openGuestEditor(
+ page,
+ editor,
+ `contacts=late&top=${top}`
+ );
+ const button = await box(trigger);
+ expect(
+ Math.abs(button.bottom - (await box(anchor)).y - buttonBottom)
+ ).toBeLessThanOrEqual(1);
+ expect((await box(dialog)).y).toBeGreaterThan(button.bottom);
+
+ await deliverContacts(page);
+ await expect
+ .poll(async () => (await box(dialog)).bottom)
+ .toBeLessThan(button.y);
+ await expectGuestEditorUsable(page, editor, dialog);
+ });
+ });
+
+ test.describe('short window', () => {
+ test.use({ viewport: { width: 1280, height: 560 } });
+
+ test('slides into view beside an event near the bottom', async ({
+ page,
+ }) => {
+ const { dialog } = await openGuestEditor(page, editor, 'top=470');
+ await expectGuestEditorUsable(page, editor, dialog);
+ });
+ });
+ });
+ }
+});
+
+test('the phone sheets keep the picker, the chosen people and the action in view', async ({
+ page,
+ isMobile,
+}) => {
+ test.skip(!isMobile, 'Desktop shows a popover');
+ for (const editor of GUEST_EDITORS) {
+ await page.goto(`/?guests=${editor.kind}`);
+ await page
+ .getByRole('button', { name: 'Planning review', exact: true })
+ .click();
+ const drawer = page.getByRole('dialog', { name: 'Planning review' });
+ await expect(drawer).toBeVisible();
+ await drawer
+ .getByRole('button', { name: editor.label, exact: true })
+ .click();
+ const sheet = page.getByRole('dialog', { name: editor.label });
+ await expect(sheet).toBeVisible();
+ await expectGuestEditorUsable(page, editor, sheet);
+ }
+});
+
test('the phone drawer shows join requests that arrive after it opens', async ({
page,
isMobile,
diff --git a/apps/web/src/features/calendar-view/browser-test/preview-adapters.tsx b/apps/web/src/features/calendar-view/browser-test/preview-adapters.tsx
index 62161eb41f..cb69d8080e 100644
--- a/apps/web/src/features/calendar-view/browser-test/preview-adapters.tsx
+++ b/apps/web/src/features/calendar-view/browser-test/preview-adapters.tsx
@@ -1,15 +1,23 @@
import { Avatar } from '@ui';
-import { createSignal } from 'solid-js';
-import { EventAttendeesSection } from '../../calendar/components/EventDetails';
-import type { CalendarEvent } from '../../calendar/types';
+import { createMemo, createSignal, For, Show } from 'solid-js';
+import {
+ FORWARD_INVITATION_INSTEAD,
+ GUEST_INVITES_RESTRICTED,
+} from '../../calendar/utils/event-guest-editing';
export { sanitizeCalendarDescription } from '../../calendar/utils/calendar-description-sanitizer';
export const parseMacroAppLink = () => undefined;
-export const recipientEntityMapper = () => () => undefined;
+export const recipientEntityMapper =
+ <K extends string>(kind: K) =>
+ <T extends { id: string }>(data: T) => ({ kind, data, id: data.id });
+export const idToEmail = (id: string) => id.replace(/^macro\|/, '');
-// Sample services for the event details overlays. The popover, drawer, and
-// join-requests section render their real UI; the requests arrive when the
-// test calls `window.calendarPreview.deliverJoinRequests()`.
+// Sample services for the event details overlays. The popover, drawer,
+// join-requests section and guest editors render their real UI; the requests
+// arrive when the test calls `window.calendarPreview.deliverJoinRequests()`,
+// and with `?contacts=late` the guest picker's contacts arrive on
+// `window.calendarPreview.deliverContacts()`.
+const params = new URLSearchParams(location.search);
export type CalendarJoinRequest = {
id: string;
eventId: string;
@@ -30,18 +38,35 @@ const sampleRequest: CalendarJoinRequest = {
const [joinRequests, setJoinRequests] = createSignal<
CalendarJoinRequest[] | undefined
->(
- new URLSearchParams(location.search).get('requests') === 'loaded'
- ? [sampleRequest]
- : undefined
+>(params.get('requests') === 'loaded' ? [sampleRequest] : undefined);
+const sampleContacts = [
+ 'Avery Park',
+ 'Blake Chen',
+ 'Casey Diaz',
+ 'Devon Price',
+ 'Emery Stone',
+ 'Finley Ross',
+ 'Harper Quinn',
+ 'Jordan Wells',
+].map((name) => {
+ const email = `${name.split(' ')[0]?.toLowerCase()}@example.com`;
+ return { id: `macro|${email}`, email, name };
+});
+const [contacts, setContacts] = createSignal(
+ params.get('contacts') === 'late' ? [] : sampleContacts
);
+
declare global {
interface Window {
- calendarPreview: { deliverJoinRequests: () => void };
+ calendarPreview: {
+ deliverJoinRequests: () => void;
+ deliverContacts: () => void;
+ };
}
}
window.calendarPreview = {
deliverJoinRequests: () => setJoinRequests([sampleRequest]),
+ deliverContacts: () => setContacts(sampleContacts),
};
function announce(message: string) {
@@ -94,17 +119,42 @@ export const useOpenEventComposer = () => () =>
announce('Edit event · Preview only');
export const useForwardEventEmail = () => () =>
announce('Forward event · Preview only');
-export const createGuestInviteController = () => ({
- editorOpen: () => false,
- forwardEditorOpen: () => false,
-});
+
+// `?guests=add` offers Add guests and `?guests=forward` offers Forward
+// invitation; sending closes the editor and announces the recipients.
+const guestAction = params.get('guests');
+export function createGuestInviteController() {
+ const [editorOpen, setEditorOpen] = createSignal(false);
+ const [forwardEditorOpen, setForwardEditorOpen] = createSignal(false);
+ return {
+ editorOpen,
+ setEditorOpen,
+ forwardEditorOpen,
+ setForwardEditorOpen,
+ canInvite: () => guestAction === 'add',
+ canForward: () => guestAction === 'forward',
+ restrictedReason: () =>
+ guestAction === 'forward'
+ ? `${GUEST_INVITES_RESTRICTED} ${FORWARD_INVITATION_INSTEAD}`
+ : undefined,
+ send: (invitation: { guests: { email: string }[] }) => {
+ setEditorOpen(false);
+ announce(
+ `Invited ${invitation.guests.map((guest) => guest.email).join(', ')}`
+ );
+ },
+ forward: (forward: { recipients: { email: string }[] }) => {
+ setForwardEditorOpen(false);
+ announce(
+ `Forwarded to ${forward.recipients.map((guest) => guest.email).join(', ')}`
+ );
+ },
+ };
+}
export const useCalendarGuestInvitesFlag = () => () => false;
export const useCalendarInvitationForwardFlag = () => () => false;
export const useCalendarMeetingNotesFlag = () => () => false;
export const CalendarMeetingNotes = () => null;
-export const EventGuests = (props: { event: CalendarEvent }) => (
- <EventAttendeesSection attendees={props.event.attendees} />
-);
export const TeamEventDetails = () => null;
export const OutlookRsvpAction = () => null;
export const copyCalendarEventMention = () =>
@@ -131,8 +181,83 @@ const names: Record<string, string> = {
'[email protected]': 'Sam Lee',
};
+export const useContacts = () => contacts;
+export const useOpenEventEmail = () => () =>
+ announce('Email guests · Preview only');
+export const copyGuestEmails = () =>
+ announce('Copy guest emails · Preview only');
+
+/**
+ * The guest picker's search field and suggestion list, laid out like the
+ * real selector (a field over a list capped at 192px) so the editor around
+ * it sizes the same, over the sample contacts instead of search.
+ */
+export function PropertyEntitySelector(props: {
+ config: {
+ placeholder?: string;
+ users?: () => { id: string; email: string; name?: string }[];
+ excludedIds?: () => ReadonlySet<string>;
+ };
+ selectedOptions: () => Set<string>;
+ setSelectedOptions: (options: Set<string>) => void;
+}) {
+ const [query, setQuery] = createSignal('');
+ const matches = createMemo(() =>
+ (props.config.users?.() ?? []).filter(
+ (user) =>
+ !props.config.excludedIds?.().has(user.id) &&
+ `${user.name ?? ''} ${user.email}`
+ .toLowerCase()
+ .includes(query().toLowerCase())
+ )
+ );
+ return (
+ <div>
+ <div class="flex w-full items-center gap-2 border-b border-edge-muted px-2 py-2">
+ <input
+ class="w-full caret-accent"
+ type="text"
+ value={query()}
+ onInput={(event) => setQuery(event.currentTarget.value)}
+ placeholder={props.config.placeholder}
+ />
+ </div>
+ <Show when={matches().length > 0}>
+ <div class="p-1.5">
+ <div
+ role="listbox"
+ aria-label="Suggestions"
+ class="max-h-48 overflow-y-auto"
+ >
+ <For each={matches()}>
+ {(user) => (
+ <button
+ type="button"
+ role="option"
+ aria-selected={false}
+ class="flex w-full min-w-0 items-center rounded-lg p-1.5 px-2 text-left text-ink"
+ onClick={() =>
+ props.setSelectedOptions(
+ new Set([...props.selectedOptions(), user.id])
+ )
+ }
+ >
+ <span class="truncate">{user.name ?? user.email}</span>
+ </button>
+ )}
+ </For>
+ </div>
+ </div>
+ </Show>
+ </div>
+ );
+}
export const emailToMacroId = (email: string) => email;
-export const getDisplayName = (id?: string) => names[id ?? ''] ?? '';
+export const getDisplayName = (id?: string) =>
+ names[id ?? ''] ??
+ sampleContacts.find((contact) => contact.id === id || contact.email === id)
+ ?.name ??
+ '';
export const getInitialsFromName = (name: string) =>
name
.split(' ')
diff --git a/apps/web/src/features/calendar-view/browser-test/vite.config.ts b/apps/web/src/features/calendar-view/browser-test/vite.config.ts
index 2398a3e960..47ca32fa28 100644
--- a/apps/web/src/features/calendar-view/browser-test/vite.config.ts
+++ b/apps/web/src/features/calendar-view/browser-test/vite.config.ts
@@ -22,7 +22,9 @@ const previewImports = [
'@app/features/calendar/hooks/create-guest-invite-controller',
'@app/features/calendar/hooks/use-calendar-ui-flag',
'@app/features/calendar-notes/calendar-meeting-notes',
- '@app/features/calendar-view/components/EventGuests',
+ '@app/features/calendar-view/components/use-open-event-email',
+ '@app/features/calendar-view/copy-guest-emails',
+ '@property/editors/selectors/PropertyEntitySelector',
'@app/features/calendar-team/components/team-event-details',
'@app/features/calendar/views/event-replacement',
'@app/features/calendar-view/copy-event-mention',
@@ -37,7 +39,10 @@ const previewImports = [
'../../calendar/hooks/create-calendar-rsvp-controller',
];
-/** The real event details popover and drawer, with sample data and preview services. */
+/**
+ * The real event details popover and drawer, and their guest editors, with
+ * sample data and preview services.
+ */
export default defineConfig({
root: directory,
cacheDir: `${directory}/.vite`,
diff --git a/apps/web/src/features/calendar-view/components/EventGuests.tsx b/apps/web/src/features/calendar-view/components/EventGuests.tsx
index d861382f37..286bb45b25 100644
--- a/apps/web/src/features/calendar-view/components/EventGuests.tsx
+++ b/apps/web/src/features/calendar-view/components/EventGuests.tsx
@@ -246,8 +246,14 @@ function GuestEditorAction(props: {
onOpenChange={props.onOpenChange}
placement="bottom-end"
gutter={4}
- flip
+ // Flip only to the other side, and let overlap slide it up over its
+ // button when neither side fits. Overlap also sizes the editor to
+ // the whole window rather than the room below: sized to that room,
+ // it never overflowed, so it never flipped, and suggestions that
+ // arrived after it opened squeezed the chosen people to nothing.
+ flip="top-end"
slide
+ overlap
>
<Popover.Trigger
as={Button}
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index f697036e33..d3a374500f 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -548,6 +548,15 @@ that load after it opens (join requests, meeting notes) therefore never move it
from below the event to above it. Check placement with an event low in a tall
window, a short window, and a pending join request; the backend-free regression
is `apps/web/src/features/calendar-view/browser-test/playwright.config.ts`.
+The `Add guests` and `Forward invitation` editors in the attendees header open
+below their button, right-aligned with it, and move above it when they don't
+fit below, including when the picker's suggestions arrive after the editor
+opens; when neither side has room they slide over the button to stay in the
+window. The picker, the people chosen and the send button stay visible at every
+event position and window height. The same regression covers both editors in a
+tall and a short window (`?guests=add` or `?guests=forward`, with
+`?contacts=late` delivering the picker's contacts on
+`window.calendarPreview.deliverContacts()`) and their phone sheets.
The `New event` composer (also opened by dragging a range on the grid) has an `Event kind`
pill choosing between `Event` and `Out of office`. Picking `Out of office` hides the guests,