fix day 0 insight main dashboard page

This commit is contained in:
Alberto-Audrix committed 2026-10-01 15:55:09 +07:00
1 parent e1987d6999
commit bc2b260065
6 files changed
+165 -36

No files matched your search

+16 -8
View File
@@ -65,7 +65,7 @@ const parseDayFromPeriod = (period: string | null): number | null => {
const match = String(period).match(/\d+/);
if (!match) return null;
const day = parseInt(match[0], 10);
return Number.isFinite(day) && day > 0 ? day : null;
return Number.isFinite(day) && day >= 0 ? day : null;
};
const stripJsonFences = (text: string) =>
@@ -273,7 +273,8 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
const currentDayVal = contextDay ?? dashboardMetrics?.hari_ke ?? selectedCycle?.current_day ?? 0;
const reportPeriod =
reportType === 'daily'
? (dayPeriod ?? (currentDayVal > 0 ? `Hari ${currentDayVal}` : null))
? (dayPeriod ??
(typeof currentDayVal === 'number' && currentDayVal >= 0 ? `Hari ${currentDayVal}` : null))
: reportType === 'weekly'
? dayPeriod
: null;
@@ -325,18 +326,23 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
setError(null);
try {
const effectiveDay =
typeof currentDayVal === 'number' && currentDayVal >= 0
? currentDayVal
: selectedCycle.current_day;
const contextPayload: InsightContext = {
kandangId: effectiveKandangId,
kandangName: selectedKandang?.kandang_name,
cycleId: selectedCycle.id,
hari_ke: currentDayVal > 0 ? currentDayVal : selectedCycle.current_day,
hari_ke: effectiveDay,
totalDays: selectedCycle.total_days,
...(contextProp ?? {}),
};
// Always stamp required identity after spread so caller cannot clear it.
contextPayload.kandangId = effectiveKandangId;
if (currentDayVal > 0) contextPayload.hari_ke = currentDayVal;
if (typeof currentDayVal === 'number' && currentDayVal >= 0)
contextPayload.hari_ke = currentDayVal;
// Prefer period-scoped display metrics so the model analyzes the same
// numbers the muted rows / tiles show for the selected day.
@@ -539,8 +545,10 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
const summary = structuredInsight?.summary;
const detailed = structuredInsight?.detailed;
const gradeDay = scopedMetrics?.hari_ke ?? (currentDayVal > 0 ? currentDayVal : null);
const fcrStandard = gradeDay ? (getCobbStandardForDay(gradeDay)?.fcr ?? null) : null;
const gradeDay =
scopedMetrics?.hari_ke ??
(typeof currentDayVal === 'number' && currentDayVal >= 0 ? currentDayVal : null);
const fcrStandard = gradeDay != null ? (getCobbStandardForDay(gradeDay)?.fcr ?? null) : null;
const fcrStatus = ((): InsightStatus => {
const actual = scopedMetrics?.fcr ?? null;
@@ -771,13 +779,13 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
<option value="end_cycle">Akhir Siklus</option>
)}
</select>
{reportType === 'daily' && currentDayVal > 0 && (
{reportType === 'daily' && currentDayVal >= 0 && (
<select
value={reportPeriod ?? `Hari ${currentDayVal}`}
onChange={(e) => setDayPeriod(e.target.value)}
className="text-sm border border-gray-200 rounded-lg shadow-sm bg-white px-2 py-1.5"
>
{Array.from({ length: currentDayVal }, (_, i) => i + 1).map((d) => (
{Array.from({ length: currentDayVal + 1 }, (_, i) => i).map((d) => (
<option key={d} value={`Hari ${d}`}>
Hari {d}
</option>