feat(admin): live flight status, booking mail import and paddle water data as rows of the addon cards

The addons page listed the trip, global and integration addons and then three
loose cards under them: live flight status, the booking mail import and the
paddle water data. They now sit where they belong, as rows of the cards:

- Live flight status is a row of the trip card, with its switch, locked when
  FLIGHT_LIVE_ENABLED holds it.
- The booking mail import is a row of the integration card with its switch;
  while it is on, "Set up mail import" opens the transport, address, AI
  allowance, test and status in a dialog, the way AI is set up.
- The paddle water data are a row under the Tours addon that opens the
  regions in a dialog, counting the open requests, else the regions.

The phone follows with the same rows and bottom sheets. The setup row and the
setup dialog are shared components (AddonSetupRow, AddonSetupDialog on the
desktop, MAdminOptionRow and MAdminSetupRow on the phone), the card counts
stay the addons' own, and the settings tab loses its features part.
This commit is contained in:
Maurice
2026-11-21 00:23:13 +01:00
parent 6ebd5cf0c7
commit 711015d5fd
52 changed files with 596 additions and 263 deletions
@@ -78,17 +78,22 @@ function adminState(overrides: Partial<Admin> = {}, search: Partial<Admin['searc
};
}
function show(overrides: Partial<Admin> = {}, search: Partial<Admin['search']> = {}) {
/** The panel as the Tours shelf shows it: a setup row, opened into its dialog unless asked not to. */
function show(overrides: Partial<Admin> = {}, search: Partial<Admin['search']> = {}, { open = true } = {}) {
const state = adminState(overrides, search);
hook.usePaddleRegionsAdmin.mockReturnValue(state);
return { state, ...render(<PaddleRegionsPanel />) };
const view = render(
<ul>
<PaddleRegionsPanel />
</ul>
);
if (open && state.toursOn) fireEvent.click(setupRow());
return { state, ...view };
}
/** The card's title row, where the number of regions sits beside the title. */
function titleRow(): HTMLElement {
const row = screen.getByRole('heading', { name: 'Paddle water data' }).parentElement;
if (!row) throw new Error('no title row');
return row;
/** The shelf row that opens the dialog, where the count of requests or regions sits beside the title. */
function setupRow(): HTMLElement {
return screen.getAllByRole('button', { name: /^Paddle water data/ })[0];
}
function rowOf(name: string): HTMLElement {
@@ -100,7 +105,7 @@ function rowOf(name: string): HTMLElement {
describe('PaddleRegionsPanel', () => {
it('FE-ADMIN-PADDLEREG-001: renders nothing while the Tours addon is off', () => {
const { container } = show({ toursOn: false, regions: [READY] });
expect(container).toBeEmptyDOMElement();
expect(container.querySelector('ul')).toBeEmptyDOMElement();
});
it('FE-ADMIN-PADDLEREG-002: shows the card with its hint, the attribution and the empty state', () => {
@@ -110,7 +115,7 @@ describe('PaddleRegionsPanel', () => {
expect(screen.getByText(EMPTY)).toBeInTheDocument();
expect(screen.getByText(ATTRIBUTION)).toBeInTheDocument();
// No count beside the title while there is no region.
expect(titleRow()).toHaveTextContent(/^Paddle water data$/);
expect(setupRow()).toHaveTextContent(/^Paddle water data$/);
const search = screen.getByRole('searchbox', { name: 'Add a region' });
expect(search).toBeEnabled();
expect(search).toHaveAttribute('placeholder', 'Search Geofabrik, for example Oberpfalz');
@@ -277,12 +282,31 @@ describe('PaddleRegionsPanel', () => {
}
});
it('FE-ADMIN-PADDLEREG-019: the title carries the number of regions', () => {
it('FE-ADMIN-PADDLEREG-019: the setup row carries the open requests, else the number of regions', () => {
show({ regions: [READY, WAITING, FAILED_FIRST] });
expect(within(titleRow()).getByText('3')).toBeInTheDocument();
expect(within(setupRow()).getByText('3')).toBeInTheDocument();
expect(screen.getAllByTestId('paddle-region-row')).toHaveLength(3);
});
it('FE-ADMIN-PADDLEREG-019b: an open request outranks the region count, a declined one does not count', () => {
const base = { bytes: 1, requested_by: 'elmo', requested_at: '2026-10-18T09:00:00Z' };
show(
{
regions: [READY, WAITING],
requests: [
{ ...base, id: 'norway', name: 'Norway', reason: 'too_large', declined: true },
{ ...base, id: 'saale', name: 'Saale', reason: 'limit', declined: false },
],
},
{},
{ open: false }
);
expect(within(setupRow()).getByText('1')).toBeInTheDocument();
expect(within(setupRow()).queryByText('2')).toBeNull();
// Closed until the row is opened.
expect(screen.queryByRole('dialog')).toBeNull();
});
it('FE-ADMIN-PADDLEREG-020: removing asks first, naming the region, and confirming hands it to the hook', () => {
const { state } = show({ regions: [READY], removing: READY });
const message = 'Oberpfalz and its obstacle data are removed. Paddle tours there then show no data.';
@@ -1,6 +1,6 @@
import type { PaddleRegion, PaddleRegionCatalogEntry } from '@trek/shared';
import { Check, ChevronRight, Loader2, Plus, RefreshCw, Search, Trash2, Waves, WifiOff } from 'lucide-react';
import { useId } from 'react';
import { useId, useState } from 'react';
import { useDateFormat } from '../../../hooks/useDateFormat';
import { useTranslation } from '../../../i18n';
import { formatDisplayDate } from '../../../utils/dateFormat';
@@ -8,7 +8,6 @@ import {
SettingRows,
SETTINGS_BUTTON,
SETTINGS_ICON_BUTTON,
SettingsCard,
SettingsHint,
StatusPill,
} from '../../Settings/settingsKit';
@@ -17,6 +16,8 @@ import { EditorField, INPUT } from '../../shared/dialogParts';
import { fs } from '../../shared/DialogShell';
import ErrorBoundary from '../../shared/ErrorBoundary';
import { Tooltip } from '../../shared/Tooltip';
import AddonSetupDialog from '../AddonSetupDialog';
import AddonSetupRow from '../AddonSetupRow';
import { AutoLoadSettings, AutoOriginPill, RequestList } from './PaddleAutoLoadParts';
import { progressPercent, regionStatusTone } from './paddleRegionsModel';
import { usePaddleRegionsAdmin } from './usePaddleRegionsAdmin';
@@ -27,8 +28,10 @@ type Admin = ReturnType<typeof usePaddleRegionsAdmin>;
* PAD-05A in the admin area: the regions TREK reads paddle obstacles for,
* picked from Geofabrik's list, and (PAD-11C) how TREK loads the region of a
* place a paddler plans in by itself, with the regions that wait for an admin.
* The desktop admin shows this card under the addons while the Tours addon
* is on; the phone has MAdminPaddleRegionsPanel on the same hook.
* The desktop admin shows it as a row of the Tours addon that opens it as a
* dialog while the addon is on; the row counts what waits for the admin (the
* requests) or else the regions. The phone has MAdminPaddleRegionsPanel on
* the same hook.
*/
export default function PaddleRegionsPanel() {
return (
@@ -41,14 +44,42 @@ export default function PaddleRegionsPanel() {
function Panel() {
const { t } = useTranslation();
const admin = usePaddleRegionsAdmin();
const [open, setOpen] = useState(false);
if (!admin.toursOn) return null;
const title = t('admin.paddleRegions.title');
// A declined request no longer waits for anyone; only the open ones ask for a look.
const waiting = admin.requests.filter((r) => !r.declined).length;
const badge =
waiting > 0 ? (
<StatusPill tone="warning">{waiting}</StatusPill>
) : admin.regions.length > 0 ? (
<StatusPill>{admin.regions.length}</StatusPill>
) : undefined;
const close = () => setOpen(false);
return (
<SettingsCard
icon={Waves}
title={t('admin.paddleRegions.title')}
hint={t('admin.paddleRegions.hint')}
badge={admin.regions.length > 0 ? <StatusPill>{admin.regions.length}</StatusPill> : undefined}
>
<>
<AddonSetupRow label={title} onOpen={() => setOpen(true)} badge={badge} />
{open && (
<AddonSetupDialog
icon={<Waves size={20} strokeWidth={2} />}
eyebrow={t('admin.addons.catalog.tours.name')}
title={title}
sub={t('admin.paddleRegions.hint')}
onClose={close}
blocked={admin.removing !== null}
>
<PanelBody admin={admin} />
</AddonSetupDialog>
)}
</>
);
}
/** What the dialog holds: the state of the list, the settings, the requests, the search and the regions. */
function PanelBody({ admin }: { admin: Admin }) {
const { t } = useTranslation();
return (
<div className="flex flex-col gap-4">
{admin.offline && (
<p
role="status"
@@ -86,7 +117,7 @@ function Panel() {
message={t('admin.paddleRegions.removeMessage', { name: admin.removing?.name ?? '' })}
confirmLabel={t('common.remove')}
/>
</SettingsCard>
</div>
);
}