fix(places): say where a result came from, and stop asking questions in the form

Six changes to the place picker and the card behind it, all of them about a
panel saying less and meaning more.

The TREK place index has no switch in the admin panel any more. It decides
whether a search leaves the instance at all, which is a property of the
deployment rather than a taste: an operator pins TREK_PLACES_ENABLED=false in
their compose file, and it cannot be turned off from a browser by whoever holds
an admin account that day. The switch never shipped, so nothing to migrate.

The standing "Using OpenStreetMap" notice above the search box is gone. It was
a sentence about configuration in the middle of a form about a place, and it
answered a question nobody asked while leaving the real one open. Each result
now carries a small mark instead: TREK, OpenStreetMap or Google. It sits on the
row rather than above the list, because a list can be two indexes interleaved
and a heading could only name one of them.

The saved-places filters open across the full width of the row. Two of them sit
side by side, only one can be open at a time, and list names were being cut at
about ten characters for no reason.

Three empty states use the mascot the rest of TREK uses. The place details panel
no longer tells the reader to go and ask an administrator for a Google key, the
saved-places list and the road trip rail no longer explain themselves in two
lines of grey text. That needed one new mood, `sad`: `sleepy` reads as falling
asleep, which is a different thing from finding nothing.

The Kind of stop field is out of the place form. It is a road trip concept, and
the road trip view already sets it from the stop's own number, where the choice
is next to what it changes.
This commit is contained in:
Maurice
2026-09-08 17:06:09 +02:00
committed by Maurice
parent 1761f2bcd5
commit 4a88dbcbcf
92 changed files with 283 additions and 557 deletions
@@ -494,50 +494,15 @@ describe('AdminSettingsTab', () => {
expect(admin.setShowRotateJwtModal).toHaveBeenCalledWith(true);
});
describe('FE-ADMSET-041: the index switch', () => {
// The one control on this card about egress rather than about spending:
// with the index on, every search and every keystroke in the place box
// leaves the instance. The flag was read by six call paths and written by
// nothing, so before this there was no way to turn it off short of an
// INSERT against app_settings by hand.
const switchFor = () =>
screen.getByRole('button', { name: /trek place index/i });
it('FE-ADMSET-041: the index has no switch, because turning it off is a deployment decision', () => {
// It decides whether a search leaves the instance at all, so it belongs in
// the compose file rather than in a browser: TREK_PLACES_ENABLED=false.
// A card that offered the choice here also had to explain what answers
// instead, which is a paragraph about configuration inside a card about a
// data source.
renderTab();
it('turns the index off and tells the server', async () => {
let sent: unknown = null;
server.use(
http.put('/api/admin/trek-places', async ({ request }) => {
sent = await request.json();
return HttpResponse.json({ enabled: false });
}),
);
const admin = renderTab({ trekPlacesEnabled: true });
expect(switchFor()).toHaveAttribute('aria-pressed', 'true');
fireEvent.click(switchFor());
expect(admin.setTrekPlacesEnabledState).toHaveBeenCalledWith(false);
await waitFor(() => expect(sent).toEqual({ enabled: false }));
});
it('rolls back when the save fails, instead of showing a state the server never took', async () => {
server.use(http.put('/api/admin/trek-places', () => HttpResponse.error()));
const admin = renderTab({ trekPlacesEnabled: true });
fireEvent.click(switchFor());
await waitFor(() => expect(admin.setTrekPlacesEnabledState).toHaveBeenLastCalledWith(true));
});
it('says what answers instead, but only while it is off', () => {
renderTab({ trekPlacesEnabled: false });
expect(screen.getByText(/place search uses openstreetmap/i)).toBeInTheDocument();
expect(switchFor()).toHaveAttribute('aria-pressed', 'false');
});
it('stays quiet about the fallback while the index is on', () => {
renderTab({ trekPlacesEnabled: true });
expect(screen.queryByText(/place search uses openstreetmap/i)).not.toBeInTheDocument();
});
expect(screen.queryByRole('button', { name: /trek place index/i })).not.toBeInTheDocument();
expect(screen.queryByText(/place search uses openstreetmap/i)).not.toBeInTheDocument();
});
});
+1 -10
View File
@@ -26,7 +26,6 @@ export default function AdminSettingsTab({ admin, t }: AdminSettingsTabProps): R
placesEnrichEnabled, setPlacesEnrichEnabledState,
transitProvider, setTransitProviderState,
transitGoogleKeySource, setTransitGoogleKeySource,
trekPlacesEnabled, setTrekPlacesEnabledState,
placeShadowEnabled, setPlaceShadowEnabledState,
oidcConfig, setOidcConfig, savingOidc, setSavingOidc,
passwordLogin, setPasswordLogin, passwordRegistration, setPasswordRegistration,
@@ -382,15 +381,7 @@ export default function AdminSettingsTab({ admin, t }: AdminSettingsTabProps): R
{/* Three comparable blocks, in the order we would have people choose
them. Weather moved out entirely: it needs no key and had nothing
to configure, so it had no business in a card about keys. */}
<TrekApiCard
t={t}
enabled={trekPlacesEnabled}
onToggle={async () => {
const next = !trekPlacesEnabled
setTrekPlacesEnabledState(next)
try { await adminApi.updateTrekPlaces(next) } catch { setTrekPlacesEnabledState(!next) }
}}
/>
<TrekApiCard t={t} />
{!managed && (<>
<ProviderBlock title={t('admin.mapsKey')}>
+1 -24
View File
@@ -1,23 +1,10 @@
import React from 'react'
import { Check, ChevronRight, Globe2, KeyRound, Library, ShieldOff, WifiOff, X } from 'lucide-react'
import TrekMark from '../../components/shared/TrekMark'
import ToggleSwitch from '../../components/Settings/ToggleSwitch'
import type { TranslationFn } from '../../types'
interface TrekApiCardProps {
t: TranslationFn
/**
* Whether the index answers on this instance.
*
* A real switch rather than a badge, and the only one on this card that is
* about egress rather than about spending: with it on, every search and every
* keystroke in the place box leaves the instance for the service. An operator
* who does not want that has to be able to say so here — the flag was read by
* six call paths and written by nothing, so the only way to turn it off was an
* INSERT against app_settings by hand.
*/
enabled: boolean
onToggle: () => void
}
/**
@@ -39,7 +26,7 @@ interface TrekApiCardProps {
*/
const SOURCES = ['Overture Maps Foundation', 'OpenStreetMap', 'Wikivoyage', 'Wikimedia']
export default function TrekApiCard({ t, enabled, onToggle }: TrekApiCardProps): React.ReactElement {
export default function TrekApiCard({ t }: TrekApiCardProps): React.ReactElement {
// Reuses the words TREK already has for these fields wherever it has them,
// so the chip row costs two new strings instead of ten.
const fields = [
@@ -84,22 +71,12 @@ export default function TrekApiCard({ t, enabled, onToggle }: TrekApiCardProps):
<div className="px-5 pt-6 pb-4">
<div className="flex items-start justify-between gap-4">
<TrekMark className="h-8 w-auto text-content" aria-label="TREK Places API" />
<ToggleSwitch on={enabled} onToggle={onToggle} label={t('admin.trekApi.toggleLabel')} />
</div>
<p className="mt-3 text-sm leading-relaxed text-content-secondary">
{t('admin.trekApi.tagline')}
</p>
{/* Said only when it is off, and said plainly: this is the state where
searches stop using the index, and the reader should know what
answers instead rather than being left to guess. */}
{!enabled && (
<p className="mt-2 text-xs leading-relaxed text-content-faint">
{t('admin.trekApi.offNote')}
</p>
)}
<ul className="mt-4 grid grid-cols-1 gap-x-6 gap-y-2 sm:grid-cols-2">
{facts.map(({ Icon, text }) => (
<li key={text} className="flex items-center gap-2 text-xs text-content-secondary">
-3
View File
@@ -114,8 +114,6 @@ export function useAdmin() {
// false rather than the true the four switches above start from.
// The index switch. Read fail-open like the server does, so the state shown
// before the request lands matches what an unset row actually means.
const [trekPlacesEnabled, setTrekPlacesEnabledState] = useState<boolean>(true)
useEffect(() => { adminApi.getTrekPlaces().then(d => setTrekPlacesEnabledState(d.enabled)).catch(() => {}) }, [])
const [placeShadowEnabled, setPlaceShadowEnabledState] = useState<boolean>(false)
useEffect(() => { adminApi.getPlaceShadow().then(d => setPlaceShadowEnabledState(d.enabled)).catch(() => {}) }, [])
@@ -453,7 +451,6 @@ export function useAdmin() {
placesEnrichEnabled, setPlacesEnrichEnabledState,
transitProvider, setTransitProviderState,
transitGoogleKeySource, setTransitGoogleKeySource,
trekPlacesEnabled, setTrekPlacesEnabledState,
placeShadowEnabled, setPlaceShadowEnabledState,
collabFeatures, setCollabFeatures,
oidcConfig, setOidcConfig, savingOidc, setSavingOidc,