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 event's length when the composer's start moves (#8642)

gbirmana3a1c3409781
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.test.tsx b/apps/web/src/features/calendar/components/composer/EventForm.test.tsx
index 40a63a3e11..7de9730b5f 100644
--- a/apps/web/src/features/calendar/components/composer/EventForm.test.tsx
+++ b/apps/web/src/features/calendar/components/composer/EventForm.test.tsx
@@ -2,7 +2,7 @@
* @vitest-environment jsdom
*/
-import { cleanup, render, screen } from '@solidjs/testing-library';
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
import userEvent from '@testing-library/user-event';
import { type ComponentProps, createMemo } from 'solid-js';
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
@@ -207,3 +207,34 @@ it('returns guest permissions to the stored ones when an edit targets one occurr
expect((seeGuests as HTMLInputElement).checked).toBe(true);
expect((seeGuests as HTMLInputElement).disabled).toBe(true);
});
+
+it('moves the end with the start until the end is picked', async () => {
+ const user = userEvent.setup();
+ showForm();
+ const start = screen.getByRole('button', {
+ name: 'Edit event start date and time',
+ });
+ const end = screen.getByRole('button', {
+ name: 'Edit event end date and time',
+ });
+ const pickTime = async (
+ trigger: HTMLElement,
+ label: string,
+ value: string
+ ) => {
+ await user.click(trigger);
+ fireEvent.input(screen.getByLabelText(label), { target: { value } });
+ await user.keyboard('{Escape}');
+ };
+
+ await pickTime(start, 'Start time', '14:00');
+ expect(start.textContent).toContain('2:00');
+ expect(end.textContent).toContain('3:00');
+
+ await pickTime(end, 'End time', '17:00');
+ await pickTime(start, 'Start time', '15:00');
+ expect(end.textContent).toContain('5:00');
+ expect(
+ screen.queryByText('End time must be after the start time.')
+ ).toBeNull();
+});
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.tsx b/apps/web/src/features/calendar/components/composer/EventForm.tsx
index bafc25aa69..143ee244f4 100644
--- a/apps/web/src/features/calendar/components/composer/EventForm.tsx
+++ b/apps/web/src/features/calendar/components/composer/EventForm.tsx
@@ -215,7 +215,7 @@ export function EventForm(props: EventFormProps) {
end={state().end}
allDay={state().allDay}
onStartChange={controller.setStart}
- onEndChange={(end) => controller.setField('end', end)}
+ onEndChange={controller.setEnd}
onAllDayChange={controller.setAllDay}
startDisabled={fieldIsDisabled('start')}
endDisabled={fieldIsDisabled('end')}
diff --git a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts
index 7c58668448..0cba6e64c6 100644
--- a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts
+++ b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts
@@ -650,3 +650,72 @@ it('allows unrelated edits to an existing Teams meeting on a calendar without co
expect(controller.canSave()).toBe(true);
expect(controller.submitValues()?.conference).toBeUndefined();
});
+
+describe('moving the start', () => {
+ const timed = {
+ allDay: false,
+ start: '2030-01-01T10:00',
+ end: '2030-01-01T11:30',
+ };
+
+ it('carries the end along, keeping the event’s length', () => {
+ const controller = controllerFor(timed);
+ controller.setStart('2030-01-01T14:00');
+ expect(controller.state()).toMatchObject({
+ start: '2030-01-01T14:00',
+ end: '2030-01-01T15:30',
+ });
+ controller.setStart('2030-01-02T23:00');
+ expect(controller.state().end).toBe('2030-01-03T00:30');
+ expect(controller.dateRangeError()).toBeUndefined();
+ });
+
+ it('leaves an end the user picked in this edit where they put it', () => {
+ const controller = controllerFor(timed);
+ controller.setEnd('2030-01-01T17:00');
+ controller.setStart('2030-01-01T15:00');
+ expect(controller.state()).toMatchObject({
+ start: '2030-01-01T15:00',
+ end: '2030-01-01T17:00',
+ });
+ });
+
+ it('does the same for all-day dates', () => {
+ const allDay = { allDay: true, start: '2030-01-01', end: '2030-01-02' };
+ const following = controllerFor(allDay);
+ following.setStart('2030-01-05');
+ expect(following.state().end).toBe('2030-01-06');
+
+ const picked = controllerFor(allDay);
+ picked.setEnd('2030-01-04');
+ picked.setStart('2030-01-03');
+ expect(picked.state().end).toBe('2030-01-04');
+ });
+
+ it('follows the start again once the times are rewritten', () => {
+ const toggled = controllerFor(timed);
+ toggled.setEnd('2030-01-01T17:00');
+ toggled.setAllDay(true);
+ toggled.setStart('2030-01-03');
+ expect(toggled.state()).toMatchObject({
+ start: '2030-01-03',
+ end: '2030-01-03',
+ });
+
+ const reset = controllerFor(timed, { isEdit: true });
+ reset.setEnd('2030-01-01T17:00');
+ reset.resetDetails();
+ reset.setStart('2030-01-01T12:00');
+ expect(reset.state().end).toBe('2030-01-01T13:30');
+ });
+
+ it('keeps the end of a range that has no length to keep', () => {
+ const controller = controllerFor({
+ allDay: false,
+ start: '2030-01-01T12:00',
+ end: '2030-01-01T09:00',
+ });
+ controller.setStart('2030-01-01T08:00');
+ expect(controller.state().end).toBe('2030-01-01T09:00');
+ });
+});
diff --git a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts
index 5952e76034..b0c5450b6c 100644
--- a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts
+++ b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts
@@ -25,6 +25,7 @@ import {
guestEmail,
initialGuestOptions,
moveAllDayRange,
+ moveTimedRange,
PAST_EVENT_GUESTS_WARNING,
type SelectedEventEditorGuest,
} from './event-form-model';
@@ -421,13 +422,33 @@ export function createCalendarEventFormController(
replaceState(value);
};
- const setStart = (start: string) =>
+ // Until the end is picked in this edit it follows the start, keeping the
+ // event's length; once picked, it stays where the user put it.
+ let endChosen = false;
+
+ const setStart = (start: string) => {
+ const current = state();
+ if (endChosen) {
+ replaceState({ ...current, start });
+ return;
+ }
replaceState(
- state().allDay ? moveAllDayRange(state(), start) : { ...state(), start }
+ current.allDay
+ ? moveAllDayRange(current, start)
+ : moveTimedRange(current, start)
);
+ };
+
+ const setEnd = (end: string) => {
+ if (end === state().end) return;
+ endChosen = true;
+ setField('end', end);
+ };
- const setAllDay = (allDay: boolean) =>
+ const setAllDay = (allDay: boolean) => {
+ endChosen = false;
replaceState(convertTimesForAllDay(state(), allDay));
+ };
const setEventKind = (kind: EventEditorEventKind) => {
if (kind === eventKind()) return;
@@ -588,6 +609,7 @@ export function createCalendarEventFormController(
*/
const resetDetails = () => {
const initial = initialValue();
+ endChosen = false;
batch(() => {
setState({
...state(),
@@ -610,6 +632,7 @@ export function createCalendarEventFormController(
const replaceFromExternal = (next: EventEditorInitialValues) => {
const cloned = cloneValue(next);
const guests = initialGuestOptions(next.guests, options.guestOptions());
+ endChosen = false;
batch(() => {
setInitialValue(cloned);
setState(cloned);
@@ -636,6 +659,7 @@ export function createCalendarEventFormController(
setReminderMinutes,
setField,
setStart,
+ setEnd,
setAllDay,
eventKind,
isOutOfOffice,
diff --git a/apps/web/src/features/calendar/components/composer/event-form-model.ts b/apps/web/src/features/calendar/components/composer/event-form-model.ts
index 6731eefc17..4b6b1a7423 100644
--- a/apps/web/src/features/calendar/components/composer/event-form-model.ts
+++ b/apps/web/src/features/calendar/components/composer/event-form-model.ts
@@ -16,9 +16,12 @@ import type { GuestPolicy } from '@service-storage/generated/schemas/guestPolicy
import {
addDays,
addHours,
+ addMinutes,
differenceInCalendarDays,
+ differenceInMinutes,
endOfDay,
format,
+ isValid,
parseISO,
startOfHour,
} from 'date-fns';
@@ -439,6 +442,30 @@ export function moveAllDayRange(
};
}
+/**
+ * Moves a timed range's end with its start, keeping the duration, as Google
+ * Calendar does. A range with no positive duration (incomplete, or already
+ * ending before it starts) keeps its end, since there is nothing to keep.
+ */
+export function moveTimedRange(
+ state: EventEditorInitialValues,
+ nextStart: string
+): EventEditorInitialValues {
+ const start = parseISO(nextStart);
+ const duration = differenceInMinutes(
+ parseISO(state.end),
+ parseISO(state.start)
+ );
+ if (!isValid(start) || !Number.isFinite(duration) || duration <= 0) {
+ return { ...state, start: nextStart };
+ }
+ return {
+ ...state,
+ start: nextStart,
+ end: format(addMinutes(start, duration), DATETIME_VALUE),
+ };
+}
+
export interface CreateEventEditorStateOptions {
initialValues: EventEditorInitialValues;
state: Accessor<EventEditorInitialValues>;
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index e8927a8f5a..b603cd6ac1 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -26,6 +26,10 @@ recurrence, Guests, conferencing, Location, and Notifications open on the first
click from the title field and accept changes without closing the composer.
Open the start/end date picker and its nested time list; selecting a time keeps
the date picker open. Escape dismisses the active menu before the composer.
+Moving the start date or time moves the end with it, keeping the event's length
+(all-day dates keep their day count), until the end is picked in the same edit;
+after that the end stays put, and a start past it shows the end-before-start
+error.
The path selects the Month, Week, or Day period, and choosing another period updates
that path. Calendar navigation defaults to Day on phones and Week on desktop; the most