Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(planner): keep the date whole and rename the title where it stands with the date first

Maurice4003769a5c84
diff --git a/client/src/components/Planner/DayDetailPanel.dateFirst.test.tsx b/client/src/components/Planner/DayDetailPanel.dateFirst.test.tsx
new file mode 100644
index 000000000..1ae8019a7
--- /dev/null
+++ b/client/src/components/Planner/DayDetailPanel.dateFirst.test.tsx
@@ -0,0 +1,75 @@
+// FE-PLANNER-DAYDETAIL-DF-001 to FE-PLANNER-DAYDETAIL-DF-002
+// The day panel's heading with "date first in day headings" on (#2921).
+import userEvent from '@testing-library/user-event';
+import { http, HttpResponse } from 'msw';
+import { buildAdmin, buildDay, buildTrip } from '../../../tests/helpers/factories';
+import { server } from '../../../tests/helpers/msw/server';
+import { render, screen } from '../../../tests/helpers/render';
+import { resetAllStores, seedStore } from '../../../tests/helpers/store';
+import { useAuthStore } from '../../store/authStore';
+import { useSettingsStore } from '../../store/settingsStore';
+import { useTripStore } from '../../store/tripStore';
+import DayDetailPanel from './DayDetailPanel';
+
+const day = buildDay({ id: 1, trip_id: 1, date: '2025-06-15', title: 'Day in Paris' });
+
+const props = {
+ day,
+ days: [day],
+ places: [],
+ categories: [],
+ tripId: 1,
+ assignments: {},
+ reservations: [],
+ lat: null,
+ lng: null,
+ onClose: vi.fn(),
+ onAccommodationChange: vi.fn(),
+};
+
+function settings(dayDateFirst: boolean) {
+ seedStore(useSettingsStore, {
+ settings: { time_format: '24h', temperature_unit: 'celsius', day_date_first: dayDateFirst },
+ });
+}
+
+beforeEach(() => {
+ resetAllStores();
+ vi.clearAllMocks();
+ server.use(
+ http.get('/api/weather/detailed', () => HttpResponse.json({ error: true })),
+ http.get('/api/trips/1/accommodations', () => HttpResponse.json({ accommodations: [] }))
+ );
+ seedStore(useAuthStore, { user: buildAdmin(), isAuthenticated: true });
+ seedStore(useTripStore, { trip: buildTrip({ id: 1 }) });
+});
+
+describe('DayDetailPanel with the date first', () => {
+ it('FE-PLANNER-DAYDETAIL-DF-001: the pencil sits with the name, and renaming keeps the date in view', async () => {
+ settings(true);
+ const user = userEvent.setup();
+ const onUpdateDayTitle = vi.fn();
+ render(<DayDetailPanel {...props} onUpdateDayTitle={onUpdateDayTitle} />);
+ const pencil = screen.getByLabelText('Edit');
+ expect(screen.getByText('Day in Paris').parentElement).toContainElement(pencil);
+ expect(screen.getByText(/June 15/).parentElement).not.toContainElement(pencil);
+ await user.click(pencil);
+ const input = await screen.findByDisplayValue('Day in Paris');
+ expect(screen.getByText(/June 15/)).toBeInTheDocument();
+ await user.clear(input);
+ await user.type(input, 'Vegueta');
+ await user.keyboard('{Enter}');
+ expect(onUpdateDayTitle).toHaveBeenCalledWith(1, 'Vegueta');
+ });
+
+ it('FE-PLANNER-DAYDETAIL-DF-002: with the name first the pencil stays on the heading, as before', async () => {
+ settings(false);
+ const user = userEvent.setup();
+ render(<DayDetailPanel {...props} onUpdateDayTitle={vi.fn()} />);
+ const pencil = screen.getByLabelText('Edit');
+ expect(screen.getByText('Day in Paris').parentElement).toContainElement(pencil);
+ await user.click(pencil);
+ expect(await screen.findByDisplayValue('Day in Paris')).toBeInTheDocument();
+ expect(screen.getByText(/June 15/)).toBeInTheDocument();
+ });
+});
diff --git a/client/src/components/Planner/DayDetailPanel.tsx b/client/src/components/Planner/DayDetailPanel.tsx
index c10062b4a..fa9803222 100644
--- a/client/src/components/Planner/DayDetailPanel.tsx
+++ b/client/src/components/Planner/DayDetailPanel.tsx
@@ -142,6 +142,28 @@ export default function DayDetailPanel({ day, days, places, categories = [], tri
{ weekday: 'long', day: 'numeric', month: 'long', timeZone: 'UTC' }
) : null
const heading = dayHeadingParts(day.title || t('planner.dayN', { n: (days.indexOf(day) + 1) || '?' }), formattedDate, dateFirst)
+ // The title input takes the place and size of the line it edits: the heading, or the line under it.
+ const titleInput = (lead: boolean) => (
+ <input
+ ref={titleInputRef}
+ value={titleDraft}
+ onChange={e => setTitleDraft(e.target.value)}
+ onClick={e => e.stopPropagation()}
+ onBlur={commitRename}
+ onKeyDown={e => { if (e.key === 'Enter') commitRename(); if (e.key === 'Escape') setEditingTitle(false) }}
+ placeholder={t('planner.dayN', { n: (days.indexOf(day) + 1) || '?' })}
+ className={`w-full border-0 border-b-[1.5px] border-content bg-transparent p-0 text-content outline-none placeholder:text-content-faint ${lead ? 'font-bold' : 'font-geist'}`}
+ style={lead ? fs(17, 'subtitle') : fs(12.5)}
+ />
+ )
+ const renamePencil = canEditDays && onUpdateDayTitle && (
+ <Tooltip label={t('common.edit')}>
+ <button type="button" onClick={startRename} aria-label={t('common.edit')}
+ className="grid h-6 w-6 flex-none place-items-center rounded-full text-content-faint hover:bg-surface-card hover:text-content">
+ <Pencil size={12} strokeWidth={2} />
+ </button>
+ </Tooltip>
+ )
const showError = (err: unknown) => toast.error(apiErrorMessage(err) || t('common.unknownError'))
// Saving the picker: a new stay or the one being edited. Both say what went
@@ -180,18 +202,8 @@ export default function DayDetailPanel({ day, days, places, categories = [], tri
<Calendar size={collapsed ? 16 : 20} strokeWidth={1.9} />
</span>
<div className="min-w-0 flex-1">
- {editingTitle ? (
- <input
- ref={titleInputRef}
- value={titleDraft}
- onChange={e => setTitleDraft(e.target.value)}
- onClick={e => e.stopPropagation()}
- onBlur={commitRename}
- onKeyDown={e => { if (e.key === 'Enter') commitRename(); if (e.key === 'Escape') setEditingTitle(false) }}
- placeholder={t('planner.dayN', { n: (days.indexOf(day) + 1) || '?' })}
- className="w-full border-0 border-b-[1.5px] border-content bg-transparent p-0 font-bold text-content outline-none placeholder:text-content-faint"
- style={fs(17, 'subtitle')}
- />
+ {editingTitle && (collapsed || heading.nameFirst) ? (
+ titleInput(true)
) : collapsed ? (
<div className="truncate font-bold text-content" style={fs(13.5, 'body')}>
{heading.primary}
@@ -200,17 +212,20 @@ export default function DayDetailPanel({ day, days, places, categories = [], tri
) : (
<div className="flex min-w-0 items-center gap-1">
<span className="truncate font-bold tracking-[-0.01em] text-content" style={fs(17, 'subtitle')}>{heading.primary}</span>
- {canEditDays && onUpdateDayTitle && (
- <Tooltip label={t('common.edit')}>
- <button type="button" onClick={startRename} aria-label={t('common.edit')}
- className="grid h-6 w-6 flex-none place-items-center rounded-full text-content-faint hover:bg-surface-card hover:text-content">
- <Pencil size={12} strokeWidth={2} />
- </button>
- </Tooltip>
- )}
+ {heading.nameFirst && renamePencil}
</div>
)}
- {!collapsed && heading.secondary && <div className="mt-0.5 truncate font-geist text-content-muted" style={fs(12.5)}>{heading.secondary}</div>}
+ {/* With the date first the name is this line, so its pencil and its input are here too (#2921). */}
+ {!collapsed && heading.secondary && (
+ editingTitle && !heading.nameFirst ? (
+ <div className="mt-0.5">{titleInput(false)}</div>
+ ) : (
+ <div className="mt-0.5 flex min-w-0 items-center gap-1">
+ <span className="truncate font-geist text-content-muted" style={fs(12.5)}>{heading.secondary}</span>
+ {!heading.nameFirst && renamePencil}
+ </div>
+ )
+ )}
</div>
<HeadButton label={collapsed ? t('common.expand') : t('common.collapse')} expanded={!collapsed}
onClick={() => toggleCollapse()}>
diff --git a/client/src/components/Planner/DayPlanSidebar.tsx b/client/src/components/Planner/DayPlanSidebar.tsx
index cbf58b702..97497c36c 100644
--- a/client/src/components/Planner/DayPlanSidebar.tsx
+++ b/client/src/components/Planner/DayPlanSidebar.tsx
@@ -54,7 +54,7 @@ import {
} from '../../utils/dayMerge'
import { withinDriveRange } from '@trek/shared/roadtrip'
import { formatDate, formatTime, formatMoneySum, splitReservationDateTime } from '../../utils/formatters'
-import { dayHeadingParts } from '../../utils/dayLabel'
+import { dayHeadingParts, headingFit } from '../../utils/dayLabel'
import { pendingStayIds } from '../../utils/pendingStays'
import { dayWeatherAnchor } from '../../utils/dayWeather'
import { metadataWithLegPositions, moveRow, planMergedOrder, withTransportPositions } from '../../utils/mergedOrder'
@@ -1664,11 +1664,11 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
<div className={hasDayPills ? 'min-w-0 pt-[5px]' : 'min-w-0'}>
<div className="flex min-w-0 items-baseline gap-2">
- <span className="min-w-0 truncate font-bold text-content" style={fs(13.5, 'body')}>
+ <span className={`${headingFit(heading).primary} font-bold text-content`} style={fs(13.5, 'body')}>
{heading.primary}
</span>
{heading.secondary && (
- <span className="flex-none whitespace-nowrap text-content-faint" style={fs(11)}>
+ <span className={`${headingFit(heading).secondary} text-content-faint`} style={fs(11)}>
{heading.secondary}
</span>
)}
diff --git a/client/src/mobile/screens/trip/sheets/MDaySheet.tsx b/client/src/mobile/screens/trip/sheets/MDaySheet.tsx
index 3a1c06acd..4b8e6f6be 100644
--- a/client/src/mobile/screens/trip/sheets/MDaySheet.tsx
+++ b/client/src/mobile/screens/trip/sheets/MDaySheet.tsx
@@ -210,6 +210,28 @@ export default function MDaySheet({ planner, shell }: MTripSheetsProps) {
// A day_number of 0 is as unusable as a missing one — both fall back to the row position.
const dayLabel = day?.title || t('planner.dayN', { n: day ? day.day_number || dayIndex + 1 : '?' })
const heading = dayHeadingParts(dayLabel, formattedDate, dateFirst)
+ // The input takes the size of the line it edits: the heading, or the line under the date.
+ const titleInput = (lead: boolean) => (
+ <input
+ ref={titleInputRef}
+ value={titleDraft}
+ onChange={e => setTitleDraft(e.target.value)}
+ onBlur={commitRename}
+ onKeyDown={e => { if (e.key === 'Enter') commitRename(); if (e.key === 'Escape') setEditingTitle(false) }}
+ placeholder={t('planner.dayN', { n: dayIndex + 1 })}
+ className={`w-full border-b-[1.5px] border-[color:var(--m-ink)] bg-transparent p-0 font-[inherit] outline-none ${lead ? 'text-[1.0625rem] font-bold' : ''}`}
+ />
+ )
+ const renamePencil = canEditDays && day && (
+ <button
+ type="button"
+ onClick={() => startRename(day.title || '')}
+ aria-label={t('mobileTrip.renameDay')}
+ className="flex flex-none p-[3px] text-m-faint"
+ >
+ <Pencil size={12} strokeWidth={1.8} />
+ </button>
+ )
const WeatherIcon = weatherIconFor(weather?.main)
const stayBadge = (acc: (typeof dayAccommodations)[number]) => {
@@ -224,34 +246,25 @@ export default function MDaySheet({ planner, shell }: MTripSheetsProps) {
{day && (
<>
<div className="flex-none px-[18px] pt-4">
+ {/* The pencil and the input go with the name: under the date when it leads (#2921). */}
<TileHeader
icon={<CalendarDays size={19} strokeWidth={1.8} />}
- title={editingTitle ? (
- <input
- ref={titleInputRef}
- value={titleDraft}
- onChange={e => setTitleDraft(e.target.value)}
- onBlur={commitRename}
- onKeyDown={e => { if (e.key === 'Enter') commitRename(); if (e.key === 'Escape') setEditingTitle(false) }}
- placeholder={t('planner.dayN', { n: dayIndex + 1 })}
- className="w-full border-b-[1.5px] border-[color:var(--m-ink)] bg-transparent p-0 font-[inherit] text-[1.0625rem] font-bold outline-none"
- />
+ title={editingTitle && heading.nameFirst ? (
+ titleInput(true)
) : (
<>
<span className="truncate">{heading.primary}</span>
- {canEditDays && (
- <button
- type="button"
- onClick={() => startRename(day.title || '')}
- aria-label={t('mobileTrip.renameDay')}
- className="flex flex-none p-[3px] text-m-faint"
- >
- <Pencil size={12} strokeWidth={1.8} />
- </button>
- )}
+ {heading.nameFirst && renamePencil}
</>
)}
- sub={heading.secondary}
+ sub={!heading.nameFirst && heading.secondary ? (
+ editingTitle ? titleInput(false) : (
+ <span className="flex min-w-0 items-center gap-1">
+ <span className="truncate">{heading.secondary}</span>
+ {renamePencil}
+ </span>
+ )
+ ) : heading.secondary}
onClose={shell.closeSheet}
closeLabel={t('common.close')}
/>
diff --git a/client/src/utils/dayLabel.test.ts b/client/src/utils/dayLabel.test.ts
index 2fcedf317..02aa6e14f 100644
--- a/client/src/utils/dayLabel.test.ts
+++ b/client/src/utils/dayLabel.test.ts
@@ -1,6 +1,6 @@
// FE-UTIL-DAYLABEL-001 to FE-UTIL-DAYLABEL-003
import { describe, it, expect } from 'vitest'
-import { dayHeadingParts, dayLabel } from './dayLabel'
+import { dayHeadingParts, dayLabel, headingFit } from './dayLabel'
const t = (key: string, params?: Record<string, string | number>) => `${key}:${params?.n}`
@@ -23,15 +23,30 @@ describe('dayLabel', () => {
describe('dayHeadingParts', () => {
it('FE-UTIL-DAYLABEL-004: the name leads by default and the date follows', () => {
- expect(dayHeadingParts('Day 2', 'Mon, Aug 17', false)).toEqual({ primary: 'Day 2', secondary: 'Mon, Aug 17' })
+ expect(dayHeadingParts('Day 2', 'Mon, Aug 17', false)).toEqual({ primary: 'Day 2', secondary: 'Mon, Aug 17', nameFirst: true })
})
it('FE-UTIL-DAYLABEL-005: planning by the calendar puts the date first', () => {
- expect(dayHeadingParts('Day 2', 'Mon, Aug 17', true)).toEqual({ primary: 'Mon, Aug 17', secondary: 'Day 2' })
+ expect(dayHeadingParts('Day 2', 'Mon, Aug 17', true)).toEqual({ primary: 'Mon, Aug 17', secondary: 'Day 2', nameFirst: false })
})
it('FE-UTIL-DAYLABEL-006: a day without a date keeps its name in front either way', () => {
- expect(dayHeadingParts('Day 2', null, true)).toEqual({ primary: 'Day 2', secondary: null })
- expect(dayHeadingParts('Day 2', '', false)).toEqual({ primary: 'Day 2', secondary: null })
+ expect(dayHeadingParts('Day 2', null, true)).toEqual({ primary: 'Day 2', secondary: null, nameFirst: true })
+ expect(dayHeadingParts('Day 2', '', false)).toEqual({ primary: 'Day 2', secondary: null, nameFirst: true })
+ })
+})
+
+describe('headingFit', () => {
+ it('FE-UTIL-DAYLABEL-007: with the date first the name behind it gives way and the date stays whole (#2920)', () => {
+ const fit = headingFit(dayHeadingParts('Arrival, East Coast & Optional Vegueta Evening', 'Thursday, November 12', true))
+ expect(fit.primary).toContain('flex-none')
+ expect(fit.primary).not.toContain('truncate')
+ expect(fit.secondary).toContain('truncate')
+ })
+
+ it('FE-UTIL-DAYLABEL-008: with the name first the name gives way, as before', () => {
+ const fit = headingFit({ nameFirst: true })
+ expect(fit.primary).toContain('truncate')
+ expect(fit.secondary).toContain('flex-none')
})
})
diff --git a/client/src/utils/dayLabel.ts b/client/src/utils/dayLabel.ts
index 01383d453..3e2bf2c62 100644
--- a/client/src/utils/dayLabel.ts
+++ b/client/src/utils/dayLabel.ts
@@ -33,8 +33,19 @@ export function dayDate(iso: string, locale: string): string | null {
* A day heading's two parts in reading order. The day's name ("Day 3" or its own
* title) leads, unless the traveller plans by the calendar and asked for the date
* first (#1953). A day without a date always leads with its name.
+ *
+ * `nameFirst` says which of the two is the name: the rename pencil and the title
+ * input belong with the name wherever it stands (#2921), and it is the name that
+ * gives way when the line is short, never the date (#2920).
*/
-export function dayHeadingParts(name: string, date: string | null | undefined, dateFirst: boolean): { primary: string; secondary: string | null } {
- if (dateFirst && date) return { primary: date, secondary: name }
- return { primary: name, secondary: date || null }
+export function dayHeadingParts(name: string, date: string | null | undefined, dateFirst: boolean): { primary: string; secondary: string | null; nameFirst: boolean } {
+ if (dateFirst && date) return { primary: date, secondary: name, nameFirst: false }
+ return { primary: name, secondary: date || null, nameFirst: true }
+}
+
+/** On one line the name gives way when it runs long, the date stays whole: with the date first a long title squeezed it to "Th…" (#2920). */
+export function headingFit({ nameFirst }: { nameFirst: boolean }): { primary: string; secondary: string } {
+ const gives = 'min-w-0 truncate'
+ const keeps = 'flex-none whitespace-nowrap'
+ return nameFirst ? { primary: gives, secondary: keeps } : { primary: keeps, secondary: gives }
}
diff --git a/client/tests/unit/mobile/trip/MDaySheet.test.tsx b/client/tests/unit/mobile/trip/MDaySheet.test.tsx
index f35bec892..d1dead251 100644
--- a/client/tests/unit/mobile/trip/MDaySheet.test.tsx
+++ b/client/tests/unit/mobile/trip/MDaySheet.test.tsx
@@ -11,7 +11,7 @@ import { resetAllStores, seedStore } from '../../../helpers/store'
import { act, fireEvent, render, screen, waitFor } from '../../../helpers/render'
import { isBlurred } from '../../../helpers/bookingCodeBlur'
-// FE-MOB-DAYSH-001 to FE-MOB-DAYSH-030
+// FE-MOB-DAYSH-001 to FE-MOB-DAYSH-031
const DAYS = [
{ id: 1, trip_id: 5, day_number: 1, date: '2026-05-01', title: null },
@@ -212,6 +212,20 @@ describe('MDaySheet', () => {
expect(planner.handleUpdateDayTitle).toHaveBeenCalledWith(2, 'Ringstrasse')
})
+ it('FE-MOB-DAYSH-031: with the date first the pencil and the input sit on the name line under the date (#2921)', async () => {
+ seedStore(useSettingsStore, { settings: { ...useSettingsStore.getState().settings, day_date_first: true } })
+ const { planner } = await renderSheet()
+ const pencil = screen.getByRole('button', { name: 'Rename day' })
+ expect(pencil.parentElement?.textContent).toBe('Old Town')
+ fireEvent.click(pencil)
+ const input = screen.getByPlaceholderText('Day 2')
+ expect(input).toHaveValue('Old Town')
+ expect(screen.getByText(/May 2/)).toBeInTheDocument()
+ fireEvent.change(input, { target: { value: 'Ringstrasse' } })
+ fireEvent.keyDown(input, { key: 'Enter' })
+ expect(planner.handleUpdateDayTitle).toHaveBeenCalledWith(2, 'Ringstrasse')
+ })
+
it('FE-MOB-DAYSH-011: Escape leaves the rename without saving', async () => {
const { planner } = await renderSheet()
fireEvent.click(screen.getByRole('button', { name: 'Rename day' }))