fix panel iot ai insight day x not updated after picking a date and limit setpoint decimal value

This commit is contained in:
Alberto-Audrix committed 2026-10-05 08:56:17 +07:00
1 parent 7dcd7b74cb
commit cceaf38a25
1 file changed
+14 -4
+14 -4
View File
@@ -17,7 +17,7 @@ import type {
InsightJobStage,
InsightTopic,
} from '../../types/api.ts';
import { formatRatio } from '../../utils/format.ts';
import { formatNumber, formatRatio } from '../../utils/format.ts';
import { getCobbStandardForDay } from '../../utils/insightHelpers.ts';
import { parseAiResult, type AiResult } from '../../utils/insightParse.ts';
import {
@@ -210,6 +210,16 @@ export const PageAiInsight: React.FC<PageAiInsightProps> = ({
return [...days].sort((a, b) => a - b);
}, [contextData, scalarScope, chartSpec]);
const contextDay: number | null = React.useMemo(() => {
const raw = contextData as Record<string, unknown> | null | undefined;
if (!raw) return null;
for (const key of ['hari_ke', 'hari', 'day', 'hari_terakhir']) {
const val = raw[key];
if (typeof val === 'number' && Number.isFinite(val)) return val;
}
return null;
}, [contextData]);
const lastAvailableDay: number | null =
availableDays.length > 0 ? availableDays[availableDays.length - 1]! : null;
@@ -220,7 +230,7 @@ export const PageAiInsight: React.FC<PageAiInsightProps> = ({
? selectedDay
: null;
const effectiveDay: number | null =
timeframe === 'harian' ? (activeDay ?? lastAvailableDay) : null;
timeframe === 'harian' ? (activeDay ?? lastAvailableDay ?? contextDay) : null;
const scopeKey = `${cacheKey}-${timeframe}${effectiveDay === null ? '' : `-h${effectiveDay}`}`;
@@ -388,7 +398,7 @@ export const PageAiInsight: React.FC<PageAiInsightProps> = ({
label: 'Suhu Rata-rata Kandang',
value: renderDayRange(lo, hi, ''),
unit: '°C',
context: setpoint === null ? null : `Setpoint: ${setpoint.toLocaleString('id-ID')} °C`,
context: setpoint === null ? null : `Setpoint: ${formatNumber(setpoint, 2, 0)} °C`,
status: (worstDiff === null
? 'unknown'
: worstDiff <= 1
@@ -399,7 +409,7 @@ export const PageAiInsight: React.FC<PageAiInsightProps> = ({
deltaLabel:
signedWorst === null
? null
: `${signedWorst > 0 ? '+' : ''}${signedWorst} °C vs setpoint`,
: `${signedWorst > 0 ? '+' : ''}${formatNumber(signedWorst, 2, 0)} °C vs setpoint`,
};
}