feat(places): say when a place has an address but no coordinates (#2837)

A place saved with a typed address and no search pick, link or map point gets no
coordinates, so it never shows on the map, and nothing said why. The place form warns
under the address while that is so, and the inspector, the phone's place sheet and
both place lists mark such a place. No geocoding on save; the form stays unchanged
for a service stop, which explains a missing position itself.
This commit is contained in:
Maurice
2026-11-13 09:37:06 +01:00
parent 0eac3a9f49
commit 5176dc29d6
44 changed files with 401 additions and 59 deletions
@@ -0,0 +1,39 @@
import { fireEvent, render, screen } from '../../../tests/helpers/render';
import { PlaceFormLocation } from './PlaceFormLocation';
import { describe, expect, it, vi } from 'vitest';
const HINT =
'This address has no coordinates yet, so the place will not show on the map. Pick it from the search above or enter latitude and longitude.';
function renderLocation(form: { address: string; lat: string; lng: string }, warnWithoutCoordinates = true) {
const onChange = vi.fn();
render(
<PlaceFormLocation fieldId="pf" form={form} onChange={onChange} warnWithoutCoordinates={warnWithoutCoordinates} />
);
return onChange;
}
describe('PlaceFormLocation', () => {
it('FE-PLANNER-PFLOC-001: an address typed without coordinates says the place will not be on the map (#2837)', () => {
renderLocation({ address: 'Rue de Rivoli 1, Paris', lat: '', lng: '' });
expect(screen.getByText(HINT)).toBeInTheDocument();
});
it('FE-PLANNER-PFLOC-002: no word with coordinates, without an address, or where the form explains it itself', () => {
renderLocation({ address: 'Rue de Rivoli 1, Paris', lat: '48.86', lng: '2.35' });
renderLocation({ address: '', lat: '', lng: '' });
renderLocation({ address: 'Rue de Rivoli 1, Paris', lat: '', lng: '' }, false);
expect(screen.queryByText(HINT)).toBeNull();
});
it('FE-PLANNER-PFLOC-003: the fields write through, and a pasted pair fills both coordinates', () => {
const onChange = renderLocation({ address: '', lat: '', lng: '' });
fireEvent.change(screen.getByLabelText('Address'), { target: { value: 'Rue de Rivoli 1' } });
expect(onChange).toHaveBeenCalledWith('address', 'Rue de Rivoli 1');
fireEvent.paste(screen.getByLabelText('Latitude'), { clipboardData: { getData: () => '48.8566, 2.3522' } });
expect(onChange).toHaveBeenCalledWith('lat', '48.8566');
expect(onChange).toHaveBeenCalledWith('lng', '2.3522');
});
});
@@ -0,0 +1,78 @@
import { MapPinOff } from 'lucide-react';
import { useTranslation } from '../../i18n';
import { EditorField, GRID_2, INPUT, PANEL } from '../shared/dialogParts';
import { NumericInput } from '../shared/NumericInput';
import { addressWithoutCoordinates } from './placeCoordinates';
import { parseCoordinatePair } from './PlaceFormModal.helpers';
type LocationField = 'address' | 'lat' | 'lng';
interface PlaceFormLocationProps {
/** The form's id prefix, so each label points at its own field. */
fieldId: string;
form: Record<LocationField, string>;
onChange: (field: LocationField, value: string) => void;
/** Off where the form explains a missing position in its own words (a service stop). */
warnWithoutCoordinates: boolean;
}
/**
* Where the place is: what a pick, a pasted link or the map filled in, or typed by hand.
* An address typed without coordinates says under the field that the place will not be
* on the map, and how to put it there (#2837).
*/
export function PlaceFormLocation({ fieldId, form, onChange, warnWithoutCoordinates }: PlaceFormLocationProps) {
const { t } = useTranslation();
const hint = warnWithoutCoordinates && addressWithoutCoordinates(form) && (
<span className="flex items-start gap-1 text-content-muted">
<MapPinOff size={12} strokeWidth={2} aria-hidden="true" className="mt-px flex-none text-warning" />
{t('places.noCoordinatesFormHint')}
</span>
);
return (
<div className={PANEL}>
<EditorField label={t('places.formAddress')} htmlFor={`${fieldId}-address`} hint={hint}>
<input
id={`${fieldId}-address`}
type="text"
value={form.address}
onChange={(e) => onChange('address', e.target.value)}
placeholder={t('places.formAddressPlaceholder')}
className={INPUT}
/>
</EditorField>
<div role="group" aria-label={t('collections.coordinates')} className={GRID_2}>
<EditorField label={t('places.formLatLabel')} htmlFor={`${fieldId}-lat`}>
<NumericInput
id={`${fieldId}-lat`}
mode="signed"
value={form.lat}
onValueChange={(v) => onChange('lat', v)}
onPaste={(e) => {
// "48.85, 2.35" pasted into the latitude fills both halves.
const pair = parseCoordinatePair(e.clipboardData.getData('text'));
if (pair) {
e.preventDefault();
onChange('lat', pair[0]);
onChange('lng', pair[1]);
}
}}
placeholder={t('places.formLat')}
className={INPUT}
/>
</EditorField>
<EditorField label={t('places.formLngLabel')} htmlFor={`${fieldId}-lng`}>
<NumericInput
id={`${fieldId}-lng`}
mode="signed"
value={form.lng}
onValueChange={(v) => onChange('lng', v)}
placeholder={t('places.formLng')}
className={INPUT}
/>
</EditorField>
</div>
</div>
);
}
@@ -15,10 +15,11 @@ import { Tooltip } from '../shared/Tooltip'
import { Search, RotateCcw, LocateFixed, PencilLine } from 'lucide-react'
import { useTranslation } from '../../i18n'
import { PlaceContactFields } from './PlaceContactFields'
import { PlaceFormLocation } from './PlaceFormLocation'
import { weekFromPeriods } from './placeHours'
import type { PlaceOpeningHours } from '@trek/shared'
import {
DEFAULT_FORM, endsBeforeStart, findDuplicatePlace, formPin, mergeResult, parseCoordinatePair, placeEditForm, placeFormPayload,
DEFAULT_FORM, endsBeforeStart, findDuplicatePlace, formPin, mergeResult, placeEditForm, placeFormPayload,
prefillForm, savedCategoryId, type PlaceFormData, type PlacePrefill,
} from './PlaceFormModal.helpers'
import { useNewCategory, usePlaceForm } from './usePlaceForm'
@@ -30,7 +31,6 @@ import { useLocationBias } from '../../hooks/useLocationBias'
import { BookingCostsSection } from './BookingCostsSection'
import type { BookingExpenseRequest } from './BookingCostsSection.types'
import type { Place, Category, Assignment, BudgetItem } from '../../types'
import { NumericInput } from '../shared/NumericInput'
import { formatDistance } from '../../utils/units'
import ServiceStopSection from '../Roadtrip/ServiceStopSection'
import { DEFAULT_SERVICE_KIND, serviceStopChoice, type ServiceStopMode } from '../Roadtrip/manualStop'
@@ -770,50 +770,7 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
)}
</div>
{/* Where it is: what a pick, a pasted link or the map filled in, or typed by hand. */}
<div className={PANEL}>
<EditorField label={t('places.formAddress')} htmlFor={`${fieldId}-address`}>
<input
id={`${fieldId}-address`}
type="text"
value={form.address}
onChange={e => handleChange('address', e.target.value)}
placeholder={t('places.formAddressPlaceholder')}
className={INPUT}
/>
</EditorField>
<div role="group" aria-label={t('collections.coordinates')} className={GRID_2}>
<EditorField label={t('places.formLatLabel')} htmlFor={`${fieldId}-lat`}>
<NumericInput
id={`${fieldId}-lat`}
mode="signed"
value={form.lat}
onValueChange={v => handleChange('lat', v)}
onPaste={e => {
// "48.85, 2.35" pasted into the latitude fills both halves.
const pair = parseCoordinatePair(e.clipboardData.getData('text'))
if (pair) {
e.preventDefault()
handleChange('lat', pair[0])
handleChange('lng', pair[1])
}
}}
placeholder={t('places.formLat')}
className={INPUT}
/>
</EditorField>
<EditorField label={t('places.formLngLabel')} htmlFor={`${fieldId}-lng`}>
<NumericInput
id={`${fieldId}-lng`}
mode="signed"
value={form.lng}
onValueChange={v => handleChange('lng', v)}
placeholder={t('places.formLng')}
className={INPUT}
/>
</EditorField>
</div>
</div>
<PlaceFormLocation fieldId={fieldId} form={form} onChange={handleChange} warnWithoutCoordinates={!serviceStop} />
{/* For a stop on a drive: the kind of stop, how long, and where it belongs.
The category it replaces is gone from the head band too: refuelling is
@@ -1871,3 +1871,16 @@ describe('PlaceInspector folded to its head (#3039)', () => {
expect(screen.queryByRole('button', { name: 'Collapse' })).toBeNull();
});
});
// ── An address without coordinates (#2837) ─────────────────────────────────────
describe('PlaceInspector without coordinates (#2837)', () => {
it('FE-PLANNER-INSPECTOR-114: a typed address without coordinates says the place is not on the map', () => {
const typed = buildPlace({ id: 3, name: 'Corner Cafe', address: 'Rue de Rivoli 1, Paris', lat: null, lng: null });
const { rerender } = render(<PlaceInspector {...defaultProps} place={typed} />);
expect(screen.getByText('No coordinates, so not on the map')).toBeInTheDocument();
rerender(<PlaceInspector {...defaultProps} />);
expect(screen.queryByText('No coordinates, so not on the map')).toBeNull();
});
});
@@ -1,4 +1,4 @@
import { Banknote, ChevronDown, ChevronUp, Mail, MapPin, Phone, Star, X } from 'lucide-react';
import { Banknote, ChevronDown, ChevronUp, Mail, MapPin, MapPinOff, Phone, Star, X } from 'lucide-react';
import type { KeyboardEvent, ReactNode, RefObject } from 'react';
import { useTranslation } from '../../i18n';
@@ -9,6 +9,7 @@ import { NEUTRAL_TINT, fs } from '../shared/DialogShell';
import PlaceAvatar from '../shared/PlaceAvatar';
import { Tooltip } from '../shared/Tooltip';
import PlacePhotoGallery from './PlacePhotoGallery';
import { addressWithoutCoordinates } from './placeCoordinates';
import { SoftPill, TimePill, tintOf } from './planParts';
/** The round buttons at the end of the band. */
@@ -81,6 +82,8 @@ export function InspectorHead({
const { t, locale, language } = useTranslation();
const ring = openNow === true ? 'bg-success' : openNow === false ? 'bg-danger' : 'bg-surface-card shadow-sm';
const hasCoords = !!(place.lat && place.lng);
// A typed address that never got coordinates: the place has no marker, and says why (#2837).
const offMap = addressWithoutCoordinates(place);
const hasPills =
openNow !== null ||
!!category ||
@@ -90,7 +93,8 @@ export function InspectorHead({
place.source === 'dawarich' ||
!!phone ||
!!email ||
hasCoords;
hasCoords ||
offMap;
return (
<header
className={`flex-none px-4 ${collapsed ? 'py-2.5' : 'border-b border-edge-faint pb-3 pt-3.5'}`}
@@ -144,6 +148,15 @@ export function InspectorHead({
{!collapsed && hasPills && (
<div className="mt-2 flex flex-wrap items-center gap-1.5">
{offMap && (
<Tooltip label={t('places.noCoordinatesHint')}>
<span className="inline-flex min-w-0">
<SoftPill tone="warning" icon={<MapPinOff size={11} strokeWidth={2} className="flex-none" />}>
{t('places.noCoordinates')}
</SoftPill>
</span>
</Tooltip>
)}
{openNow !== null && (
<SoftPill
tone={openNow ? 'success' : 'danger'}
@@ -1,4 +1,4 @@
// FE-COMP-PLACES-001 to FE-COMP-PLACES-015 + FE-PLANNER-SIDEBAR-016 to 067
// FE-COMP-PLACES-001 to FE-COMP-PLACES-015 + FE-PLANNER-SIDEBAR-016 to 068
import { render, screen, fireEvent, waitFor, act, within } from '../../../tests/helpers/render';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
@@ -1168,3 +1168,16 @@ describe('Category filter: places without a category', () => {
expect(screen.queryByRole('button', { name: 'No Category' })).not.toBeInTheDocument();
});
});
describe('Places without coordinates', () => {
it('FE-PLANNER-SIDEBAR-068: a typed address without coordinates is marked as not on the map (#2837)', () => {
const typed = buildPlace({ name: 'Typed Cafe', address: 'Rue de Rivoli 1, Paris', lat: null, lng: null });
const picked = buildPlace({ name: 'Picked Cafe', address: 'Rue de Rivoli 2, Paris' });
const note = buildPlace({ name: 'Loose Idea', address: null, lat: null, lng: null });
render(<PlacesSidebar {...defaultProps} places={[typed, picked, note]} />);
const marks = screen.getAllByRole('img', { name: 'No coordinates, so not on the map' });
expect(marks).toHaveLength(1);
expect(marks[0].closest('[data-place-id]')).toHaveAttribute('data-place-id', String(typed.id));
});
});
@@ -1,7 +1,7 @@
import React, { useId } from 'react'
import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'
import { Plus, Check, Star } from 'lucide-react'
import { Plus, Check, Star, MapPinOff } from 'lucide-react'
import PlaceAvatar from '../shared/PlaceAvatar'
import { Tooltip } from '../shared/Tooltip'
import { fs } from '../shared/DialogShell'
@@ -10,6 +10,7 @@ import { resolveTrackColor } from '../Map/trackColors'
import { MoreButton, SoftPill, type MenuEntry } from './planParts'
import type { Place, Category } from '../../types'
import { startPlaceDrag } from '../Map/markerDrag'
import { addressWithoutCoordinates } from './placeCoordinates'
interface MemoPlaceRowProps {
place: Place
@@ -115,6 +116,15 @@ export const MemoPlaceRow = React.memo(function MemoPlaceRow({
<span id={nameId} className="min-w-0 truncate font-semibold leading-tight text-content" style={fs(13, 'body')}>
{place.name}
</span>
{/* A typed address that never got coordinates: nothing stands for this place on the
map, and the row says so (#2837). */}
{addressWithoutCoordinates(place) && (
<Tooltip label={t('places.noCoordinates')}>
<span role="img" aria-label={t('places.noCoordinates')} className="inline-flex flex-none text-warning">
<MapPinOff size={12} strokeWidth={2.2} />
</span>
</Tooltip>
)}
{/* Average member rating (#1435). */}
{hasRating && (
<SoftPill className="tabular-nums" icon={<Star size={9} strokeWidth={2.2} fill="currentColor" className="flex-none text-warning" />}>
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest';
import { addressWithoutCoordinates } from './placeCoordinates';
describe('addressWithoutCoordinates', () => {
it('FE-PLANNER-COORDS-001: an address without coordinates is flagged, from a saved place or the form (#2837)', () => {
expect(addressWithoutCoordinates({ address: 'Rue de Rivoli 1, Paris', lat: null, lng: null })).toBe(true);
expect(addressWithoutCoordinates({ address: 'Rue de Rivoli 1, Paris', lat: '', lng: '' })).toBe(true);
// One half is not a position either.
expect(addressWithoutCoordinates({ address: 'Rue de Rivoli 1, Paris', lat: 48.86, lng: null })).toBe(true);
expect(addressWithoutCoordinates({ address: 'Rue de Rivoli 1, Paris', lat: '48.86', lng: ' ' })).toBe(true);
});
it('FE-PLANNER-COORDS-002: a place with coordinates, zero included, is not flagged', () => {
expect(addressWithoutCoordinates({ address: 'Rue de Rivoli 1, Paris', lat: 48.86, lng: 2.35 })).toBe(false);
expect(addressWithoutCoordinates({ address: 'Rue de Rivoli 1, Paris', lat: '48.86', lng: '2.35' })).toBe(false);
expect(addressWithoutCoordinates({ address: 'Null Island', lat: 0, lng: 0 })).toBe(false);
});
it('FE-PLANNER-COORDS-003: a place without an address is a note on purpose and is not flagged', () => {
expect(addressWithoutCoordinates({ address: null, lat: null, lng: null })).toBe(false);
expect(addressWithoutCoordinates({ address: ' ', lat: null, lng: null })).toBe(false);
expect(addressWithoutCoordinates({})).toBe(false);
});
});
@@ -0,0 +1,22 @@
type Coordinate = number | string | null | undefined;
/** A number the map can use. Zero is one; an empty form field or a blank string is not. */
const isCoordinate = (value: Coordinate): boolean =>
value != null && String(value).trim() !== '' && Number.isFinite(Number(value));
/**
* Whether a place has an address but nothing to put it on the map with (#2837).
*
* The address field is plain text: a place saved with a typed address, and no pick from
* the search, no pasted link and no point on the map, has no coordinates, so it gets no
* marker, no route and no navigation, and nothing used to say why. The form, the place's
* detail and the place lists say so. A place with neither is a note on purpose and is
* left alone. Reads a saved place (numbers) and the form (strings) alike.
*/
export function addressWithoutCoordinates(place: {
address?: string | null;
lat?: Coordinate;
lng?: Coordinate;
}): boolean {
return !!place.address?.trim() && !(isCoordinate(place.lat) && isCoordinate(place.lng));
}