Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e2aa9366f | ||
|
|
270652f1a8 | ||
|
|
56d8818581 |
No files matched your search
+10
-9
@@ -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() {
|
||||
}}
|
||||
>
|
||||
<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>
|
||||
</select>
|
||||
</label>
|
||||
@@ -7922,8 +7923,8 @@ function App() {
|
||||
}
|
||||
/>
|
||||
<span>
|
||||
<strong>Owner changed</strong>
|
||||
<small>Records a change without owner names.</small>
|
||||
<strong>Adopted</strong>
|
||||
<small>Records an adoption without owner names.</small>
|
||||
</span>
|
||||
</label>
|
||||
) : null}
|
||||
@@ -7967,7 +7968,7 @@ function App() {
|
||||
) : (
|
||||
<article className="empty-card">
|
||||
<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>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -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)),
|
||||
);
|
||||
};
|
||||
@@ -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]);
|
||||
});
|
||||
Reference in new issue
Block a user