Skip to content

Commit 536cf0f

Browse files
authored
fix(web): preserve timed event stack order (#1844)
1 parent bfec7b6 commit 536cf0f

5 files changed

Lines changed: 23 additions & 20 deletions

File tree

packages/web/src/views/Day/components/Calendar/DayCalendarEventCards.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const DayTimedCalendarEvent = ({
109109
visibleDates,
110110
}: DayTimedEventCardProps) => {
111111
const isRegistered = Boolean(event._id) && !isPending && !isPlaceholder;
112-
const isDeck = Boolean(deckLayout) && !isActiveDraft;
112+
const isDeck = Boolean(deckLayout);
113113
const [isFocused, setIsFocused] = useState(false);
114114
const registrationRef = useDayEventRegistrationRef({
115115
eventId: event._id,
@@ -135,7 +135,7 @@ export const DayTimedCalendarEvent = ({
135135
const highlight = `inset 0 1px 0 rgba(255,255,255,${isFocused ? 0.1 : 0.07})`;
136136
return `${ring}, ${drop}, ${highlight}`;
137137
})();
138-
const shouldFloatAboveDeck = isActiveDraft || (isDeck && isFocused);
138+
const shouldFloatAboveDeck = isActiveDraft && !isDeck;
139139
const position = getDayTimedEventPosition({
140140
deckLayout,
141141
event,

packages/web/src/views/Day/components/Calendar/DayCalendarGrid.test.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ describe("DayCalendarGrid", () => {
241241
);
242242
});
243243

244-
it("raises a focused Day deck card above its group-mates", () => {
244+
it("keeps a focused Day deck card in its fan-out stack", () => {
245245
setDayEvents([
246246
createTimedEvent({
247247
_id: "back",
@@ -260,17 +260,18 @@ describe("DayCalendarGrid", () => {
260260
renderDayCalendarGrid();
261261

262262
const back = screen.getByRole("button", { name: /back overlap/i });
263+
const initialBackZIndex = Number(back.style.zIndex);
263264

264-
expect(Number(back.style.zIndex)).toBeLessThan(ZIndex.MAX);
265+
expect(initialBackZIndex).toBeLessThan(ZIndex.MAX);
265266

266267
fireEvent.focus(back);
267-
expect(Number(back.style.zIndex)).toBe(ZIndex.MAX);
268+
expect(Number(back.style.zIndex)).toBe(initialBackZIndex);
268269

269270
fireEvent.blur(back);
270-
expect(Number(back.style.zIndex)).toBeLessThan(ZIndex.MAX);
271+
expect(Number(back.style.zIndex)).toBe(initialBackZIndex);
271272
});
272273

273-
it("raises a clicked overlapping Day event above its group-mates without widening it", async () => {
274+
it("keeps a clicked overlapping Day event in its fan-out stack without widening it", async () => {
274275
setDayEvents([
275276
createTimedEvent({
276277
_id: "back",
@@ -291,10 +292,11 @@ describe("DayCalendarGrid", () => {
291292
const back = screen.getByRole("button", { name: /back overlap/i });
292293
const front = screen.getByRole("button", { name: /front overlap/i });
293294
const initialBackWidth = parseFloat(back.style.width);
295+
const initialBackZIndex = Number(back.style.zIndex);
294296
const frontWidth = parseFloat(front.style.width);
295297

296298
expect(initialBackWidth).toBe(frontWidth);
297-
expect(Number(back.style.zIndex)).toBeLessThan(ZIndex.MAX);
299+
expect(initialBackZIndex).toBeLessThan(ZIndex.MAX);
298300

299301
fireEvent.pointerDown(back, {
300302
button: 0,
@@ -312,7 +314,7 @@ describe("DayCalendarGrid", () => {
312314

313315
await waitFor(() => {
314316
expect(getDraft()?._id).toBe("back");
315-
expect(Number(back.style.zIndex)).toBe(ZIndex.MAX);
317+
expect(Number(back.style.zIndex)).toBe(initialBackZIndex);
316318
expect(parseFloat(back.style.width)).toBe(frontWidth);
317319
});
318320
});

packages/web/src/views/Week/components/Draft/grid/GridDraft.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { type PropsWithChildren, type Ref, useState } from "react";
44
import { Origin, Priorities } from "@core/constants/core.constants";
55
import dayjs from "@core/util/date/dayjs";
66
import { CALENDAR_DECK_MIN_WIDTH } from "@web/common/calendar-grid/calendarGrid.constants";
7-
import { ZIndex } from "@web/common/constants/web.constants";
87
import { type Schema_GridEvent } from "@web/common/types/web.event.types";
98
import { gridEventDefaultPosition } from "@web/common/utils/event/event.util";
109
import { DraftContext } from "@web/views/Week/components/Draft/context/DraftContext";
@@ -239,17 +238,19 @@ describe("GridDraft keyboard focus", () => {
239238
});
240239
});
241240

242-
it("keeps an active overlapping saved draft at its stacked width while raising it", () => {
241+
it("keeps an active overlapping saved draft at its stacked width and stack order", () => {
242+
const deckLayout = { groupSize: 2, order: 0 };
243+
243244
renderGridDraft({
244-
deckLayout: { groupSize: 2, order: 0 },
245+
deckLayout,
245246
});
246247

247248
const draftBlock = screen.getByRole("button", {
248249
name: /Timed event: Planning/,
249250
});
250251

251252
expect(draftBlock.style.width).toBe(`${CALENDAR_DECK_MIN_WIDTH}px`);
252-
expect(Number(draftBlock.style.zIndex)).toBe(ZIndex.MAX);
253+
expect(Number(draftBlock.style.zIndex)).toBe(deckLayout.order + 1);
253254
});
254255

255256
it("submits the draft from title Enter without focusing the draft block", async () => {

packages/web/src/views/Week/components/Event/Grid/GridEvent/GridEvent.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const GridEventBase = (
6969
const isPlaceholder = displayMode === "placeholder";
7070
const isResizing = motionMode === "resizing";
7171
const event = _event;
72-
const isDeck = Boolean(deckLayout) && !isDraft;
72+
const isDeck = Boolean(deckLayout);
7373
const [isFocused, setIsFocused] = useState(false);
7474
const shouldAcknowledgeCommit =
7575
useSomedayCommitAcknowledgement(event._id) &&
@@ -104,8 +104,7 @@ const GridEventBase = (
104104
? basePosition
105105
: applyCalendarTimedEventDisplayPosition(basePosition, deckLayout);
106106

107-
const shouldFloatAboveDeck =
108-
isDraft || isDragging || isResizing || (isDeck && isFocused);
107+
const shouldFloatAboveDeck = isDragging || isResizing || (isDraft && !isDeck);
109108
const zIndex = shouldFloatAboveDeck
110109
? ZIndex.MAX
111110
: (position.zIndex ?? ZIndex.LAYER_1);

packages/web/src/views/Week/components/Grid/MainGrid/MainGrid.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ describe("saved Week event ownership", () => {
637637
expect(Number(solo.style.zIndex)).toBe(ZIndex.LAYER_1);
638638
});
639639

640-
it("raises a focused deck card above its group-mates", () => {
640+
it("keeps a focused deck card in its fan-out stack", () => {
641641
const store = createStore([
642642
createSavedEvent({
643643
_id: "back",
@@ -665,13 +665,14 @@ describe("saved Week event ownership", () => {
665665
);
666666

667667
const back = screen.getByRole("button", { name: /back overlap/i });
668-
expect(Number(back.style.zIndex)).toBeLessThan(ZIndex.MAX);
668+
const initialBackZIndex = Number(back.style.zIndex);
669+
expect(initialBackZIndex).toBeLessThan(ZIndex.MAX);
669670

670671
fireEvent.focus(back);
671-
expect(Number(back.style.zIndex)).toBe(ZIndex.MAX);
672+
expect(Number(back.style.zIndex)).toBe(initialBackZIndex);
672673

673674
fireEvent.blur(back);
674-
expect(Number(back.style.zIndex)).toBeLessThan(ZIndex.MAX);
675+
expect(Number(back.style.zIndex)).toBe(initialBackZIndex);
675676
});
676677

677678
it("keeps saved timed mouse and resize events out of the draft motion owner", () => {

0 commit comments

Comments
 (0)