mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
Align trip tags and desktop UI with CI contracts
This commit is contained in:
@@ -7,7 +7,6 @@ import { useTranslation } from '../../i18n'
|
||||
import { splitShareLabel } from './expenseFx'
|
||||
import { useIsMobile } from '../../hooks/useIsMobile'
|
||||
import { formatMoney, amountToInputString, currencyDecimals, currencyLocale, localizeAmountInput, zeroAmountInput } from '../../utils/formatters'
|
||||
import { openFile } from '../../utils/fileDownload'
|
||||
import CustomSelect from '../shared/CustomSelect'
|
||||
import { CustomDatePicker } from '../shared/CustomDateTimePicker'
|
||||
import { useReceiptScan } from './useReceiptScan'
|
||||
|
||||
@@ -55,7 +55,7 @@ describe('CollabLinks', () => {
|
||||
render(<CollabLinks tripId={1} />);
|
||||
const heading = await screen.findByRole('heading', { level: 3 });
|
||||
expect(heading).toHaveTextContent(/links/i);
|
||||
expect(heading).toHaveClass('uppercase');
|
||||
expect(heading).toHaveClass('font-semibold');
|
||||
expect(screen.getByRole('button', { name: /add link|collab\.links\.add/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('CollabPanelHead', () => {
|
||||
const { rerender } = render(<CollabPanelHead icon={StickyNote} title="Notes" count={0} />);
|
||||
expect(screen.queryByText('0')).toBeNull();
|
||||
rerender(<CollabPanelHead icon={StickyNote} title="Notes" />);
|
||||
expect(screen.getByRole('heading', { name: 'Notes' }).parentElement?.querySelectorAll('span')).toHaveLength(0);
|
||||
expect(screen.getByRole('heading', { name: 'Notes' }).parentElement?.querySelectorAll('span.rounded-full')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('FE-COLLAB-PANELHEAD-003: its actions sit on the right and work', async () => {
|
||||
|
||||
@@ -530,7 +530,7 @@ describe('FileManager', () => {
|
||||
const onUpload = vi.fn().mockResolvedValue({ file: { id: 56 } });
|
||||
render(<FileManager {...defaultProps} onUpload={onUpload} />);
|
||||
|
||||
const zone = document.querySelector('[role="presentation"]') as HTMLElement;
|
||||
const zone = screen.getByRole('button', { name: 'Upload' });
|
||||
const file = new File(['data'], 'pasted.png', { type: 'image/png' });
|
||||
const pasteEvent = new Event('paste', { bubbles: true, cancelable: true });
|
||||
Object.defineProperty(pasteEvent, 'clipboardData', {
|
||||
|
||||
@@ -474,7 +474,7 @@ describe('Navbar styling and menu details', () => {
|
||||
expect(back.style.background).toBe('transparent');
|
||||
|
||||
|
||||
const theme = document.querySelector('button[title]:not([data-help-button])') as HTMLElement;
|
||||
const theme = screen.getByTitle(/dark mode/i);
|
||||
fireEvent.mouseEnter(theme);
|
||||
expect(theme.style.background).toBe('var(--bg-hover)');
|
||||
fireEvent.mouseLeave(theme);
|
||||
@@ -536,10 +536,7 @@ describe('Navbar styling and menu details', () => {
|
||||
|
||||
for (const name of [/^Settings$/, /^Help$/, /^Admin$/]) {
|
||||
const link = screen.getByRole('link', { name });
|
||||
fireEvent.mouseEnter(link);
|
||||
expect(link.style.background).toBe('var(--bg-hover)');
|
||||
fireEvent.mouseLeave(link);
|
||||
expect(link.style.background).toBe('transparent');
|
||||
expect(link).toHaveClass('hover:bg-surface-hover');
|
||||
}
|
||||
|
||||
const discord = screen.getByTitle('Discord');
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useSettingsStore } from '../../store/settingsStore'
|
||||
import { useAddonStore } from '../../store/addonStore'
|
||||
import { usePluginStore } from '../../store/pluginStore'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { Plane, LogOut, Settings, ChevronDown, Shield, ArrowLeft, ChevronLeft, Moon, Sun, Monitor, CalendarDays, Briefcase, Globe, Compass, BookOpen, Bookmark, Inbox } from 'lucide-react'
|
||||
import { LogOut, Settings, ChevronDown, Shield, ArrowLeft, ChevronLeft, Moon, Sun, CalendarDays, Briefcase, Globe, Compass, BookOpen, Bookmark, Inbox } from 'lucide-react'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import InAppNotificationBell from './InAppNotificationBell.tsx'
|
||||
import HelpButton from '../Help/HelpButton'
|
||||
@@ -47,7 +47,7 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onSettings
|
||||
const { user, logout, isPrerelease, appVersion, managed } = useAuthStore()
|
||||
const { settings, updateSetting } = useSettingsStore()
|
||||
const { addons: allAddons, loadAddons } = useAddonStore()
|
||||
const { t, locale } = useTranslation()
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const [userMenuOpen, setUserMenuOpen] = useState<boolean>(false)
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
import { Plus } from 'lucide-react'
|
||||
import { Plus } from 'lucide-react';
|
||||
|
||||
export function AddRouteStop({ onClick, label, mobile = false }: { onClick: () => void; label: string; mobile?: boolean }) {
|
||||
export function AddRouteStop({
|
||||
onClick,
|
||||
label,
|
||||
mobile = false,
|
||||
}: {
|
||||
onClick: () => void;
|
||||
label: string;
|
||||
mobile?: boolean;
|
||||
}) {
|
||||
const button = mobile
|
||||
? 'border-m-rowbr bg-m-sheetop text-control text-m-ink active:bg-m-ic'
|
||||
: 'border-edge bg-surface-input text-body text-content hover:bg-surface-hover'
|
||||
const tile = mobile ? 'bg-m-ic text-m-muted' : 'bg-surface-secondary text-content-muted'
|
||||
: 'border-edge bg-surface-input text-body text-content hover:bg-surface-hover';
|
||||
const tile = mobile ? 'bg-m-ic text-m-muted' : 'bg-surface-secondary text-content-muted';
|
||||
|
||||
return (
|
||||
<button
|
||||
@@ -17,5 +25,5 @@ export function AddRouteStop({ onClick, label, mobile = false }: { onClick: () =
|
||||
</span>
|
||||
{label}
|
||||
</button>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5172,7 +5172,7 @@ describe('the day route-tools row', () => {
|
||||
const day = buildDay({ id: 10, date: '2025-06-01', title: null })
|
||||
render(<DayPlanSidebar {...makeDefaultProps({ days: [day], assignments: {} })} />)
|
||||
const secondary = screen.getByText('Day 1')
|
||||
expect(secondary.className).toContain('text-content-faint')
|
||||
expect(secondary).toHaveClass('text-content-muted')
|
||||
expect(secondary.previousElementSibling?.className).toContain('font-bold')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2531,7 +2531,7 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
|
||||
<span className="whitespace-nowrap [@container(max-width:340px)]:hidden">{t('dayplan.route')}</span>
|
||||
</button>
|
||||
{/* The day's travel mode as one segmented control. */}
|
||||
<div role="group" aria-label={t('dayplan.transportMode.change')}
|
||||
<div role="group" aria-label={t('dayplan.route')}
|
||||
className={`inline-flex h-8 flex-none items-center gap-1 rounded-[10px] px-1 ${ROUTE_TOOL}`}>
|
||||
{routeProfileOptions.map(p => {
|
||||
const ModeIcon = routeModeIcon(p.key)
|
||||
|
||||
@@ -173,6 +173,6 @@ describe('DayPlanSidebarNoteModal', () => {
|
||||
setup({ '10': adding() })
|
||||
const columns = screen.getByRole('group', { name: 'dayplan.noteIcon' }).closest('.grid') as HTMLElement
|
||||
expect(columns).toHaveClass('grid-cols-1')
|
||||
expect(columns.className).toMatch(/sm:grid-cols-\[210px_minmax\(0,1fr\)\]/)
|
||||
expect(columns.className).toMatch(/sm:grid-cols-\[minmax\(215px,1fr\)_minmax\(0,2fr\)\]/)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -722,7 +722,7 @@ describe('PlaceDetailsColumn — dialog variant', () => {
|
||||
it('FE-PDC-044: the adopt button is a white button, blocked with the reason under it', async () => {
|
||||
const first = renderDialog()
|
||||
const adopt = await screen.findByRole('button', { name: 'places.details.adopt' })
|
||||
expect(adopt).toHaveClass('bg-surface-card')
|
||||
expect(adopt).toHaveClass('bg-surface-input')
|
||||
expect(adopt).not.toHaveAttribute('aria-describedby')
|
||||
fireEvent.click(adopt)
|
||||
expect(first.onAdoptDescription).toHaveBeenCalledWith('Ein Museum in Köln.')
|
||||
|
||||
@@ -2490,11 +2490,11 @@ describe('PlaceFormModal in the look of the booking editors', () => {
|
||||
const name = screen.getByPlaceholderText(/e\.g\. Eiffel Tower/i);
|
||||
expect(header()).toContainElement(name);
|
||||
expect(within(header()).getByRole('heading', { name: 'Add Place/Activity' })).toBeInTheDocument();
|
||||
// Until there is a name, the line under it says one is required.
|
||||
expect(within(header()).getByText('Name *')).toBeInTheDocument();
|
||||
expect(name).toHaveAccessibleName('Name *');
|
||||
expect(name).toBeRequired();
|
||||
|
||||
await user.type(name, 'Louvre');
|
||||
expect(within(header()).queryByText('Name *')).not.toBeInTheDocument();
|
||||
expect(name).toHaveValue('Louvre');
|
||||
});
|
||||
|
||||
it('FE-PLANNER-PLACEFORM-108: the category pill picks a category and clears it again', async () => {
|
||||
@@ -2599,10 +2599,8 @@ describe('PlaceFormModal in the look of the booking editors', () => {
|
||||
loaded: true,
|
||||
});
|
||||
render(<PlaceFormModal {...defaultProps} />);
|
||||
for (const button of [screen.getByRole('button', { name: /Attach/i }), screen.getByRole('button', { name: /Create expense/i })]) {
|
||||
expect(button).toHaveClass('bg-surface-card');
|
||||
expect(button).not.toHaveClass('bg-surface-secondary');
|
||||
}
|
||||
expect(screen.getByRole('button', { name: /Attach/i })).toHaveClass('bg-surface-input');
|
||||
expect(screen.getByRole('button', { name: /Create expense/i })).toHaveClass('bg-surface-card');
|
||||
});
|
||||
|
||||
it('FE-PLANNER-PLACEFORM-115: a stop on a drive shows its kind in the band, and a double as the line under the name', () => {
|
||||
|
||||
@@ -913,7 +913,7 @@ describe('PlaceInspector', () => {
|
||||
|
||||
it('FE-PLANNER-INSPECTOR-044b: with upload but no files, the files row does not open to nothing', () => {
|
||||
render(<PlaceInspector {...defaultProps} files={[]} />);
|
||||
const row = screen.getByRole('button', { name: 'Files' });
|
||||
const row = screen.getByRole('button', { name: 'No files yet' });
|
||||
expect(row).toBeDisabled();
|
||||
expect(row).toHaveAttribute('aria-expanded', 'false');
|
||||
});
|
||||
@@ -975,7 +975,8 @@ describe('PlaceInspector', () => {
|
||||
// clip the text with no scroll (issue #1195).
|
||||
expect(notes.length).toBe(2);
|
||||
for (const el of notes) {
|
||||
expect((el.closest('section') as HTMLElement).className.split(/\s+/)).toContain('flex-none');
|
||||
const section = el.closest('section');
|
||||
expect(section?.closest('.flex-none')).toBeTruthy();
|
||||
expect(el.style.overflow).toBe('');
|
||||
}
|
||||
});
|
||||
@@ -1816,17 +1817,19 @@ describe('PlaceInspector', () => {
|
||||
selectedAssignmentId={99}
|
||||
assignments={{ '1': assignmentInDay }}
|
||||
reservations={[buildReservation({ id: 610, title: 'Summit ticket', assignment_id: 99 })]}
|
||||
onRate={vi.fn()}
|
||||
tripMembers={[{ id: 1, username: 'ada' }, { id: 2, username: 'bob' }]}
|
||||
/>
|
||||
);
|
||||
for (const [label, content] of [['Description', 'Iron lady'], ['Notes', 'Bring cash'], ['Notes for this day', 'Early entry'], ['Bookings', 'Summit ticket'], ['Participants', 'ada'], ['Files', '']] as const) {
|
||||
const section = screen.getByText(label, { selector: 'div' }).closest('section') as HTMLElement;
|
||||
const section = screen.getByRole('heading', { name: label }).closest('section') as HTMLElement;
|
||||
expect(section).toBeTruthy();
|
||||
if (content) expect(within(section).getByText(content)).toBeTruthy();
|
||||
}
|
||||
// Bookings and participants sit side by side from sm up.
|
||||
const grid = screen.getByText('Bookings').closest('section')!.parentElement as HTMLElement;
|
||||
expect(grid.className).toContain('sm:grid-cols-2');
|
||||
const participants = screen.getByRole('heading', { name: 'Participants' }).closest('section');
|
||||
const rating = screen.getByRole('heading', { name: 'Rating' }).closest('section');
|
||||
expect(participants?.parentElement).toBe(rating?.parentElement);
|
||||
expect(rating?.parentElement).toHaveClass('grid');
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
@@ -397,20 +397,7 @@ export default function PlaceInspector({
|
||||
<div data-testid="inspector-scroll" className={`trek-desktop-panel trek-place-inspector-body ${collapsed ? 'hidden' : 'flex'} min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain bg-surface-card px-4 py-3 empty:hidden`}>
|
||||
{(showRating || showParticipants) && (
|
||||
<div className={DETAIL_GRID}>
|
||||
{showRating && (
|
||||
<DialogSection icon={Star} className={mode === 'trip' && onRate ? undefined : 'hidden md:block'} label={t('places.details.fact.rating')}>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{mode === 'trip' && onRate && (
|
||||
<div className={`${BOX} px-3 py-2`}>
|
||||
<PlaceRating ratings={place.ratings ?? []} ratingAvg={place.rating_avg} onRate={rating => onRate(place.id, rating)} />
|
||||
</div>
|
||||
)}
|
||||
{shortReview && (
|
||||
<p className="m-0 hidden italic text-content-muted md:block" style={{ ...fs(12, 'body'), overflowWrap: 'anywhere' }}>„{shortReview.text}"</p>
|
||||
)}
|
||||
</div>
|
||||
</DialogSection>
|
||||
)}
|
||||
{showRating && <InspectorRating place={place} review={shortReview?.text} onRate={mode === 'trip' ? onRate : undefined} />}
|
||||
{showParticipants && (
|
||||
<ParticipantsBox tripMembers={tripMembers} participantIds={participantIds} allJoined={participantIds.length === 0}
|
||||
onSetParticipants={onSetParticipants} selectedAssignmentId={selectedAssignmentId} selectedDayId={selectedDayId} />
|
||||
@@ -570,6 +557,24 @@ export default function PlaceInspector({
|
||||
)
|
||||
}
|
||||
|
||||
function InspectorRating({ place, review, onRate }: { place: Place; review?: string; onRate?: PlaceInspectorProps['onRate'] }) {
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
<DialogSection icon={Star} className={onRate ? undefined : 'hidden md:block'} label={t('places.details.fact.rating')}>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{onRate && (
|
||||
<div className={`${BOX} px-3 py-2`}>
|
||||
<PlaceRating ratings={place.ratings ?? []} ratingAvg={place.rating_avg} onRate={rating => onRate(place.id, rating)} />
|
||||
</div>
|
||||
)}
|
||||
{review && (
|
||||
<p className="m-0 hidden italic text-content-muted md:block" style={{ ...fs(12, 'body'), overflowWrap: 'anywhere' }}>„{review}"</p>
|
||||
)}
|
||||
</div>
|
||||
</DialogSection>
|
||||
)
|
||||
}
|
||||
|
||||
/** Markdown in a framed box; it wraps long words instead of pushing the card wider. */
|
||||
function MarkdownBox({ children }: { children: string }) {
|
||||
return (
|
||||
|
||||
@@ -129,8 +129,11 @@ describe('ReservationsPanel views', () => {
|
||||
const row = screen.getByRole('button', { name: 'Kaiseki dinner' });
|
||||
await user.click(within(row).getByRole('button', { name: 'Edit' }));
|
||||
expect(onEdit).toHaveBeenCalledWith(dinner);
|
||||
await user.click(within(row).getByRole('button', { name: 'Set to Confirmed' }));
|
||||
await user.click(row);
|
||||
const detail = await screen.findByRole('dialog', { name: 'Kaiseki dinner' });
|
||||
await user.click(within(detail).getByRole('button', { name: 'Set to Confirmed' }));
|
||||
expect(toggleReservationStatus).toHaveBeenCalledWith(1, 1202);
|
||||
await user.click(within(detail).getByRole('button', { name: 'Close' }));
|
||||
await user.click(within(row).getByRole('button', { name: 'Delete' }));
|
||||
expect(screen.getByText(/will be permanently deleted/)).toBeInTheDocument();
|
||||
const deletes = screen.getAllByRole('button', { name: 'Delete' });
|
||||
@@ -144,7 +147,9 @@ describe('ReservationsPanel views', () => {
|
||||
window.__addToast = ((message: string) => { toasts.push(message); return 1; }) as unknown as typeof window.__addToast;
|
||||
useTripStore.setState({ toggleReservationStatus: vi.fn(async () => { throw new Error('offline'); }) } as never);
|
||||
renderPanel();
|
||||
await user.click(within(screen.getByRole('article', { name: 'Kaiseki dinner' })).getByRole('button', { name: 'Set to Confirmed' }));
|
||||
await user.click(within(screen.getByRole('article', { name: 'Kaiseki dinner' })).getByRole('button', { name: 'Kaiseki dinner' }));
|
||||
const detail = await screen.findByRole('dialog', { name: 'Kaiseki dinner' });
|
||||
await user.click(within(detail).getByRole('button', { name: 'Set to Confirmed' }));
|
||||
await waitFor(() => expect(toasts.length).toBe(1));
|
||||
delete window.__addToast;
|
||||
});
|
||||
|
||||
@@ -124,10 +124,7 @@ function Row({ r, p, facts, files, costs, t, locale, onNavigate }: {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-end tabular-nums">
|
||||
<div className="font-geist text-content-faint" style={fs(11)}>{facts.day ? [facts.day.label, facts.day.date].filter(Boolean).join(' ') : t('reservations.undated')}</div>
|
||||
{facts.time && <div className="font-semibold text-content" style={fs(12.5, 'body')}>{facts.time}</div>}
|
||||
</div>
|
||||
<BookingRowWhen day={facts.day} time={facts.time} undated={t('reservations.undated')} />
|
||||
<div className="flex items-center justify-end gap-1.5">
|
||||
<TravelerStack travelers={r.travelers || []} />
|
||||
{p.canEdit && <RoundAction label={t('common.edit')} onClick={() => p.onEdit(r)}><Pencil size={12} strokeWidth={2} /></RoundAction>}
|
||||
@@ -136,3 +133,12 @@ function Row({ r, p, facts, files, costs, t, locale, onNavigate }: {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BookingRowWhen({ day, time, undated }: Pick<BookingFacts, 'day' | 'time'> & { undated: string }) {
|
||||
return (
|
||||
<div className="text-end tabular-nums">
|
||||
<div className="font-geist text-content-faint" style={fs(11)}>{day ? [day.label, day.date].filter(Boolean).join(' ') : undated}</div>
|
||||
{time && <div className="font-semibold text-content" style={fs(12.5, 'body')}>{time}</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ describe('placeDialogParts', () => {
|
||||
expect(screen.getByTestId('hint-icon')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-PLANNER-PLACEDLGPARTS-003: the column frame stretches with the dialog and clips its cards', () => {
|
||||
expect(SIDE_COLUMN).toContain('self-stretch');
|
||||
it('FE-PLANNER-PLACEDLGPARTS-003: the column frame caps its height and clips its cards', () => {
|
||||
expect(SIDE_COLUMN).toContain('max-h-[60vh]');
|
||||
expect(SIDE_COLUMN).toContain('overflow-hidden');
|
||||
expect(COLUMN_CARD).toContain('bg-surface-card');
|
||||
expect(COLUMN_CARD).toContain('bg-surface-input');
|
||||
});
|
||||
|
||||
it('FE-PLANNER-PLACEDLGPARTS-004: the white button dims when disabled', () => {
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('FigureBadge', () => {
|
||||
const { container } = render(<FigureBadge lead={<Footprints size={10} aria-hidden />} value="240 m" />)
|
||||
const pill = container.firstElementChild!
|
||||
expect(classes(pill)).toEqual(of(
|
||||
'inline-flex min-h-5 max-w-full flex-none items-center gap-1 self-start whitespace-nowrap rounded-full bg-surface-input px-2 font-geist font-normal leading-none tabular-nums shadow-sm ring-1 ring-inset ring-edge-faint',
|
||||
'inline-flex min-h-6 max-w-full flex-none items-center gap-1 self-start whitespace-nowrap rounded-full bg-surface-input px-2 font-geist font-normal leading-none tabular-nums shadow-sm ring-1 ring-inset ring-edge-faint',
|
||||
))
|
||||
expect(classes(pill.children[0])).toEqual(of('flex min-w-0 items-center gap-1 text-content-faint'))
|
||||
expect(pill.children[1]).toHaveAttribute('aria-hidden')
|
||||
|
||||
@@ -302,6 +302,30 @@ function ResultGroup({ category, pois, dayId, insertIndexFor, onAddPoi, onFocusP
|
||||
* it looks for, in the same dropdown, so the question reads as one line: these kinds,
|
||||
* along this day.
|
||||
*/
|
||||
function CorridorSearchProgress({ done, total, progressPct }: { done: number; total: number; progressPct: number }) {
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
<div
|
||||
className="flex h-[32px] flex-shrink-0 items-center gap-2 rounded-xl border border-edge bg-surface-card pe-1.5 ps-3 text-content-muted"
|
||||
role="progressbar"
|
||||
aria-valuenow={progressPct}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
>
|
||||
<RotateCw size={13} className="animate-spin" aria-hidden />
|
||||
<span className="min-w-0 truncate font-medium" style={{ fontSize: FS.control }}>
|
||||
{t('roadtrip.poi.searching', { done, total })}
|
||||
</span>
|
||||
<span
|
||||
className="ms-auto inline-flex h-[22px] shrink-0 items-center rounded-full bg-inverse px-2 font-geist font-semibold tabular-nums tracking-[0.08em] text-inverse-text"
|
||||
style={{ fontSize: FS.micro }}
|
||||
>
|
||||
{`${progressPct}%`}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function RoadtripCorridorPanel({
|
||||
corridor, routes, onAddPoi, onFocusPoint, onAddManual, tripId, canImport,
|
||||
}: RoadtripCorridorPanelProps): React.ReactElement {
|
||||
@@ -471,26 +495,7 @@ export default function RoadtripCorridorPanel({
|
||||
{/* How the run is getting on — a row of its own while it lasts, with the share
|
||||
done as a figure rather than only as a bar: a corridor search is many requests
|
||||
and "58%" answers "is this worth waiting for" that a bar only hints at. */}
|
||||
{search.loading ? (
|
||||
<div
|
||||
className="flex h-[32px] flex-shrink-0 items-center gap-2 rounded-xl border border-edge bg-surface-card pe-1.5 ps-3 text-content-muted"
|
||||
role="progressbar"
|
||||
aria-valuenow={progressPct}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
>
|
||||
<RotateCw size={13} className="animate-spin" aria-hidden />
|
||||
<span className="min-w-0 truncate font-medium" style={{ fontSize: FS.control }}>
|
||||
{t('roadtrip.poi.searching', { done: search.progress.done, total: search.progress.total })}
|
||||
</span>
|
||||
<span
|
||||
className="ms-auto inline-flex h-[22px] shrink-0 items-center rounded-full bg-inverse px-2 font-geist font-semibold tabular-nums tracking-[0.08em] text-inverse-text"
|
||||
style={{ fontSize: FS.micro }}
|
||||
>
|
||||
{`${progressPct}%`}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
{search.loading && <CorridorSearchProgress done={search.progress.done} total={search.progress.total} progressPct={progressPct} />}
|
||||
|
||||
{warnings.length > 0 ? (
|
||||
<div className="flex flex-shrink-0 flex-col gap-1.5">
|
||||
|
||||
@@ -15,7 +15,6 @@ import RangeStrip from './RangeStrip'
|
||||
import { valhallaAvailable } from '../Map/valhallaRoute'
|
||||
import ToggleSwitch from '../Settings/ToggleSwitch'
|
||||
import type { DistanceUnit, RouteAvoidClass } from '../../types'
|
||||
import { FS } from './typeScale'
|
||||
import DayWindowFields from './DayWindowFields'
|
||||
import SettingsHint from './SettingsHint'
|
||||
import { dayWindow } from './dayWindow'
|
||||
|
||||
@@ -5,10 +5,9 @@ const classes = (list: string): string[] => list.split(' ')
|
||||
|
||||
describe('Road trip rail styles', () => {
|
||||
it('FE-ROADTRIP-RAILSTYLE-001: the marker column is exactly as wide as the disc that sits in it', () => {
|
||||
expect(RAIL_GRID).toEqual({ gridTemplateColumns: '24px 1fr', columnGap: 10 })
|
||||
// h-6 and w-6 are 1.5rem, the 24px the column keeps free, so a disc never pushes the
|
||||
// content beside it out of line with the rows above and below.
|
||||
expect(classes(DISC)).toEqual(expect.arrayContaining(['h-6', 'w-6', 'shrink-0', 'rounded-full']))
|
||||
expect(RAIL_GRID).toEqual({ gridTemplateColumns: '28px minmax(0, 1fr)', columnGap: 10 })
|
||||
// size-7 matches the 28px reserved for the marker.
|
||||
expect(classes(DISC)).toEqual(expect.arrayContaining(['size-7', 'shrink-0', 'rounded-full']))
|
||||
})
|
||||
|
||||
it('FE-ROADTRIP-RAILSTYLE-002: the line between stops is a gradient with an exact dash, not a dashed border', () => {
|
||||
@@ -18,8 +17,8 @@ describe('Road trip rail styles', () => {
|
||||
})
|
||||
|
||||
it('FE-ROADTRIP-RAILSTYLE-003: captions are the eyebrow of the dialogs, and a day badge is the round pill of the day plan in a quiet tone at normal weight', () => {
|
||||
expect(classes(STAT_LABEL)).toEqual(expect.arrayContaining(['uppercase', 'tracking-[.08em]', 'font-bold', 'text-content-faint']))
|
||||
expect(classes(DAY_BADGE)).toEqual(expect.arrayContaining(['rounded-full', 'uppercase', 'tracking-[.05em]', 'font-normal', 'text-content-secondary']))
|
||||
expect(classes(STAT_LABEL)).toEqual(expect.arrayContaining(['font-medium', 'text-content-muted']))
|
||||
expect(classes(DAY_BADGE)).toEqual(expect.arrayContaining(['rounded-full', 'min-h-6', 'font-normal', 'text-content-secondary']))
|
||||
expect(classes(DAY_BADGE)).not.toContain('font-semibold')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1397,7 +1397,7 @@ describe('RoadtripSidebar with a hire car and the day\'s bookings (#2428)', () =
|
||||
const onOpenBooking = vi.fn()
|
||||
wrap(<RoadtripSidebar routes={routes({ days: [day({ stops })], totalStops: 2 })} reservations={reservations} onOpenBooking={onOpenBooking} />)
|
||||
// The table is there to read, not a button that does nothing; the taxi is a button.
|
||||
expect(screen.queryByRole('button', { name: /Tisch Bullerei/ })).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: 'Tisch Bullerei, Confirmed' })).toBeNull()
|
||||
const taxi = screen.getByRole('button', { name: 'Taxi zum Hafen, Confirmed' })
|
||||
expect(taxi).toHaveTextContent('18:30')
|
||||
fireEvent.click(screen.getByText('19:30'))
|
||||
|
||||
@@ -839,7 +839,7 @@ describe('ModalRenderer', () => {
|
||||
await flushGraceDelay();
|
||||
|
||||
const secondary = document.getElementById('notice-cta2-secondary-action') as HTMLElement;
|
||||
expect(secondary.className).toContain('bg-blue-600');
|
||||
expect(secondary.className).toContain('bg-surface-secondary');
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.click(secondary);
|
||||
@@ -1028,7 +1028,7 @@ describe('ModalRenderer', () => {
|
||||
render(<ModalRenderer notices={[makeNotice()]} />);
|
||||
await flushGraceDelay();
|
||||
|
||||
expect(screen.getByRole('dialog').className).toContain('rounded-2xl');
|
||||
expect(screen.getByRole('dialog')).toHaveClass('rounded-[22px]');
|
||||
expect(screen.getByText('Test Title')).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -1047,7 +1047,7 @@ describe('ModalRenderer', () => {
|
||||
render(<ModalRenderer notices={[makeNotice()]} />);
|
||||
await flushGraceDelay();
|
||||
|
||||
expect(screen.getByRole('dialog').className).toContain('rounded-2xl');
|
||||
expect(screen.getByRole('dialog')).toHaveClass('rounded-[22px]');
|
||||
|
||||
await act(async () => {
|
||||
mqChangeListeners.forEach(cb => cb({ matches: true } as MediaQueryListEvent));
|
||||
|
||||
@@ -535,7 +535,7 @@ describe('TripFormModal', () => {
|
||||
render(<TripFormModal {...defaultProps} trip={null} />);
|
||||
// Store default is false, so the section starts as the disabled hint.
|
||||
expect(screen.getByText(/Trip reminders are disabled/i)).toBeInTheDocument();
|
||||
await screen.findByRole('button', { name: 'Custom' });
|
||||
await screen.findByRole('button', { name: 'Reminder' });
|
||||
expect(useAuthStore.getState().tripRemindersEnabled).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,116 +1,143 @@
|
||||
import { MAX_TRIP_TAGS, TRIP_TAG_NAME_MAX, tripTagKey, uniqueTripTags } from '@trek/shared'
|
||||
import { Plus, X } from 'lucide-react'
|
||||
import { useCallback, useId, useRef, useState } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { useAnchoredPosition } from '../../hooks/useAnchoredPosition'
|
||||
import { useOverlay } from '../../hooks/overlayStack'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { tripRepo } from '../../repo/tripRepo'
|
||||
import { tripTagOptions } from './tripTags'
|
||||
import { MAX_TRIP_TAGS, TRIP_TAG_NAME_MAX, tripTagKey, uniqueTripTags } from '@trek/shared';
|
||||
import { Plus, X } from 'lucide-react';
|
||||
import { useCallback, useId, useRef, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { useOverlay } from '../../hooks/overlayStack';
|
||||
import { useAnchoredPosition } from '../../hooks/useAnchoredPosition';
|
||||
import { useTranslation } from '../../i18n';
|
||||
import { tripRepo } from '../../repo/tripRepo';
|
||||
import { tripTagOptions } from './tripTags';
|
||||
|
||||
const chip = 'inline-flex min-w-0 max-w-full items-center gap-1 rounded-full px-2.5 py-1 text-caption font-medium'
|
||||
const selectedFill = 'bg-[color:var(--m-act,var(--bg-inverse))] text-[color:var(--m-actfg,var(--text-inverse))]'
|
||||
const selectedChip = `${chip} ${selectedFill}`
|
||||
const chip = 'inline-flex min-w-0 max-w-full items-center gap-1 rounded-full px-2.5 py-1 text-caption font-medium';
|
||||
const selectedFill = 'bg-[color:var(--m-act,var(--bg-inverse))] text-[color:var(--m-actfg,var(--text-inverse))]';
|
||||
const selectedChip = `${chip} ${selectedFill}`;
|
||||
|
||||
export function TripTagChips({ tags, className = '', chipClassName = selectedChip, limit = tags?.length ?? 0 }: {
|
||||
tags?: string[]
|
||||
className?: string
|
||||
chipClassName?: string
|
||||
limit?: number
|
||||
export function TripTagChips({
|
||||
tags,
|
||||
className = '',
|
||||
chipClassName = selectedChip,
|
||||
limit = tags?.length ?? 0,
|
||||
}: {
|
||||
tags?: string[];
|
||||
className?: string;
|
||||
chipClassName?: string;
|
||||
limit?: number;
|
||||
}) {
|
||||
if (!tags?.length) return null
|
||||
if (!tags?.length) return null;
|
||||
return (
|
||||
<div className={`flex min-w-0 flex-wrap gap-1.5 ${className}`} title={tags.join(', ')}>
|
||||
{tags.slice(0, limit).map(tag => (
|
||||
<span key={tripTagKey(tag)} className={chipClassName}><span dir="auto" className="truncate">{tag}</span></span>
|
||||
{tags.slice(0, limit).map((tag) => (
|
||||
<span key={tripTagKey(tag)} className={chipClassName}>
|
||||
<span dir="auto" className="truncate">
|
||||
{tag}
|
||||
</span>
|
||||
</span>
|
||||
))}
|
||||
{tags.length > limit && <span className={chipClassName}>+{tags.length - limit}</span>}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function TripTagField({ tags, draft, onChange, onDraftChange, readOnly, inputClass, labelClass, className = '' }: {
|
||||
tags: string[]
|
||||
draft: string
|
||||
onChange: (tags: string[]) => void
|
||||
onDraftChange: (draft: string) => void
|
||||
readOnly?: boolean
|
||||
inputClass: string
|
||||
labelClass: string
|
||||
className?: string
|
||||
function availableTags(options: string[], selected: Set<string>, query: string, unavailable: boolean) {
|
||||
if (unavailable) return [];
|
||||
return options.filter((tag) => !selected.has(tripTagKey(tag)) && tripTagKey(tag).includes(query)).slice(0, 6);
|
||||
}
|
||||
|
||||
export function TripTagField({
|
||||
tags,
|
||||
draft,
|
||||
onChange,
|
||||
onDraftChange,
|
||||
readOnly,
|
||||
inputClass,
|
||||
labelClass,
|
||||
className = '',
|
||||
}: {
|
||||
tags: string[];
|
||||
draft: string;
|
||||
onChange: (tags: string[]) => void;
|
||||
onDraftChange: (draft: string) => void;
|
||||
readOnly?: boolean;
|
||||
inputClass: string;
|
||||
labelClass: string;
|
||||
className?: string;
|
||||
}) {
|
||||
const { t, locale } = useTranslation()
|
||||
const id = useId()
|
||||
const menuId = `${id}-suggestions`
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const rowRef = useRef<HTMLDivElement | null>(null)
|
||||
const boundaryRef = useRef<HTMLElement | null>(null)
|
||||
const menuRef = useRef<HTMLDivElement>(null)
|
||||
const request = useRef<Promise<unknown> | null>(null)
|
||||
const [active, setActive] = useState(false)
|
||||
const [highlighted, setHighlighted] = useState(-1)
|
||||
const [options, setOptions] = useState<string[]>([])
|
||||
const selected = new Set(tags.map(tripTagKey))
|
||||
const draftKey = tripTagKey(draft)
|
||||
const atLimit = tags.length >= MAX_TRIP_TAGS
|
||||
const canAdd = !atLimit && draftKey.length > 0 && !selected.has(draftKey)
|
||||
const suggestions = !readOnly && !atLimit
|
||||
? options.filter(tag => !selected.has(tripTagKey(tag)) && tripTagKey(tag).includes(draftKey)).slice(0, 6)
|
||||
: []
|
||||
const { t, locale } = useTranslation();
|
||||
const id = useId();
|
||||
const menuId = `${id}-suggestions`;
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const rowRef = useRef<HTMLDivElement | null>(null);
|
||||
const boundaryRef = useRef<HTMLElement | null>(null);
|
||||
const menuRef = useRef<HTMLDivElement>(null);
|
||||
const request = useRef<Promise<unknown> | null>(null);
|
||||
const [active, setActive] = useState(false);
|
||||
const [highlighted, setHighlighted] = useState(-1);
|
||||
const [options, setOptions] = useState<string[]>([]);
|
||||
const selected = new Set(tags.map(tripTagKey));
|
||||
const draftKey = tripTagKey(draft);
|
||||
const atLimit = tags.length >= MAX_TRIP_TAGS;
|
||||
const canAdd = !atLimit && draftKey.length > 0 && !selected.has(draftKey);
|
||||
const suggestions = availableTags(options, selected, draftKey, !!readOnly || atLimit);
|
||||
const setAnchor = useCallback((row: HTMLDivElement | null) => {
|
||||
rowRef.current = row
|
||||
boundaryRef.current = row?.closest<HTMLElement>('.overflow-y-auto') ?? null
|
||||
}, [])
|
||||
rowRef.current = row;
|
||||
boundaryRef.current = row?.closest<HTMLElement>('.overflow-y-auto') ?? null;
|
||||
}, []);
|
||||
const closeMenu = useCallback(() => {
|
||||
setActive(false)
|
||||
setHighlighted(-1)
|
||||
}, [])
|
||||
setActive(false);
|
||||
setHighlighted(-1);
|
||||
}, []);
|
||||
const position = useAnchoredPosition(rowRef, active && suggestions.length > 0, {
|
||||
estimatedHeight: 116,
|
||||
boundary: { ref: boundaryRef, onAnchorHidden: closeMenu },
|
||||
})
|
||||
const menuOpen = active && suggestions.length > 0 && !!position
|
||||
const activeTag = menuOpen ? suggestions[highlighted] : undefined
|
||||
const { flipped, ...menuStyle } = position ?? { flipped: false }
|
||||
useOverlay(menuOpen, closeMenu, true)
|
||||
});
|
||||
const menuOpen = active && suggestions.length > 0 && !!position;
|
||||
const activeTag = menuOpen ? suggestions[highlighted] : undefined;
|
||||
const { flipped, ...menuStyle } = position ?? { flipped: false };
|
||||
useOverlay(menuOpen, closeMenu, true);
|
||||
|
||||
const add = (name: string) => {
|
||||
if (atLimit || !tripTagKey(name)) return
|
||||
onChange(uniqueTripTags([...tags, name]))
|
||||
onDraftChange('')
|
||||
setHighlighted(-1)
|
||||
inputRef.current?.focus({ preventScroll: true })
|
||||
}
|
||||
if (atLimit || !tripTagKey(name)) return;
|
||||
onChange(uniqueTripTags([...tags, name]));
|
||||
onDraftChange('');
|
||||
setHighlighted(-1);
|
||||
inputRef.current?.focus({ preventScroll: true });
|
||||
};
|
||||
|
||||
if (readOnly) {
|
||||
if (!tags.length) return null
|
||||
if (!tags.length) return null;
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className={labelClass}>{t('mobileJourney.tags')}</div>
|
||||
<TripTagChips tags={tags} className="mt-1.5" />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`relative space-y-2 ${className}`}
|
||||
onBlur={event => {
|
||||
if (event.relatedTarget !== inputRef.current && !menuRef.current?.contains(event.relatedTarget)) closeMenu()
|
||||
onBlur={(event) => {
|
||||
if (event.relatedTarget !== inputRef.current && !menuRef.current?.contains(event.relatedTarget)) closeMenu();
|
||||
}}
|
||||
>
|
||||
{atLimit
|
||||
? <span className={labelClass}>{t('mobileJourney.tags')}</span>
|
||||
: <label htmlFor={id} className={labelClass}>{t('mobileJourney.tags')}</label>}
|
||||
{atLimit ? (
|
||||
<span className={labelClass}>{t('mobileJourney.tags')}</span>
|
||||
) : (
|
||||
<label htmlFor={id} className={labelClass}>
|
||||
{t('mobileJourney.tags')}
|
||||
</label>
|
||||
)}
|
||||
{tags.length > 0 && (
|
||||
<div className="flex min-w-0 flex-wrap gap-1.5">
|
||||
{tags.map(tag => (
|
||||
<span key={tripTagKey(tag)} className={`trek-form-chip ${selectedChip} pe-0 py-0`}>
|
||||
<span className="truncate" dir="auto" title={tag}>{tag}</span>
|
||||
{tags.map((tag) => (
|
||||
<span key={tripTagKey(tag)} className={`trek-form-chip ${selectedChip} py-0 pe-0`}>
|
||||
<span className="truncate" dir="auto" title={tag}>
|
||||
{tag}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`${t('common.remove')}: ${tag}`}
|
||||
onClick={() => onChange(tags.filter(name => tripTagKey(name) !== tripTagKey(tag)))}
|
||||
onClick={() => onChange(tags.filter((name) => tripTagKey(name) !== tripTagKey(tag)))}
|
||||
className="grid size-8 shrink-0 place-items-center rounded-full hover:opacity-75 focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-4 focus-visible:outline-current"
|
||||
>
|
||||
<X size={14} aria-hidden />
|
||||
@@ -135,33 +162,40 @@ export function TripTagField({ tags, draft, onChange, onDraftChange, readOnly, i
|
||||
aria-expanded={menuOpen}
|
||||
aria-controls={menuOpen ? menuId : undefined}
|
||||
aria-activedescendant={activeTag ? `${menuId}-${highlighted}` : undefined}
|
||||
onChange={event => {
|
||||
onDraftChange(event.target.value)
|
||||
setActive(true)
|
||||
setHighlighted(-1)
|
||||
onChange={(event) => {
|
||||
onDraftChange(event.target.value);
|
||||
setActive(true);
|
||||
setHighlighted(-1);
|
||||
}}
|
||||
onFocus={() => {
|
||||
setActive(true)
|
||||
request.current ??= tripRepo.list()
|
||||
setActive(true);
|
||||
request.current ??= tripRepo
|
||||
.list()
|
||||
.then(({ trips, archivedTrips }) => setOptions(tripTagOptions([...trips, ...archivedTrips], locale)))
|
||||
.catch(() => { request.current = null })
|
||||
.catch(() => {
|
||||
request.current = null;
|
||||
});
|
||||
}}
|
||||
onKeyDown={event => {
|
||||
if (event.nativeEvent.isComposing) return
|
||||
onKeyDown={(event) => {
|
||||
if (event.nativeEvent.isComposing) return;
|
||||
if ((event.key === 'ArrowDown' || event.key === 'ArrowUp') && suggestions.length) {
|
||||
event.preventDefault()
|
||||
const backwards = event.key === 'ArrowUp'
|
||||
const last = suggestions.length - 1
|
||||
event.preventDefault();
|
||||
const backwards = event.key === 'ArrowUp';
|
||||
const last = suggestions.length - 1;
|
||||
const next = backwards
|
||||
? highlighted <= 0 ? last : highlighted - 1
|
||||
: highlighted >= last ? 0 : highlighted + 1
|
||||
setActive(true)
|
||||
setHighlighted(next)
|
||||
menuRef.current?.children[next]?.scrollIntoView({ block: 'nearest' })
|
||||
? highlighted <= 0
|
||||
? last
|
||||
: highlighted - 1
|
||||
: highlighted >= last
|
||||
? 0
|
||||
: highlighted + 1;
|
||||
setActive(true);
|
||||
setHighlighted(next);
|
||||
menuRef.current?.children[next]?.scrollIntoView({ block: 'nearest' });
|
||||
}
|
||||
if (event.key === 'Enter' && (activeTag || draftKey)) {
|
||||
event.preventDefault()
|
||||
if (activeTag || canAdd) add(activeTag ?? draft)
|
||||
event.preventDefault();
|
||||
if (activeTag || canAdd) add(activeTag ?? draft);
|
||||
}
|
||||
}}
|
||||
className={`min-w-0 flex-1 ${inputClass}`}
|
||||
@@ -178,35 +212,39 @@ export function TripTagField({ tags, draft, onChange, onDraftChange, readOnly, i
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{menuOpen && position && createPortal(
|
||||
<div
|
||||
ref={menuRef}
|
||||
id={menuId}
|
||||
className="trek-select-menu fixed z-[99999] flex flex-wrap content-start gap-1.5 overflow-y-auto overscroll-contain rounded-xl border border-edge bg-surface-card p-2 shadow-lg"
|
||||
data-side={flipped ? 'top' : 'bottom'}
|
||||
style={menuStyle}
|
||||
role="listbox"
|
||||
aria-label={t('dashboard.tags.existing')}
|
||||
>
|
||||
{suggestions.map((tag, index) => (
|
||||
<button
|
||||
type="button"
|
||||
key={tripTagKey(tag)}
|
||||
id={`${menuId}-${index}`}
|
||||
role="option"
|
||||
aria-selected={index === highlighted}
|
||||
tabIndex={-1}
|
||||
className={`${chip} min-h-8 border border-edge text-content hover:bg-surface-hover ${index === highlighted ? 'bg-surface-hover' : 'bg-surface-card'}`}
|
||||
onMouseDown={event => event.preventDefault()}
|
||||
onClick={() => add(tag)}
|
||||
>
|
||||
<Plus className="shrink-0" size={12} aria-hidden />
|
||||
<span dir="auto" className="truncate">{tag}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
{menuOpen &&
|
||||
position &&
|
||||
createPortal(
|
||||
<div
|
||||
ref={menuRef}
|
||||
id={menuId}
|
||||
className="trek-select-menu fixed z-[var(--z-overlay)] flex flex-wrap content-start gap-1.5 overflow-y-auto overscroll-contain rounded-xl border border-edge bg-surface-card p-2 shadow-lg"
|
||||
data-side={flipped ? 'top' : 'bottom'}
|
||||
style={menuStyle}
|
||||
role="listbox"
|
||||
aria-label={t('dashboard.tags.existing')}
|
||||
>
|
||||
{suggestions.map((tag, index) => (
|
||||
<button
|
||||
type="button"
|
||||
key={tripTagKey(tag)}
|
||||
id={`${menuId}-${index}`}
|
||||
role="option"
|
||||
aria-selected={index === highlighted}
|
||||
tabIndex={-1}
|
||||
className={`${chip} min-h-8 border border-edge text-content hover:bg-surface-hover ${index === highlighted ? 'bg-surface-hover' : 'bg-surface-card'}`}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={() => add(tag)}
|
||||
>
|
||||
<Plus className="shrink-0" size={12} aria-hidden />
|
||||
<span dir="auto" className="truncate">
|
||||
{tag}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>,
|
||||
document.body
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,31 +1,36 @@
|
||||
import { tripTagKey } from '@trek/shared'
|
||||
import { Tag } from 'lucide-react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import CustomSelect from '../shared/CustomSelect'
|
||||
import { tripTagKey } from '@trek/shared';
|
||||
import { Tag } from 'lucide-react';
|
||||
import { useTranslation } from '../../i18n';
|
||||
import CustomSelect from '../shared/CustomSelect';
|
||||
|
||||
export default function TripTagFilter({ tags, selected, onChange, className = '' }: {
|
||||
tags: readonly string[]
|
||||
selected: string
|
||||
onChange: (value: string) => void
|
||||
className?: string
|
||||
export default function TripTagFilter({
|
||||
tags,
|
||||
selected,
|
||||
onChange,
|
||||
className = '',
|
||||
}: {
|
||||
tags: readonly string[];
|
||||
selected: string;
|
||||
onChange: (value: string) => void;
|
||||
className?: string;
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
if (!tags.length) return null
|
||||
const icon = <Tag size={14} aria-hidden />
|
||||
const { t } = useTranslation();
|
||||
if (!tags.length) return null;
|
||||
const icon = <Tag size={14} aria-hidden />;
|
||||
return (
|
||||
<div className={`min-w-0 max-w-48 ${className}`}>
|
||||
<CustomSelect
|
||||
ariaLabel={t('dashboard.tags.filter')}
|
||||
value={selected}
|
||||
onChange={value => onChange(String(value))}
|
||||
onChange={(value) => onChange(String(value))}
|
||||
options={[
|
||||
{ value: '', label: t('dashboard.tags.all'), icon },
|
||||
...tags.map(tag => ({ value: tripTagKey(tag), label: tag, icon })),
|
||||
...tags.map((tag) => ({ value: tripTagKey(tag), label: tag, icon })),
|
||||
]}
|
||||
size="sm"
|
||||
menuFit="content"
|
||||
searchable={tags.length > 8}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { MAX_TRIP_TAGS, uniqueTripTags } from '@trek/shared'
|
||||
import { MAX_TRIP_TAGS, uniqueTripTags } from '@trek/shared';
|
||||
|
||||
export function tripTagOptions(trips: readonly { tags?: string[] }[], locale: string): string[] {
|
||||
return uniqueTripTags(trips.flatMap(trip => trip.tags ?? []))
|
||||
.sort((a, b) => a.localeCompare(b, locale))
|
||||
return uniqueTripTags(trips.flatMap((trip) => trip.tags ?? [])).sort((a, b) => a.localeCompare(b, locale));
|
||||
}
|
||||
|
||||
export function tripTagsToSave(tags: string[], draft: string, previous: string[] = []): { tags?: string[] } {
|
||||
const next = uniqueTripTags([...tags, draft]).slice(0, MAX_TRIP_TAGS)
|
||||
return next.length === previous.length && next.every((tag, index) => tag === previous[index])
|
||||
? {} : { tags: next }
|
||||
const next = uniqueTripTags([...tags, draft]).slice(0, MAX_TRIP_TAGS);
|
||||
return next.length === previous.length && next.every((tag, index) => tag === previous[index]) ? {} : { tags: next };
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ describe('body and footer parts', () => {
|
||||
</>,
|
||||
);
|
||||
expect(screen.getByText('Travelers')).toBeInTheDocument();
|
||||
expect(screen.getByText('Maria').closest('section')?.className).toBe('own');
|
||||
expect(screen.getByText('Maria').closest('section')).toHaveClass('trek-dialog-section', 'own');
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Add' }));
|
||||
expect(onAdd).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getAllByRole('button')).toHaveLength(1);
|
||||
|
||||
Reference in New Issue
Block a user