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
feat(calendar): scope recurring event edits to this or all events (#6347)
gbirman7f6620fca6d1
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.tsx b/apps/web/src/features/calendar/components/composer/EventForm.tsxindex 092a226f96..440349b5e3 100644--- a/apps/web/src/features/calendar/components/composer/EventForm.tsx+++ b/apps/web/src/features/calendar/components/composer/EventForm.tsx@@ -1,7 +1,14 @@import { MarkdownTextarea } from '@core/component/LexicalMarkdown/component/core/MarkdownTextarea';import SpinnerIcon from '@phosphor/spinner.svg';+import type { CalendarUpdateScope } from '@service-email/client';import { Button, cn, Layer } from '@ui';-import { createEffect, createUniqueId, Show } from 'solid-js';+import {+ createEffect,+ createSignal,+ createUniqueId,+ For,+ Show,+} from 'solid-js';import {calendarDescriptionToEditorHtml,exportCalendarDescription,@@ -38,9 +45,21 @@ export interface EventFormProps {onCalendarChange?: (calendarId: string, color: string) => void;onDirtyChange?: (dirty: boolean) => void;onCancel: () => void;- onSubmit: (values: EventEditorSubmitValues) => void;+ onSubmit: (+ values: EventEditorSubmitValues,+ scope?: CalendarUpdateScope+ ) => void;}+/** Whether edits to a recurring event patch one occurrence or the whole series. */+const RECURRING_EDIT_SCOPE_OPTIONS = [+ { scope: 'this_event', label: 'This event' },+ { scope: 'all', label: 'All events' },+] as const satisfies readonly {+ scope: CalendarUpdateScope;+ label: string;+}[];+/** Create/edit event form laid out like the standalone task composer. */export function EventForm(props: EventFormProps) {const formId = createUniqueId();@@ -53,6 +72,10 @@ export function EventForm(props: EventFormProps) {const isEdit = () => props.isEdit ?? false;const formIsDisabled = () => props.pending || props.disabled === true;+ // Recurring edits default to the whole series, matching the long-standing+ // behavior; "this event" writes a single-occurrence exception.+ const [editScope, setEditScope] = createSignal<CalendarUpdateScope>('all');+// An invalid range already speaks for itself; only one line shows at a time.const pastEventWarning = () =>controller.dateRangeError() ? undefined : controller.pastEventWarning();@@ -94,7 +117,10 @@ export function EventForm(props: EventFormProps) {const submit = () => {const values = controller.submitValues();if (!values || formIsDisabled()) return;- props.onSubmit(values);+ props.onSubmit(+ values,+ props.showRecurringEditNotice ? editScope() : undefined+ );};return (@@ -221,7 +247,11 @@ export function EventForm(props: EventFormProps) {value={controller.selectedRecurrenceOption()}onChange={controller.changeRecurrenceChoice}disabled={formIsDisabled()}- readOnly={fieldIsReadOnly('recurrence')}+ // A single occurrence has no recurrence rule of its own, so the+ // recurrence cannot be edited while the scope is one event.+ readOnly={+ fieldIsReadOnly('recurrence') || editScope() === 'this_event'+ }/><Show when={!isOutOfOffice()}><EventComposerGuestsPill@@ -314,7 +344,9 @@ export function EventForm(props: EventFormProps) {value={controller.customConfig()}start={controller.startForRecurrence()}allDay={state().allDay}- disabled={fieldIsDisabled('recurrence')}+ disabled={+ fieldIsDisabled('recurrence') || editScope() === 'this_event'+ }onChange={controller.setCustomConfig}/></div>@@ -324,9 +356,26 @@ export function EventForm(props: EventFormProps) {<div class="flex shrink-0 items-center justify-end gap-3"><Show when={props.showRecurringEditNotice}>- <p class="mr-auto text-xs text-ink-extra-muted">- Changes apply to all occurrences- </p>+ <div+ role="radiogroup"+ aria-label="Apply changes to"+ class="mr-auto flex items-center gap-3 text-xs text-ink-muted"+ >+ <For each={RECURRING_EDIT_SCOPE_OPTIONS}>+ {(option) => (+ <label class="flex items-center gap-1.5">+ <input+ type="radio"+ name="event-edit-scope"+ checked={editScope() === option.scope}+ onChange={() => setEditScope(option.scope)}+ disabled={formIsDisabled()}+ />+ {option.label}+ </label>+ )}+ </For>+ </div></Show><Buttontype="button"diff --git a/apps/web/src/features/calendar/hooks/use-event-editor.ts b/apps/web/src/features/calendar/hooks/use-event-editor.tsindex 4f1da4596c..c97ec73cb4 100644--- a/apps/web/src/features/calendar/hooks/use-event-editor.ts+++ b/apps/web/src/features/calendar/hooks/use-event-editor.ts@@ -5,6 +5,7 @@ import {useCreateCalendarEventMutation,useUpdateCalendarEventMutation,} from '@queries/calendar/mutations';+import type { CalendarUpdateScope } from '@service-email/client';import { type Accessor, createMemo } from 'solid-js';import {calendarEventToEditorInitialValues,@@ -113,18 +114,36 @@ export function useEventEditor(props: UseEventEditorProps) {const pending = () => create.isPending || update.isPending;- const save = (values: EventEditorSubmitValues) => {+ const save = (+ values: EventEditorSubmitValues,+ scope?: CalendarUpdateScope+ ) => {if (pending()) return;const event = props.event();if (event) {+ const effectiveScope: CalendarUpdateScope = scope ?? 'all';+ const targetsOneOccurrence = effectiveScope === 'this_event';++ // A single occurrence has no recurrence of its own, and the provider+ // rejects a recurrence-carrying patch scoped to one event, so recurrence+ // lines only travel with a whole-series edit. Under `this_event` the+ // recurrence controls are read-only, so any diff here is an incidental+ // re-serialization (e.g. a date-dependent preset regenerated by a+ // reschedule), not an intended rule change.const recurrenceChanged =+ !targetsOneOccurrence &&values.recurrenceLines !== undefined &&values.recurrenceLines.join('\n') !== initialLines().join('\n');update.mutate({eventId: event.eventId,calendarId: event.calendarId,+ scope: effectiveScope,+ recurrenceId: targetsOneOccurrence+ ? (event.recurrenceId ?? event.occurrenceKey)+ : undefined,+ occurrenceKey: targetsOneOccurrence ? event.occurrenceKey : undefined,patch: {title: values.title,time: values.time,diff --git a/apps/web/src/lib/queries/calendar/mutations.ts b/apps/web/src/lib/queries/calendar/mutations.tsindex befdb4767f..f04bd10e63 100644--- a/apps/web/src/lib/queries/calendar/mutations.ts+++ b/apps/web/src/lib/queries/calendar/mutations.ts@@ -4,6 +4,7 @@ import { type MutationCallbacks, withCallbacks } from '@queries/utils';import {type CalendarDeletionScope,type CalendarRsvpScope,+ type CalendarUpdateScope,emailClient,} from '@service-email/client';import type { CalendarEvent as CalendarEventEntity } from '@service-email/generated/schemas/calendarEvent';@@ -396,7 +397,16 @@ export interface UpdateCalendarEventArgs {eventId: string;/** Calendar whose copy of the event is patched. Omit for the canonical copy. */calendarId?: string;- patch: Omit<UpdateCalendarEventRequest, 'calendarId'>;+ /** How much of a recurring series to patch; defaults to all of it. */+ scope?: CalendarUpdateScope;+ /** Original-start key of the occurrence a scoped update targets. */+ recurrenceId?: string;+ /** Cache key of the occurrence a scoped update targets, for the optimistic update. */+ occurrenceKey?: string;+ patch: Omit<+ UpdateCalendarEventRequest,+ 'calendarId' | 'scope' | 'recurrenceId'+ >;}type UpdateCallbacks = MutationCallbacks<@@ -469,7 +479,12 @@ function applyEventPatch(return { ...item, event, occurrence };}-/** Patches event fields; recurring events update the whole series. */+/**+ * Patches event fields. A recurring event patches the whole series by+ * default; a `this_event` scope writes the patch as a single-occurrence+ * exception addressed by `recurrenceId`, so the optimistic update lands on+ * that occurrence alone.+ */export function useUpdateCalendarEventMutation(callbacks?: UpdateCallbacks) {return useMutation(() => ({mutationFn: async (args: UpdateCalendarEventArgs) =>@@ -477,6 +492,8 @@ export function useUpdateCalendarEventMutation(callbacks?: UpdateCallbacks) {emailClient.updateCalendarEvent(args.eventId, {...args.patch,calendarId: args.calendarId,+ scope: args.scope,+ recurrenceId: args.recurrenceId,})),...withCallbacks<@@ -486,10 +503,18 @@ export function useUpdateCalendarEventMutation(callbacks?: UpdateCallbacks) {CalendarMutationContext>({- onMutate: (args) =>- patchOccurrenceCaches(- patchEventItems(args.eventId, (item) => applyEventPatch(item, args))- ),+ onMutate: (args) => {+ const patchesOneOccurrence =+ args.scope === 'this_event' && args.occurrenceKey !== undefined;+ return patchOccurrenceCaches(+ patchEventItems(args.eventId, (item) =>+ patchesOneOccurrence &&+ item.occurrence.occurrenceKey !== args.occurrenceKey+ ? item+ : applyEventPatch(item, args)+ )+ );+ },onError: (_error, _args, context) => context?.rollback(),onSettled: (_data, _error, args) => {invalidateCalendarEventPreviews(args.eventId);diff --git a/apps/web/src/lib/queries/calendar/tests/mutations.test.tsx b/apps/web/src/lib/queries/calendar/tests/mutations.test.tsxindex ad1d2ee6ae..b5f81521cc 100644--- a/apps/web/src/lib/queries/calendar/tests/mutations.test.tsx+++ b/apps/web/src/lib/queries/calendar/tests/mutations.test.tsx@@ -596,4 +596,67 @@ describe('useUpdateCalendarEventMutation', () => {startsAt: '2026-08-05T09:00:00Z',});});++ it('scopes an optimistic edit to the targeted occurrence, or widens to the series', async () => {+ const keys = [+ '2026-08-04T09:00:00Z',+ '2026-08-05T09:00:00Z',+ '2026-08-06T09:00:00Z',+ ];+ const occurrence = (key: string): CalendarOccurrenceItem =>+ ({+ event: {+ id: 'event-4',+ title: 'Standup',+ description: 'series notes',+ recurrenceLines: ['RRULE:FREQ=DAILY'],+ time: { kind: 'timed', startsAt: key, endsAt: key },+ attendees: [],+ },+ occurrence: {+ eventId: 'event-4',+ occurrenceKey: key,+ recurrenceId: key,+ time: { kind: 'timed', startsAt: key, endsAt: key },+ },+ }) as unknown as CalendarOccurrenceItem;+ testQueryClient.setQueryData(+ calendarKeys.occurrences('user', viewportA).queryKey,+ { items: keys.map(occurrence), syncStatus: 'ready' }+ );+ updateCalendarEventMock.mockResolvedValue(ok({ id: 'event-4' }));+ const update = renderHook(() => useUpdateCalendarEventMutation());+ const descriptionAt = (key: string) =>+ viewportData(viewportA)?.items.find(+ (item) => item.occurrence.occurrenceKey === key+ )?.event.description;++ await update.mutateAsync({+ eventId: 'event-4',+ scope: 'this_event',+ recurrenceId: keys[1],+ occurrenceKey: keys[1],+ patch: { description: 'this day only' },+ });++ expect(descriptionAt(keys[0])).toBe('series notes');+ expect(descriptionAt(keys[1])).toBe('this day only');+ expect(descriptionAt(keys[2])).toBe('series notes');+ expect(updateCalendarEventMock).toHaveBeenCalledWith('event-4', {+ description: 'this day only',+ calendarId: undefined,+ scope: 'this_event',+ recurrenceId: keys[1],+ });++ await update.mutateAsync({+ eventId: 'event-4',+ scope: 'all',+ patch: { description: 'shared notes' },+ });++ expect(descriptionAt(keys[0])).toBe('shared notes');+ expect(descriptionAt(keys[1])).toBe('shared notes');+ expect(descriptionAt(keys[2])).toBe('shared notes');+ });});diff --git a/apps/web/src/lib/service-clients/service-email/client.ts b/apps/web/src/lib/service-clients/service-email/client.tsindex 08fe046f8a..d70f4e65d9 100644--- a/apps/web/src/lib/service-clients/service-email/client.ts+++ b/apps/web/src/lib/service-clients/service-email/client.ts@@ -57,6 +57,9 @@ export type CalendarDeletionScope = 'all' | 'this_event' | 'this_and_following';/** How much of a recurring series a calendar RSVP answers for. */export type CalendarRsvpScope = 'all' | 'this_event';+/** How much of a recurring series a calendar update applies to. */+export type CalendarUpdateScope = 'all' | 'this_event';+function emailLinkHeaders(linkId?: string): Record<string, string> | undefined {return linkId ? { [EMAIL_LINK_ID_HEADER]: linkId } : undefined;}