Merge remote-tracking branch 'origin/dev'
Deploy / deploy-dev (push) Skipped
Deploy / deploy-prod (push) Successful in 2m35s

This commit is contained in:
blaisadmin committed 2026-10-07 21:38:14 -04:00
commit 0e2aa9366f
3 files changed
+59 -9

No files matched your search

+10 -9
View File
@@ -1,3 +1,4 @@
import { combineLocationOwnerMarkers } from './birdTimeline';
import { BehaviorJournal } from './BehaviorJournal'; import { BehaviorJournal } from './BehaviorJournal';
import { useEffect, useMemo, useState, type CSSProperties, type Dispatch, type SetStateAction } from 'react'; import { useEffect, useMemo, useState, type CSSProperties, type Dispatch, type SetStateAction } from 'react';
import birdSilhouette from './assets/bird-silhouette.jpg'; import birdSilhouette from './assets/bird-silhouette.jpg';
@@ -1146,7 +1147,7 @@ const formatBirdTimelineTitle = (event: BirdTimelineEvent) => {
} }
if (event.eventType === 'owner_changed') { if (event.eventType === 'owner_changed') {
return 'Owner record changed'; return 'Adopted';
} }
if (event.eventType === 'manual_note') { if (event.eventType === 'manual_note') {
@@ -1169,7 +1170,7 @@ const formatBirdTimelineDescription = (event: BirdTimelineEvent) => {
} }
if (event.eventType === 'owner_changed') { 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') { if (event.eventType === 'manual_note') {
@@ -1191,7 +1192,7 @@ const formatBirdTimelineSecondary = (event: BirdTimelineEvent) => {
} }
if (event.eventType === 'owner_changed') { if (event.eventType === 'owner_changed') {
return 'Owner changed without owner name'; return 'Adoption recorded without owner names';
} }
return ''; return '';
@@ -1246,7 +1247,7 @@ const getBirdTimelineGraphLabel = (event: BirdTimelineEvent) => {
} }
if (event.eventType === 'owner_changed') { if (event.eventType === 'owner_changed') {
return 'Owner changed'; return event.locationLabel ? `${compactTimelineLocationLabel(event.locationLabel)} — Adopted` : 'Adopted';
} }
if (event.eventType === 'transferred') { if (event.eventType === 'transferred') {
@@ -1346,7 +1347,7 @@ const compactTimelineLocationLabel = (label: string) =>
.join(', '); .join(', ');
const getBirdTimelineGraphItems = (bird: Bird, events: BirdTimelineEvent[]): BirdTimelineGraphItem[] => { const getBirdTimelineGraphItems = (bird: Bird, events: BirdTimelineEvent[]): BirdTimelineGraphItem[] => {
const graphEvents: BirdTimelineGraphItem[] = sortBirdTimelineEvents(events) const graphEvents: BirdTimelineGraphItem[] = sortBirdTimelineEvents(combineLocationOwnerMarkers(events, compactTimelineLocationLabel))
.reverse() .reverse()
.filter((event) => event.eventType !== 'profile_created') .filter((event) => event.eventType !== 'profile_created')
.map((event) => ({ .map((event) => ({
@@ -7872,7 +7873,7 @@ function App() {
}} }}
> >
<option value="location_updated">Location note</option> <option value="location_updated">Location note</option>
<option value="owner_changed">Owner</option> <option value="owner_changed">Adoption</option>
<option value="manual_note">General note</option> <option value="manual_note">General note</option>
</select> </select>
</label> </label>
@@ -7922,8 +7923,8 @@ function App() {
} }
/> />
<span> <span>
<strong>Owner changed</strong> <strong>Adopted</strong>
<small>Records a change without owner names.</small> <small>Records an adoption without owner names.</small>
</span> </span>
</label> </label>
) : null} ) : null}
@@ -7967,7 +7968,7 @@ function App() {
) : ( ) : (
<article className="empty-card"> <article className="empty-card">
<strong>No timeline events yet</strong> <strong>No timeline events yet</strong>
<small>New location and owner changes for {selectedBird.name} will appear here.</small> <small>New location changes and adoptions for {selectedBird.name} will appear here.</small>
</article> </article>
)} )}
</div> </div>
+26
View File
@@ -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 = <T extends LocationEvent>(
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)),
);
};
+23
View File
@@ -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]);
});