Give GPX tracks their own colour (#776)

Imported tracks all render in the same blue: the GPX/KML importers never
assign a category, so category_color is null for every one of them and
several walks in the same area are impossible to tell apart.

Adds a nullable route_color on places, kept out of the COALESCE group in
updatePlace so an explicit null can reset a track back to inheriting its
category colour. The hex is validated in the Nest controller rather than
in the shared contract: the update body is an open record on purpose, and
tightening it would mean removing PlacesController.update from the
ratchet-only body-contract allow-list.

The importers now hand each new track a colour of its own, picked from
the palette entries the trip is not already using. That happens in the
Nest service over the injected DatabaseService — the colour assignment is
new logic, and new logic does not belong in the legacy place service (see
server/src/nest/README.md). The field itself is only threaded through the
existing update/create statements, which the proportionality rule covers.

Also fixes duplicateTrip, whose explicit column list has been silently
dropping route_geometry all along, so a duplicated trip lost its tracks.
This commit is contained in:
Maurice
2026-07-27 17:35:20 +02:00
committed by Maurice
parent 351b5fb4ec
commit 1b5317a817
14 changed files with 430 additions and 13 deletions
+1
View File
@@ -31,6 +31,7 @@ export * from './airtrail/airtrail.schema';
export * from './day/day.schema';
export * from './assignment/assignment.schema';
export * from './place/place.schema';
export * from './place/track-colors';
export * from './collection/collection.schema';
export * from './trip/trip.schema';
export * from './trip-invite/trip-invite.schema';
+24 -1
View File
@@ -1,7 +1,30 @@
import { placeCreateRequestSchema, placeBulkDeleteRequestSchema, placeImportListRequestSchema } from './place.schema';
import {
placeCreateRequestSchema,
placeBulkDeleteRequestSchema,
placeImportListRequestSchema,
placeSchema,
} from './place.schema';
import { describe, it, expect } from 'vitest';
describe('placeSchema route_color (#776)', () => {
const place = { id: 1, trip_id: 1, name: 'Walk' };
it('takes a hex colour, null, or nothing at all', () => {
expect(placeSchema.safeParse({ ...place, route_color: '#e11d48' }).success).toBe(true);
expect(placeSchema.safeParse({ ...place, route_color: '#abc' }).success).toBe(true);
// null is how a track goes back to inheriting its category colour.
expect(placeSchema.safeParse({ ...place, route_color: null }).success).toBe(true);
expect(placeSchema.safeParse(place).success).toBe(true);
});
it('rejects anything a map renderer could not parse', () => {
expect(placeSchema.safeParse({ ...place, route_color: 'blue' }).success).toBe(false);
expect(placeSchema.safeParse({ ...place, route_color: '#12345' }).success).toBe(false);
expect(placeSchema.safeParse({ ...place, route_color: 'e11d48' }).success).toBe(false);
});
});
describe('placeCreateRequestSchema', () => {
it('requires a name and keeps the other place fields open', () => {
expect(
+5
View File
@@ -16,6 +16,9 @@ import { z } from 'zod';
const open = z.record(z.string(), z.unknown());
/** `#rgb` / `#rrggbb`, the form both map renderers and CSS accept. */
export const hexColorSchema = z.string().regex(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/);
/**
* Embedded category as returned on a place — a trimmed projection of the
* categories row (id/name/color/icon), built inline by placeService and
@@ -70,6 +73,8 @@ export const placeSchema = z.object({
google_ftid: z.string().nullable().optional(),
osm_id: z.string().nullable().optional(),
route_geometry: z.string().nullable().optional(),
// Manual track colour (#776). null = inherit the category colour like before.
route_color: hexColorSchema.nullable().optional(),
website: z.string().nullable().optional(),
phone: z.string().nullable().optional(),
transport_mode: z.string().nullable().optional(),
+32
View File
@@ -0,0 +1,32 @@
/**
* Track colour palette (#776) — shared so the importer's automatic assignment
* and the picker in the UI hand out the exact same set.
*
* Tuned against map tiles rather than UI surfaces: the 600 tier survives thin
* 3.5px lines on light basemaps where 400/500 washes out, and nothing here is
* a neutral grey (invisible on CartoDB Dark) or a pale pastel (invisible at
* any size). Blue is deliberately blue-700 — darker than both the #3b82f6 GPX
* fallback and the #0a84ff day route, so a blue track reads as chosen rather
* than defaulted.
*
* The order matters: the importer assigns these round-robin, so the first five
* are the ones most tracks get. They follow the Okabe-Ito idea of staying
* separable under red-green colour blindness (blue, orange, green, magenta,
* cyan) instead of running through the rainbow and handing out four adjacent
* warm tones in a row.
*/
export const TRACK_COLORS = [
'#1d4ed8', // blue-700
'#ea580c', // orange-600
'#059669', // emerald-600
'#c026d3', // fuchsia-600
'#0891b2', // cyan-600
'#e11d48', // rose-600
'#d97706', // amber-600
'#65a30d', // lime-600
'#7c3aed', // violet-600
'#4f46e5', // indigo-600
] as const;
/** Colour a track falls back to when it has neither a manual nor a category colour. */
export const TRACK_COLOR_FALLBACK = '#3b82f6';