Limit editable weight entries to three
This commit is contained in:
@@ -930,7 +930,7 @@ export const updateWeightForBird = async (
|
|||||||
FROM weight_records recent
|
FROM weight_records recent
|
||||||
WHERE recent.bird_id = $2
|
WHERE recent.bird_id = $2
|
||||||
ORDER BY recent.recorded_on DESC, recent.created_at DESC
|
ORDER BY recent.recorded_on DESC, recent.created_at DESC
|
||||||
LIMIT 4
|
LIMIT 3
|
||||||
)
|
)
|
||||||
RETURNING id, bird_id, weight_grams, recorded_on::text, notes`,
|
RETURNING id, bird_id, weight_grams, recorded_on::text, notes`,
|
||||||
[weightId, birdId, weightGrams, recordedOn, notes],
|
[weightId, birdId, weightGrams, recordedOn, notes],
|
||||||
|
|||||||
@@ -877,7 +877,7 @@ const formatWeight = (value: number | null) => (value ? `${value.toFixed(1)} g`
|
|||||||
const formatRange = (minGrams: number, maxGrams: number) => `${minGrams.toFixed(0)}-${maxGrams.toFixed(0)} g`;
|
const formatRange = (minGrams: number, maxGrams: number) => `${minGrams.toFixed(0)}-${maxGrams.toFixed(0)} g`;
|
||||||
const parseDateValue = (value: string) => new Date(`${value}T00:00:00`);
|
const parseDateValue = (value: string) => new Date(`${value}T00:00:00`);
|
||||||
const getEditableWeights = (entries: WeightRecord[]) =>
|
const getEditableWeights = (entries: WeightRecord[]) =>
|
||||||
[...entries].sort((left, right) => right.recordedOn.localeCompare(left.recordedOn)).slice(0, 4);
|
[...entries].sort((left, right) => right.recordedOn.localeCompare(left.recordedOn)).slice(0, 3);
|
||||||
const daysBetweenDates = (startDate: string, endDate: string) =>
|
const daysBetweenDates = (startDate: string, endDate: string) =>
|
||||||
Math.abs(parseDateValue(endDate).getTime() - parseDateValue(startDate).getTime()) / (24 * 60 * 60 * 1000);
|
Math.abs(parseDateValue(endDate).getTime() - parseDateValue(startDate).getTime()) / (24 * 60 * 60 * 1000);
|
||||||
const addYearsToDate = (date: Date, years: number) => {
|
const addYearsToDate = (date: Date, years: number) => {
|
||||||
@@ -3416,7 +3416,7 @@ function App() {
|
|||||||
|
|
||||||
const handleEditWeight = (weight: WeightRecord) => {
|
const handleEditWeight = (weight: WeightRecord) => {
|
||||||
if (!editableWeightIds.has(weight.id)) {
|
if (!editableWeightIds.has(weight.id)) {
|
||||||
setError('Only the 4 most recent weight entries can be edited.');
|
setError('Only the 3 most recent weight entries can be edited.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user