diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f9e4b95..447550f 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,3 +1,4 @@ +import { combineLocationOwnerMarkers } from './birdTimeline'; import { BehaviorJournal } from './BehaviorJournal'; import { useEffect, useMemo, useState, type CSSProperties, type Dispatch, type SetStateAction } from 'react'; import birdSilhouette from './assets/bird-silhouette.jpg'; @@ -1146,7 +1147,7 @@ const formatBirdTimelineTitle = (event: BirdTimelineEvent) => { } if (event.eventType === 'owner_changed') { - return 'Owner record changed'; + return 'Adopted'; } if (event.eventType === 'manual_note') { @@ -1169,7 +1170,7 @@ const formatBirdTimelineDescription = (event: BirdTimelineEvent) => { } if (event.eventType === 'owner_changed') { - return event.locationLabel ? `Owner changed at ${event.locationLabel}` : 'Owner changed'; + return event.locationLabel ? `Adopted at ${event.locationLabel}` : 'Adopted'; } if (event.eventType === 'manual_note') { @@ -1191,7 +1192,7 @@ const formatBirdTimelineSecondary = (event: BirdTimelineEvent) => { } if (event.eventType === 'owner_changed') { - return 'Owner changed without owner name'; + return 'Adoption recorded without owner names'; } return ''; @@ -1246,7 +1247,7 @@ const getBirdTimelineGraphLabel = (event: BirdTimelineEvent) => { } if (event.eventType === 'owner_changed') { - return 'Owner changed'; + return event.locationLabel ? `${compactTimelineLocationLabel(event.locationLabel)} — Adopted` : 'Adopted'; } if (event.eventType === 'transferred') { @@ -1346,7 +1347,7 @@ const compactTimelineLocationLabel = (label: string) => .join(', '); const getBirdTimelineGraphItems = (bird: Bird, events: BirdTimelineEvent[]): BirdTimelineGraphItem[] => { - const graphEvents: BirdTimelineGraphItem[] = sortBirdTimelineEvents(events) + const graphEvents: BirdTimelineGraphItem[] = sortBirdTimelineEvents(combineLocationOwnerMarkers(events, compactTimelineLocationLabel)) .reverse() .filter((event) => event.eventType !== 'profile_created') .map((event) => ({ @@ -7872,7 +7873,7 @@ function App() { }} > - + @@ -7922,8 +7923,8 @@ function App() { } /> - Owner changed - Records a change without owner names. + Adopted + Records an adoption without owner names. ) : null} @@ -7967,7 +7968,7 @@ function App() { ) : (
No timeline events yet - New location and owner changes for {selectedBird.name} will appear here. + New location changes and adoptions for {selectedBird.name} will appear here.
)} diff --git a/frontend/src/birdTimeline.ts b/frontend/src/birdTimeline.ts new file mode 100644 index 0000000..5a89a4e --- /dev/null +++ b/frontend/src/birdTimeline.ts @@ -0,0 +1,26 @@ +type LocationEvent = { + eventType: string; + eventDate: string; + createdAt: string; + locationLabel: string | null; + toWorkspaceId: number | null; +}; + +// Keep the owner marker when it already represents the same dated location. +// The original event list remains unchanged so notes and audit history are retained. +export const combineLocationOwnerMarkers = ( + events: T[], + normalizeLocation: (location: string) => string, +): T[] => { + const key = (event: T) => JSON.stringify([ + event.eventDate || event.createdAt.slice(0, 10), + normalizeLocation(event.locationLabel || '').trim().toLowerCase(), + event.toWorkspaceId, + ]); + const ownerLocations = new Set(events + .filter((event) => event.eventType === 'owner_changed' && event.locationLabel?.trim()) + .map(key)); + return events.filter((event) => + event.eventType !== 'location_updated' || !event.locationLabel?.trim() || !ownerLocations.has(key(event)), + ); +}; diff --git a/frontend/tests/birdTimeline.test.ts b/frontend/tests/birdTimeline.test.ts new file mode 100644 index 0000000..a85eb53 --- /dev/null +++ b/frontend/tests/birdTimeline.test.ts @@ -0,0 +1,23 @@ +import assert from 'node:assert/strict'; +import { test } from 'node:test'; +import { combineLocationOwnerMarkers } from '../src/birdTimeline.ts'; + +const location = { id: 'location', eventType: 'location_updated', eventDate: '2023-04-07', createdAt: '2026-10-07T12:00:00Z', locationLabel: 'Warwick, RI, US', toWorkspaceId: 1 }; +const owner = { ...location, id: 'owner', eventType: 'owner_changed' }; +const normalize = (value: string) => value.replace('United States', 'US'); + +test('combines a same-date location and owner change without modifying saved events', () => { + const events = [location, { ...owner, locationLabel: 'Warwick, RI, United States' }]; + assert.deepEqual(combineLocationOwnerMarkers(events, normalize).map(event => event.id), ['owner']); + assert.equal(events.length, 2); +}); + +test('preserves different dates, locations, flocks, and standalone location changes', () => { + for (const other of [ + { ...owner, eventDate: '2023-04-08' }, + { ...owner, locationLabel: 'Providence, RI, US' }, + { ...owner, toWorkspaceId: 2 }, + { ...owner, locationLabel: null }, + ]) assert.equal(combineLocationOwnerMarkers([location, other], normalize).length, 2); + assert.deepEqual(combineLocationOwnerMarkers([location], normalize), [location]); +});