feat(collections): own order, KML/KMZ import, copy options, position search, place names on the trip map

- A list keeps its own order: drag a place by its grip (desktop and phone) or
  move it with the arrow keys. Reordering is off while a search or filter hides
  places and the list says why. New PUT /collections/:id/places/reorder and the
  MCP tool reorder_collection_places; new places go to the end. Client and
  server now order ties the same way (sort_order, oldest first, id).
- Copying saved places into a trip no longer takes their notes and tags along
  unasked. The picker offers both; a tag taken along becomes a trip tag (a trip
  tag of the same name is reused), never someone's personal tag.
- The source trip and place a saved place names are only kept when the user can
  open that trip and the place belongs to it.
- A KML or KMZ map can be read into a list: the dialog lists every placemark to
  keep or leave out and says which entries were skipped and why
  (POST /collections/map/read writes nothing; the import does).
- A saved place without coordinates says so and can be looked up on the map
  from its edit form, on the phone too, where a missing position could not be
  added at all. A typed address without a pick says it will not be on the map.
- The trip map can show the place names beside the pins (desktop and phone,
  both renderers). Names that would cover another pin or a control give way,
  the selected place and the planned stops first.
This commit is contained in:
Maurice
2026-11-29 14:57:00 +01:00
parent 177a0febe2
commit 82165855c7
148 changed files with 4219 additions and 321 deletions
@@ -1,6 +1,8 @@
import {
COLLECTION_GPX_PLACE_FIELDS,
MAX_COLLECTION_FILE_BYTES,
COLLECTION_FILE_FORMAT,
collectionMapReadResultSchema,
collectionFilePlaceSchema,
collectionGpxReadRequestSchema,
} from './collection-file.schema';
@@ -56,3 +58,21 @@ describe('collectionFilePlaceSchema website (#2483)', () => {
expect(place('Chapelle').website).toBeNull();
});
});
describe('collectionMapReadResultSchema (PLC-22)', () => {
const file = { format: COLLECTION_FILE_FORMAT, version: 1, name: 'Lisbon', places: [{ name: 'Miradouro' }] };
it('carries the file, a folder per place and every placemark left out with its reason', () => {
const read = {
file,
folders: ['Views'],
skipped: [{ name: 'Tram 28', folder: null, reason: 'line' }],
};
expect(collectionMapReadResultSchema.parse(read)).toEqual(read);
});
it('refuses a skip reason it does not know', () => {
const read = { file, folders: [null], skipped: [{ name: null, folder: null, reason: 'polygon' }] };
expect(collectionMapReadResultSchema.safeParse(read).success).toBe(false);
});
});
@@ -285,6 +285,50 @@ export interface CollectionGpxReadResult {
track_points: number;
}
/*
* ── KML and KMZ in (PLC-22) ──────────────────────────────────────────────
*
* Google My Maps and Google Earth hand out KML or KMZ. Read the same way as a
* GPX: the server turns the uploaded file into a list file and touches no
* table, the browser shows it, and what the user keeps of it goes through the
* same import routes as any other file.
*/
/** The most bytes a KML or KMZ upload may have, the trip map import's cap. */
export const MAX_COLLECTION_MAP_UPLOAD_BYTES = 10 * 1024 * 1024;
/** Why a KML or KMZ file was not read, as the `code` of the 4xx that says so. */
export const COLLECTION_MAP_PROBLEMS = ['no-file', 'not-map', 'unreadable', 'too-large', 'too-many-places'] as const;
export type CollectionMapProblem = (typeof COLLECTION_MAP_PROBLEMS)[number];
/**
* Why a placemark did not become a place: `line` for a path (a list has no
* lines), `no_point` for an area or a placemark without any geometry,
* `invalid` for one the place contract refused (coordinates out of range).
*/
export const COLLECTION_MAP_SKIP_REASONS = ['line', 'no_point', 'invalid'] as const;
export type CollectionMapSkipReason = (typeof COLLECTION_MAP_SKIP_REASONS)[number];
export const collectionMapReadResultSchema = z.object({
/** The list file the map amounts to, ready for the import routes. */
file: collectionFileSchema,
/**
* The KML folder each place sat in, by its index in `file.places` (null at
* the top level). Carried for a later mapping onto categories or labels; the
* import does not read it.
*/
folders: z.array(z.string().nullable()),
/** Every placemark that did not become a place, in document order. */
skipped: z.array(
z.object({
name: z.string().nullable(),
folder: z.string().nullable(),
reason: z.enum(COLLECTION_MAP_SKIP_REASONS),
}),
),
});
export type CollectionMapReadResult = z.infer<typeof collectionMapReadResultSchema>;
export interface CollectionGpxExport {
/** The list's name, for the file name. */
name: string;
@@ -1,8 +1,10 @@
import {
collectionCopyToTripRequestSchema,
collectionDeleteManyRequestSchema,
collectionItemsRequestSchema,
collectionMembershipSchema,
collectionPlacesPageRequestSchema,
collectionPlacesReorderRequestSchema,
collectionPlaceUpdateRequestSchema,
collectionReorderRequestSchema,
COLLECTION_PLACES_PAGE_DEFAULT,
@@ -161,3 +163,34 @@ describe('collectionPlacesPageRequestSchema', () => {
expect(COLLECTION_PLACES_PAGE_DEFAULT).toBe(100);
});
});
describe('collectionCopyToTripRequestSchema', () => {
// D9: notes and tags only travel when asked for, so an older body still parses and carries neither.
it('takes the old body as it was, and the two opt-ins beside it', () => {
expect(collectionCopyToTripRequestSchema.parse({ trip_id: 3, place_ids: [1] })).toEqual({
trip_id: 3,
place_ids: [1],
});
const full = { trip_id: 3, place_ids: [1, 2], force: true, include_notes: true, tag_ids: [7, 8] };
expect(collectionCopyToTripRequestSchema.parse(full)).toEqual(full);
});
it('refuses a fractional tag id and more than 50 of them', () => {
expect(collectionCopyToTripRequestSchema.safeParse({ trip_id: 3, place_ids: [1], tag_ids: [1.5] }).success).toBe(
false,
);
const many = Array.from({ length: 51 }, (_, i) => i + 1);
expect(collectionCopyToTripRequestSchema.safeParse({ trip_id: 3, place_ids: [1], tag_ids: many }).success).toBe(
false,
);
});
});
describe('collectionPlacesReorderRequestSchema', () => {
// PLC-03: a list's places in the order its members want them.
it('takes the ids in order and refuses an empty list or a fractional id', () => {
expect(collectionPlacesReorderRequestSchema.parse({ orderedIds: [5, 3, 4] })).toEqual({ orderedIds: [5, 3, 4] });
expect(collectionPlacesReorderRequestSchema.safeParse({ orderedIds: [] }).success).toBe(false);
expect(collectionPlacesReorderRequestSchema.safeParse({ orderedIds: [1.5] }).success).toBe(false);
});
});
+35 -1
View File
@@ -271,11 +271,28 @@ export const collectionDeleteManyRequestSchema = z.object({
});
export type CollectionDeleteManyRequest = z.infer<typeof collectionDeleteManyRequestSchema>;
/** Copy one or many saved places INTO a trip (dedup precheck on server). */
/**
* Copy one or many saved places INTO a trip (dedup precheck on server).
*
* A saved place's notes and tags stay in the list unless the request asks for
* them (D9): a note is often private, and a tag is somebody's own. Older clients
* that send neither field get the places without both.
*/
export const collectionCopyToTripRequestSchema = z.object({
trip_id: z.number().int(),
place_ids: z.array(z.number().int()).min(1),
force: z.boolean().optional(),
include_notes: z
.boolean()
.optional()
.describe("true copies each saved place's notes into the trip; left out or false, the notes stay in the list"),
tag_ids: z
.array(z.number().int())
.max(50)
.optional()
.describe(
'Ids of tags the saved places carry that should come along. Each becomes a tag of the trip, reusing a trip tag of the same name; ids a place does not carry are ignored. Left out, no tags are copied',
),
});
export type CollectionCopyToTripRequest = z.infer<typeof collectionCopyToTripRequestSchema>;
@@ -287,6 +304,23 @@ export const collectionCopyToTripResponseSchema = z.object({
});
export type CollectionCopyToTripResponse = z.infer<typeof collectionCopyToTripResponseSchema>;
/** The most places one reorder names; well past the size lists grow to. */
export const MAX_COLLECTION_REORDER_PLACES = 10000;
/**
* A list's places in the order its members want them (PLC-03). Every id must
* be a place of that list. Places it leaves out (saved by someone else since
* the list was loaded) keep their relative order and follow the named ones.
*/
export const collectionPlacesReorderRequestSchema = z.object({
orderedIds: z
.array(z.number().int())
.min(1)
.max(MAX_COLLECTION_REORDER_PLACES)
.describe("The list's place ids (collection place ids) in the new order, first to last"),
});
export type CollectionPlacesReorderRequest = z.infer<typeof collectionPlacesReorderRequestSchema>;
/** Saved places and labels asked for by their ids, across every list the caller can see (get_collection_items). */
export const collectionItemsRequestSchema = z.object({
placeIds: z.array(idSchema).max(50).optional(),