Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e2aa9366f | ||
|
|
270652f1a8 | ||
|
|
56d8818581 | ||
|
|
f676b94e36 | ||
|
|
cf8dceb014 | ||
|
|
ac4b50293e | ||
|
|
802544e452 | ||
|
|
8205fee420 | ||
|
|
4869756957 |
No files matched your search
@@ -37,12 +37,16 @@ jobs:
|
||||
docker run --rm -v "$PWD/frontend:/src:ro" -w /tmp/app node:22-alpine sh -lc "cp -a /src/. /tmp/app && npm ci && npm run build"
|
||||
|
||||
- name: Validate dev compose config
|
||||
env:
|
||||
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
||||
run: |
|
||||
set -e
|
||||
cd /docker/FlockPal-dev
|
||||
docker compose -f docker-compose.dev.yaml config --quiet
|
||||
|
||||
- name: Deploy dev
|
||||
env:
|
||||
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
||||
run: |
|
||||
set -e
|
||||
cd /docker/FlockPal-dev
|
||||
@@ -53,7 +57,6 @@ jobs:
|
||||
env:
|
||||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||
JOB_STATUS: ${{ job.status }}
|
||||
DEPLOY_ENVIRONMENT: dev
|
||||
run: |
|
||||
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
|
||||
echo "DISCORD_WEBHOOK_URL is not configured; skipping Discord notification."
|
||||
@@ -61,14 +64,53 @@ jobs:
|
||||
fi
|
||||
|
||||
if [ "$JOB_STATUS" = "success" ]; then
|
||||
STATUS_LABEL="SUCCESS"
|
||||
STATUS_TITLE="Deploy succeeded"
|
||||
COLOR=65280
|
||||
else
|
||||
STATUS_LABEL="FAILED"
|
||||
STATUS_TITLE="Deploy failed"
|
||||
COLOR=16711680
|
||||
fi
|
||||
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
AVATAR_URL="${{ vars.DISCORD_AVATAR_URL }}"
|
||||
AVATAR_URL="${AVATAR_URL:-https://www.flockpal.app/FlockPal-Paint.png}"
|
||||
COMMIT_MESSAGE="$(git -C /docker/FlockPal-dev log -1 --pretty=%s 2>/dev/null || printf '%s' '${{ github.sha }}')"
|
||||
json_escape() {
|
||||
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
|
||||
}
|
||||
BRANCH="$(json_escape '${{ github.ref_name }}')"
|
||||
MESSAGE="$(json_escape "$COMMIT_MESSAGE")"
|
||||
AVATAR_URL="$(json_escape "$AVATAR_URL")"
|
||||
|
||||
cat > /tmp/discord-payload.json <<EOF
|
||||
{
|
||||
"username": "FlockPal Build",
|
||||
"avatar_url": "${AVATAR_URL}",
|
||||
"embeds": [
|
||||
{
|
||||
"title": "${STATUS_TITLE}",
|
||||
"url": "${RUN_URL}",
|
||||
"description": "FlockPal dev deploy",
|
||||
"color": ${COLOR},
|
||||
"fields": [
|
||||
{
|
||||
"name": "Branch",
|
||||
"value": "${BRANCH}",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Message",
|
||||
"value": "${MESSAGE}",
|
||||
"inline": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
curl --fail --show-error --silent \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"content\":\"[${STATUS_LABEL}] FlockPal ${DEPLOY_ENVIRONMENT} deploy completed with status: ${JOB_STATUS}\\nBranch: ${{ github.ref_name }}\\nCommit: ${{ github.sha }}\\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \
|
||||
-d @/tmp/discord-payload.json \
|
||||
"$DISCORD_WEBHOOK_URL" || echo "Discord notification failed."
|
||||
|
||||
deploy-prod:
|
||||
@@ -99,12 +141,16 @@ jobs:
|
||||
docker run --rm -v "$PWD/frontend:/src:ro" -w /tmp/app node:22-alpine sh -lc "cp -a /src/. /tmp/app && npm ci && npm run build"
|
||||
|
||||
- name: Validate prod compose config
|
||||
env:
|
||||
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
||||
run: |
|
||||
set -e
|
||||
cd /docker/FlockPal
|
||||
docker compose -f docker-compose.prod.yml config --quiet
|
||||
|
||||
- name: Deploy prod
|
||||
env:
|
||||
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
||||
run: |
|
||||
set -e
|
||||
cd /docker/FlockPal
|
||||
@@ -121,7 +167,6 @@ jobs:
|
||||
env:
|
||||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||
JOB_STATUS: ${{ job.status }}
|
||||
DEPLOY_ENVIRONMENT: production
|
||||
run: |
|
||||
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
|
||||
echo "DISCORD_WEBHOOK_URL is not configured; skipping Discord notification."
|
||||
@@ -129,12 +174,51 @@ jobs:
|
||||
fi
|
||||
|
||||
if [ "$JOB_STATUS" = "success" ]; then
|
||||
STATUS_LABEL="SUCCESS"
|
||||
STATUS_TITLE="Deploy succeeded"
|
||||
COLOR=65280
|
||||
else
|
||||
STATUS_LABEL="FAILED"
|
||||
STATUS_TITLE="Deploy failed"
|
||||
COLOR=16711680
|
||||
fi
|
||||
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
AVATAR_URL="${{ vars.DISCORD_AVATAR_URL }}"
|
||||
AVATAR_URL="${AVATAR_URL:-https://www.flockpal.app/FlockPal-Paint.png}"
|
||||
COMMIT_MESSAGE="$(git -C /docker/FlockPal log -1 --pretty=%s 2>/dev/null || printf '%s' '${{ github.sha }}')"
|
||||
json_escape() {
|
||||
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
|
||||
}
|
||||
BRANCH="$(json_escape '${{ github.ref_name }}')"
|
||||
MESSAGE="$(json_escape "$COMMIT_MESSAGE")"
|
||||
AVATAR_URL="$(json_escape "$AVATAR_URL")"
|
||||
|
||||
cat > /tmp/discord-payload.json <<EOF
|
||||
{
|
||||
"username": "FlockPal Build",
|
||||
"avatar_url": "${AVATAR_URL}",
|
||||
"embeds": [
|
||||
{
|
||||
"title": "${STATUS_TITLE}",
|
||||
"url": "${RUN_URL}",
|
||||
"description": "FlockPal production deploy",
|
||||
"color": ${COLOR},
|
||||
"fields": [
|
||||
{
|
||||
"name": "Branch",
|
||||
"value": "${BRANCH}",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Message",
|
||||
"value": "${MESSAGE}",
|
||||
"inline": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
curl --fail --show-error --silent \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"content\":\"[${STATUS_LABEL}] FlockPal ${DEPLOY_ENVIRONMENT} deploy completed with status: ${JOB_STATUS}\\nBranch: ${{ github.ref_name }}\\nCommit: ${{ github.sha }}\\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \
|
||||
-d @/tmp/discord-payload.json \
|
||||
"$DISCORD_WEBHOOK_URL" || echo "Discord notification failed."
|
||||
@@ -103,7 +103,7 @@ curl -H "Authorization: Bearer <admin-token>" https://your-host/api/metrics
|
||||
- `FRONTEND_URL`
|
||||
- `BACKEND_URL`
|
||||
- `VITE_API_BASE_URL`
|
||||
- `MAPBOX_ACCESS_TOKEN`
|
||||
- `MAPBOX_ACCESS_TOKEN` as a Gitea Actions secret for automated deployments (or in `.env` for manual Compose deployments)
|
||||
- `REDIS_URL`
|
||||
- `IMAGE_STORAGE_PROVIDER`
|
||||
- `S3_ENDPOINT`
|
||||
|
||||
+3
-5
@@ -657,7 +657,6 @@ const normalizeBird = (row: BirdRow) => ({
|
||||
publicProfileEnabled: row.public_profile_enabled ?? false,
|
||||
memorializedAt: row.memorialized_at,
|
||||
memorializedOn: row.memorialized_on,
|
||||
memorialNote: row.memorial_note,
|
||||
notifyOnMemorialDay: row.notify_on_memorial_day,
|
||||
createdAt: row.created_at,
|
||||
latestWeightGrams: row.latest_weight_grams ? Number(row.latest_weight_grams) : null,
|
||||
@@ -1712,9 +1711,7 @@ const buildBirdMilestoneReminderCopy = (reminder: BirdMilestoneReminderCandidate
|
||||
yearCount > 0
|
||||
? `From our flock to yours, holding ${reminder.name}'s memory close on this ${formatOrdinal(yearCount)} memorial day.`
|
||||
: `From our flock to yours, holding ${reminder.name}'s memory close today.`,
|
||||
body: reminder.memorial_note
|
||||
? reminder.memorial_note
|
||||
: 'A quiet moment for the feathers, songs, routines, and happy memories that still stay with you.',
|
||||
body: 'A quiet moment for the feathers, songs, routines, and happy memories that still stay with you.',
|
||||
milestoneLabel: yearCount > 0 ? `${formatOrdinal(yearCount)} Memorial Day` : 'Memorial Day on file',
|
||||
};
|
||||
}
|
||||
@@ -3569,6 +3566,7 @@ app.post('/api/birds', requireAuth, requireWriteAccess, requireWorkspaceRole(['o
|
||||
toWorkspaceId: req.auth!.workspace.id,
|
||||
locationLabel: bird!.location_label,
|
||||
locationDetails: bird!.location_details,
|
||||
eventDate: emptyToNull(parsed.data.locationDate),
|
||||
createdByUserId: req.auth!.user.id,
|
||||
});
|
||||
res.status(201).json({ bird: normalizeBird(bird!) });
|
||||
@@ -3948,6 +3946,7 @@ app.put('/api/birds/:birdId', requireAuth, requireWriteAccess, requireWorkspaceR
|
||||
toWorkspaceId: req.auth!.workspace.id,
|
||||
locationLabel: bird.location_label,
|
||||
locationDetails: bird.location_details,
|
||||
eventDate: emptyToNull(parsed.data.locationDate),
|
||||
createdByUserId: req.auth!.user.id,
|
||||
});
|
||||
}
|
||||
@@ -4015,7 +4014,6 @@ app.post('/api/birds/:birdId/memorialize', requireAuth, requireWriteAccess, requ
|
||||
birdId: req.params.birdId,
|
||||
workspaceId: req.auth!.workspace.id,
|
||||
memorializedOn: parsed.data.memorializedOn,
|
||||
memorialNote: emptyToNull(parsed.data.memorialNote),
|
||||
notifyOnMemorialDay: parsed.data.notifyOnMemorialDay ?? false,
|
||||
});
|
||||
|
||||
|
||||
@@ -235,7 +235,6 @@ export const ensureSchema = async (database: DatabaseClient = db) => {
|
||||
public_profile_enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
memorialized_at TIMESTAMPTZ,
|
||||
memorialized_on DATE,
|
||||
memorial_note VARCHAR(1000),
|
||||
notify_on_memorial_day BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
@@ -265,7 +264,6 @@ export const ensureSchema = async (database: DatabaseClient = db) => {
|
||||
ADD COLUMN IF NOT EXISTS public_profile_enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS memorialized_at TIMESTAMPTZ,
|
||||
ADD COLUMN IF NOT EXISTS memorialized_on DATE,
|
||||
ADD COLUMN IF NOT EXISTS memorial_note VARCHAR(1000),
|
||||
ADD COLUMN IF NOT EXISTS notify_on_memorial_day BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
|
||||
ALTER TABLE birds
|
||||
|
||||
@@ -32,7 +32,7 @@ export const birdResponse = z.object({
|
||||
photoDataUrl: text.describe('Photo URL or legacy data URL. Storage-backed URLs expire; refresh the bird list to obtain a new URL.'),
|
||||
photoObjectKey: text, photoContentType: text, photoUpdatedAt: timestamp.nullable(),
|
||||
notifyOnDob: z.boolean(), notifyOnGotchaDay: z.boolean(), publicProfileCode: text, publicProfileEnabled: z.boolean(),
|
||||
memorializedAt: timestamp.nullable(), memorializedOn: date.nullable(), memorialNote: text,
|
||||
memorializedAt: timestamp.nullable(), memorializedOn: date.nullable(),
|
||||
notifyOnMemorialDay: z.boolean(), createdAt: timestamp,
|
||||
latestWeightGrams: z.number().nullable(), latestRecordedOn: date.nullable(),
|
||||
});
|
||||
|
||||
@@ -48,7 +48,6 @@ const birdSelectFields = `
|
||||
birds.public_profile_enabled,
|
||||
birds.memorialized_at,
|
||||
birds.memorialized_on::text,
|
||||
birds.memorial_note,
|
||||
birds.notify_on_memorial_day,
|
||||
birds.created_at,
|
||||
latest.weight_grams AS latest_weight_grams,
|
||||
@@ -544,7 +543,7 @@ export const createBird = async ({
|
||||
const result = await db.query<BirdRow>(
|
||||
`INSERT INTO birds (id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth, gotcha_day, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled)
|
||||
VALUES (COALESCE($1::uuid, gen_random_uuid()), $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at, NULL::text AS latest_weight_grams, NULL::text AS latest_recorded_on`,
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at, NULL::text AS latest_weight_grams, NULL::text AS latest_recorded_on`,
|
||||
[
|
||||
birdId ?? null,
|
||||
workspaceId,
|
||||
@@ -662,7 +661,7 @@ export const updateBird = async ({
|
||||
WHERE id = $1
|
||||
AND workspace_id = $26
|
||||
AND memorialized_at IS NULL
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at,
|
||||
(
|
||||
SELECT weight_grams::text
|
||||
FROM weight_records
|
||||
@@ -714,25 +713,22 @@ export const memorializeBird = async ({
|
||||
birdId,
|
||||
workspaceId,
|
||||
memorializedOn,
|
||||
memorialNote,
|
||||
notifyOnMemorialDay,
|
||||
}: {
|
||||
birdId: string;
|
||||
workspaceId: number;
|
||||
memorializedOn: string;
|
||||
memorialNote: string | null;
|
||||
notifyOnMemorialDay: boolean;
|
||||
}) => {
|
||||
const result = await db.query<BirdRow>(
|
||||
`UPDATE birds
|
||||
SET memorialized_at = CURRENT_TIMESTAMP,
|
||||
memorialized_on = $3,
|
||||
memorial_note = $4,
|
||||
notify_on_memorial_day = $5
|
||||
notify_on_memorial_day = $4
|
||||
WHERE id = $1
|
||||
AND workspace_id = $2
|
||||
AND memorialized_at IS NULL
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at,
|
||||
(
|
||||
SELECT weight_grams::text
|
||||
FROM weight_records
|
||||
@@ -747,7 +743,7 @@ export const memorializeBird = async ({
|
||||
ORDER BY recorded_on DESC
|
||||
LIMIT 1
|
||||
) AS latest_recorded_on`,
|
||||
[birdId, workspaceId, memorializedOn, memorialNote, notifyOnMemorialDay],
|
||||
[birdId, workspaceId, memorializedOn, notifyOnMemorialDay],
|
||||
);
|
||||
|
||||
return result.rows[0] ?? null;
|
||||
@@ -768,7 +764,7 @@ export const updateMemorialReminderPreference = async ({
|
||||
WHERE id = $1
|
||||
AND workspace_id = $2
|
||||
AND memorialized_at IS NOT NULL
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at,
|
||||
(
|
||||
SELECT weight_grams::text
|
||||
FROM weight_records
|
||||
@@ -796,7 +792,7 @@ export const transferBirdToWorkspace = async (birdId: string, sourceWorkspaceId:
|
||||
WHERE id = $1
|
||||
AND workspace_id = $2
|
||||
AND memorialized_at IS NULL
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
|
||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at,
|
||||
(
|
||||
SELECT weight_grams::text
|
||||
FROM weight_records
|
||||
|
||||
@@ -104,6 +104,7 @@ export const locationSearchSchema = z.object({
|
||||
});
|
||||
|
||||
export const birdSchema = z.object({
|
||||
locationDate: dateStringSchema.optional().or(z.literal('')),
|
||||
name: z.string().trim().min(1).max(120),
|
||||
tagId: z.string().trim().max(80).optional().or(z.literal('')),
|
||||
species: z.string().trim().min(1).max(120),
|
||||
@@ -129,7 +130,6 @@ export const birdSchema = z.object({
|
||||
|
||||
export const memorializeBirdSchema = z.object({
|
||||
memorializedOn: dateStringSchema,
|
||||
memorialNote: z.string().trim().max(1000).optional().or(z.literal('')),
|
||||
notifyOnMemorialDay: z.boolean().optional(),
|
||||
});
|
||||
|
||||
|
||||
@@ -121,7 +121,6 @@ export type BirdRow = {
|
||||
public_profile_enabled: boolean;
|
||||
memorialized_at: string | null;
|
||||
memorialized_on: string | null;
|
||||
memorial_note: string | null;
|
||||
notify_on_memorial_day: boolean;
|
||||
created_at: string;
|
||||
latest_weight_grams: string | null;
|
||||
|
||||
+45
-42
@@ -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';
|
||||
@@ -65,7 +66,6 @@ type Bird = {
|
||||
publicProfileEnabled: boolean;
|
||||
memorializedAt: string | null;
|
||||
memorializedOn: string | null;
|
||||
memorialNote: string | null;
|
||||
notifyOnMemorialDay: boolean;
|
||||
createdAt: string;
|
||||
latestWeightGrams: number | null;
|
||||
@@ -272,6 +272,7 @@ type FlockNoteFormState = {
|
||||
};
|
||||
|
||||
type BirdFormState = {
|
||||
locationDate: string;
|
||||
name: string;
|
||||
tagId: string;
|
||||
species: string;
|
||||
@@ -335,7 +336,6 @@ type PublicBirdProfile = {
|
||||
|
||||
type MemorializeBirdFormState = {
|
||||
memorializedOn: string;
|
||||
memorialNote: string;
|
||||
notifyOnMemorialDay: boolean;
|
||||
};
|
||||
|
||||
@@ -814,6 +814,7 @@ const VerifiedLocationSearchField = ({
|
||||
};
|
||||
|
||||
const emptyBirdForm: BirdFormState = {
|
||||
locationDate: '',
|
||||
name: '',
|
||||
tagId: '',
|
||||
species: '',
|
||||
@@ -856,7 +857,6 @@ const emptyVeterinaryInfoForm: VeterinaryInfoFormState = {
|
||||
|
||||
const emptyMemorializeBirdForm = (): MemorializeBirdFormState => ({
|
||||
memorializedOn: new Date().toISOString().slice(0, 10),
|
||||
memorialNote: '',
|
||||
notifyOnMemorialDay: false,
|
||||
});
|
||||
|
||||
@@ -969,6 +969,7 @@ const ProviderIcon = ({ providerKey }: { providerKey: AuthProvider['providerKey'
|
||||
const sortBirdsByName = (nextBirds: Bird[]) => [...nextBirds].sort((left, right) => left.name.localeCompare(right.name));
|
||||
|
||||
const toBirdForm = (bird: Bird): BirdFormState => ({
|
||||
locationDate: '',
|
||||
name: bird.name,
|
||||
tagId: bird.tagId ?? '',
|
||||
species: bird.species,
|
||||
@@ -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) => ({
|
||||
@@ -3991,7 +3992,7 @@ function App() {
|
||||
const response = await apiFetch(isEditing ? `/birds/${editingBirdId}` : '/birds', authToken, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ...birdForm, hatchDay: birdForm.dateOfBirth, locationLabel }),
|
||||
body: JSON.stringify({ ...birdForm, hatchDay: birdForm.dateOfBirth, locationLabel, locationDate: birdForm.locationDate || getLocalDateString() }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -6589,27 +6590,6 @@ function App() {
|
||||
) : null}
|
||||
</div>
|
||||
</label>
|
||||
<div className="settings-inline-header wide-field">
|
||||
<p className="eyebrow">Location</p>
|
||||
<h3>Mappable location</h3>
|
||||
</div>
|
||||
<VerifiedLocationSearchField
|
||||
label="Location"
|
||||
location={birdForm.locationDetails}
|
||||
fallbackLabel={birdForm.locationLabel}
|
||||
searchState={birdLocationSearch}
|
||||
onSearchStateChange={setBirdLocationSearch}
|
||||
onSearch={() => searchVerifiedLocations(birdLocationSearch, setBirdLocationSearch)}
|
||||
onSelect={(location) => {
|
||||
const locationLabel = formatVerifiedLocationLabel(location);
|
||||
setBirdForm({ ...birdForm, locationDetails: location, locationLabel });
|
||||
setBirdLocationSearch({ ...emptyLocationSearchState, query: locationLabel });
|
||||
}}
|
||||
onClear={() => {
|
||||
setBirdForm({ ...birdForm, locationDetails: emptyVerifiedLocationDetails, locationLabel: '' });
|
||||
setBirdLocationSearch(emptyLocationSearchState);
|
||||
}}
|
||||
/>
|
||||
<div className="segmented-field wide-field">
|
||||
<span>Gender</span>
|
||||
<div className="segmented-control" role="radiogroup" aria-label="Bird gender">
|
||||
@@ -6748,6 +6728,37 @@ function App() {
|
||||
))}
|
||||
</div>
|
||||
</label>
|
||||
<div className="settings-inline-header wide-field">
|
||||
<p className="eyebrow">Location</p>
|
||||
<h3>Mappable location</h3>
|
||||
</div>
|
||||
<VerifiedLocationSearchField
|
||||
label="Location"
|
||||
location={birdForm.locationDetails}
|
||||
fallbackLabel={birdForm.locationLabel}
|
||||
searchState={birdLocationSearch}
|
||||
onSearchStateChange={setBirdLocationSearch}
|
||||
onSearch={() => searchVerifiedLocations(birdLocationSearch, setBirdLocationSearch)}
|
||||
onSelect={(location) => {
|
||||
const locationLabel = formatVerifiedLocationLabel(location);
|
||||
setBirdForm({ ...birdForm, locationDetails: location, locationLabel });
|
||||
setBirdLocationSearch({ ...emptyLocationSearchState, query: locationLabel });
|
||||
}}
|
||||
onClear={() => {
|
||||
setBirdForm({ ...birdForm, locationDetails: emptyVerifiedLocationDetails, locationLabel: '' });
|
||||
setBirdLocationSearch(emptyLocationSearchState);
|
||||
}}
|
||||
/>
|
||||
<label>
|
||||
Location date
|
||||
<input
|
||||
type="date"
|
||||
value={birdForm.locationDate || getLocalDateString()}
|
||||
onChange={(event) => setBirdForm({ ...birdForm, locationDate: event.target.value })}
|
||||
required
|
||||
/>
|
||||
<span className="muted">Date this location took effect. Used when adding a bird or changing its location.</span>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
<section className="settings-nested-card">
|
||||
@@ -6996,14 +7007,6 @@ function App() {
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label className="wide-field">
|
||||
Memorial note
|
||||
<textarea
|
||||
rows={3}
|
||||
value={memorializeBirdForm.memorialNote}
|
||||
onChange={(event) => setMemorializeBirdForm({ ...memorializeBirdForm, memorialNote: event.target.value })}
|
||||
/>
|
||||
</label>
|
||||
<div className="button-row care-form-actions">
|
||||
<button className="danger-button" type="submit" disabled={memorializingBird || activeMembership?.role !== 'owner'}>
|
||||
{memorializingBird ? 'Memorializing...' : `Memorialize ${selectedBird.name}`}
|
||||
@@ -7870,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>
|
||||
@@ -7920,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}
|
||||
@@ -7965,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