mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
feat(mobile): number the stops of a day in the plan as their pins are
The map numbers a day's stops on their pins, the phone's plan did not, so matching a pin to its row meant reading names. Each stop now carries its number at the foot of its picture, in the pin's dark round. The count moved into stopNumbersOfDay, which the map reads too, so a row and its pin always agree, service stops passed over on both. Addresses discussion #2584.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// FE-PLANNER-STOPNUM-001 to -002: the one stop count the map's pins and the plan's rows read (#2584).
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { Assignment } from '../../types';
|
||||
import { stopNumbersOfDay } from './stopNumbers';
|
||||
|
||||
const stop = (id: number, order_index: number, place: Partial<NonNullable<Assignment['place']>> | null = {}) =>
|
||||
({ id, order_index, place: place && { id: id * 10, ...place } }) as unknown as Assignment;
|
||||
|
||||
describe('stopNumbersOfDay', () => {
|
||||
it('FE-PLANNER-STOPNUM-001: numbers the stops from 1 in their stored order', () => {
|
||||
const numbers = stopNumbersOfDay([stop(3, 2), stop(1, 0), stop(2, 1)]);
|
||||
expect([...numbers.entries()]).toEqual([
|
||||
[1, 1],
|
||||
[2, 2],
|
||||
[3, 3],
|
||||
]);
|
||||
});
|
||||
|
||||
it('FE-PLANNER-STOPNUM-002: passes over service stops and rows without a place', () => {
|
||||
const numbers = stopNumbersOfDay([stop(1, 0), stop(2, 1, { stop_type: 'fuel' }), stop(3, 2, null), stop(4, 3)]);
|
||||
expect(numbers.get(1)).toBe(1);
|
||||
expect(numbers.has(2)).toBe(false);
|
||||
expect(numbers.has(3)).toBe(false);
|
||||
expect(numbers.get(4)).toBe(2);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { Assignment } from '../../types';
|
||||
import { isServiceStopType } from '../Roadtrip/roadtripModel';
|
||||
|
||||
/**
|
||||
* The number each stop of a day carries, by assignment id: counted from 1 in the
|
||||
* day's stored order. A service stop is passed over rather than counted: the map
|
||||
* draws it without a badge and the rail gives it no number, so a number spent on
|
||||
* it left the pin after a fuel stop wearing "3" where the rail said "2".
|
||||
*
|
||||
* The one count the map's pins and the plan's rows both read (#2584), so the
|
||||
* number beside a stop in the list is the one on its pin.
|
||||
*/
|
||||
export function stopNumbersOfDay(dayAssignments: readonly Assignment[]): Map<number, number> {
|
||||
const numbers = new Map<number, number>();
|
||||
let counted = 0;
|
||||
for (const a of [...dayAssignments].sort((x, y) => x.order_index - y.order_index)) {
|
||||
if (!a.place?.id || isServiceStopType(a.place.stop_type)) continue;
|
||||
counted += 1;
|
||||
numbers.set(a.id, counted);
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
Reference in New Issue
Block a user