From 236c83ec3d454795f6db4c5f9ef75a3115c09b64 Mon Sep 17 00:00:00 2001 From: Alberto-Audrix Date: Mon, 5 Oct 2026 14:56:19 +0700 Subject: [PATCH] adjust dashboard berat page to match dashboard-cpsp --- components/WeightMonitoringPage.tsx | 40 ++++++++++------------------- utils/weight.ts | 8 +++++- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/components/WeightMonitoringPage.tsx b/components/WeightMonitoringPage.tsx index e4ff12d..3561d06 100644 --- a/components/WeightMonitoringPage.tsx +++ b/components/WeightMonitoringPage.tsx @@ -2,8 +2,12 @@ import React, { useEffect, useMemo, useState } from 'react'; import { api, ApiError, errorMessage } from '../services/apiClient.ts'; import type { ChickenWeight, LatestAvg } from '../types/api.ts'; import { useFarm } from '../context/FarmContext.tsx'; -import { Banner, EmptyFarm, Spinner } from './ui/Feedback.tsx'; -import { formatDateId, formatNumber } from '../utils/format.ts'; +import { Banner, EmptyFarm, PageHeader, Spinner } from './ui/Feedback.tsx'; +import { + formatDateId, + formatDateRange, + formatNumber, +} from '../utils/format.ts'; import { formatWeight } from '../utils/weight.ts'; import { buildWeightInsightContext } from '../utils/insightContextBuilders.ts'; import { PageAiInsight } from './shared/PageAiInsight.tsx'; @@ -13,7 +17,7 @@ import DailyWeightGainChart from './weight/DailyWeightGainChart.tsx'; import DailyDetailPanel from './weight/DailyDetailPanel.tsx'; const WeightMonitoringPage: React.FC<{ onSettings: () => void }> = ({ onSettings }) => { - const { selectedCycle, selectedKandang } = useFarm(); + const { selectedCycle, selectedSite, selectedKandang } = useFarm(); const [rows, setRows] = useState([]); const [latest, setLatest] = useState(null); const [loading, setLoading] = useState(false); @@ -119,26 +123,11 @@ const WeightMonitoringPage: React.FC<{ onSettings: () => void }> = ({ onSettings return (
- {/* Header */} -
-
-
- -
-
-

Dashboard Berat Ayam

-

- Analisis pertumbuhan dan kesejahteraan bobot ayam secara real-time. -

- {!loading && latest?.date && ( -

- - Terakhir diperbarui: {formatDateId(latest.date)} -

- )} -
-
-
+ } + subtitle={`Analisis pertumbuhan bobot ayam secara real-time · ${selectedSite?.site_name ?? ''} · ${selectedKandang?.kandang_name ?? ''} · Siklus ${formatDateRange(selectedCycle.start_date, selectedCycle.end_date)}`} + /> {error && (
@@ -295,9 +284,8 @@ const WeightMonitoringPage: React.FC<{ onSettings: () => void }> = ({ onSettings

Informasi Pembaruan Data

    -
  • • Data berat diperbarui lewat Sync di header (dari site dashboard)
  • -
  • • Grafik menampilkan data dari awal siklus hingga hari ini
  • -
  • • Target berat menggunakan standar performa Ross 308
  • +
  • • Hari 0 memakai berat DOC dan uniformity 0%
  • +
  • • Target berat menggunakan standar performa berdasarkan DOC
diff --git a/utils/weight.ts b/utils/weight.ts index c1f7365..f450a47 100644 --- a/utils/weight.ts +++ b/utils/weight.ts @@ -61,6 +61,7 @@ function pickStandardValues(docWeight: number): number[] { /** Target body weight (grams) for a given age from the Ross 308 DOC-weight table. */ export function getTargetWeightForAge(age: number, docWeight: number): number | null { + if (age === 0) return docWeight > 0 ? docWeight : null; const values = pickStandardValues(docWeight); if (age < 1 || age > values.length) return null; return values[age - 1] ?? null; @@ -69,7 +70,12 @@ export function getTargetWeightForAge(age: number, docWeight: number): number | /** Target daily weight gain (grams/day) for a given age from the standard. */ export function getTargetGainForAge(age: number, docWeight: number): number | null { const values = pickStandardValues(docWeight); - if (age < 2 || age > values.length) return null; + if (age < 1 || age > values.length) return null; + if (age === 1) { + const current = values[0]; + if (current == null || docWeight <= 0) return null; + return current - docWeight; + } const current = values[age - 1]; const previous = values[age - 2]; if (current == null || previous == null) return null;