fix and adjust main dashboard ai insight
This commit is contained in:
1 parent
18790ab8f6
commit
68e0d1a0bb
27 files changed
+360
-107
No files matched your search
@@ -11,7 +11,6 @@ import type {
|
||||
InsightCitation,
|
||||
InsightContext,
|
||||
InsightReportType,
|
||||
InsightSource,
|
||||
InsightStructuredReport,
|
||||
InsightStructuredSection,
|
||||
InsightStatusLabel,
|
||||
@@ -27,15 +26,6 @@ import InsightTrendChart from './shared/InsightTrendChart.tsx';
|
||||
|
||||
const CLIENT_TIMEOUT_MS = 1_200_000; // 20 minutes
|
||||
|
||||
const SOURCE_LABEL: Record<InsightSource, { text: string; cls: string }> = {
|
||||
generated: { text: 'Baru dibuat', cls: 'bg-green-50 text-green-700 border-green-200' },
|
||||
cache: { text: 'Dari cache', cls: 'bg-blue-50 text-blue-700 border-blue-200' },
|
||||
local_fallback: {
|
||||
text: 'Fallback lokal',
|
||||
cls: 'bg-amber-50 text-amber-800 border-amber-200',
|
||||
},
|
||||
};
|
||||
|
||||
const sectionBadgeClasses: Record<InsightStatusLabel, string> = {
|
||||
ok: 'border-emerald-200 bg-emerald-50 text-emerald-700',
|
||||
warning: 'border-amber-200 bg-amber-50 text-amber-700',
|
||||
@@ -179,7 +169,6 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
|
||||
|
||||
const [insightText, setInsightText] = useState('');
|
||||
const [structuredInsight, setStructuredInsight] = useState<InsightStructuredReport | null>(null);
|
||||
const [source, setSource] = useState<InsightSource | null>(null);
|
||||
const [citations, setCitations] = useState<InsightCitation[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [lastUpdated, setLastUpdated] = useState<Date | null>(null);
|
||||
@@ -214,10 +203,9 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
|
||||
const topic = page === 'dashboard' ? 'dashboard' : page === 'panel_iot' ? 'iot_panel' : page;
|
||||
|
||||
const applyInsight = useCallback(
|
||||
(text: string, nextSource: InsightSource, nextCitations?: InsightCitation[]) => {
|
||||
(text: string, nextCitations?: InsightCitation[]) => {
|
||||
setInsightText(text);
|
||||
setStructuredInsight(normalizeStructuredInsight(text));
|
||||
setSource(nextSource);
|
||||
setCitations(nextCitations ?? []);
|
||||
},
|
||||
[]
|
||||
@@ -261,6 +249,8 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
|
||||
contextPayload.eef_terakhir = scopedMetrics.eef;
|
||||
contextPayload.bobot_avg_gram = scopedMetrics.bobot_avg_gram;
|
||||
contextPayload.ayam_hidup_ekor = scopedMetrics.ayam_hidup_ekor;
|
||||
contextPayload.mortalitas_kumulatif_persen =
|
||||
scopedMetrics.mortalitas_kumulatif_persen ?? null;
|
||||
contextPayload.persen_hidup =
|
||||
scopedMetrics.mortalitas_kumulatif_persen == null
|
||||
? null
|
||||
@@ -323,11 +313,7 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
|
||||
throw new Error(apiResult?.message || 'Gagal mengambil insight AI dari server');
|
||||
}
|
||||
|
||||
applyInsight(
|
||||
apiResult.insight_text,
|
||||
apiResult.source ?? (forceRefresh ? 'generated' : 'cache'),
|
||||
apiResult.citations
|
||||
);
|
||||
applyInsight(apiResult.insight_text, apiResult.citations);
|
||||
setLastUpdated(new Date());
|
||||
setDetailsOpen(false);
|
||||
} catch (err) {
|
||||
@@ -424,7 +410,6 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
|
||||
</section>
|
||||
);
|
||||
|
||||
const sourceMeta = source ? SOURCE_LABEL[source] : null;
|
||||
const summary = structuredInsight?.summary;
|
||||
const detailed = structuredInsight?.detailed;
|
||||
|
||||
@@ -675,13 +660,6 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{sourceMeta && (
|
||||
<span
|
||||
className={`inline-flex rounded-full border px-2 py-0.5 text-[10px] font-semibold ${sourceMeta.cls}`}
|
||||
>
|
||||
{sourceMeta.text}
|
||||
</span>
|
||||
)}
|
||||
<button
|
||||
onClick={() => generateInsight(true)}
|
||||
disabled={loading || effectiveKandangId == null}
|
||||
|
||||
Reference in new issue
Block a user