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
@@ -12,7 +12,6 @@ import { api, errorMessage } from '../../services/apiClient.ts';
|
||||
import type {
|
||||
InsightCitation,
|
||||
InsightContext,
|
||||
InsightSource,
|
||||
InsightTopic,
|
||||
} from '../../types/api.ts';
|
||||
import { formatRatio } from '../../utils/format.ts';
|
||||
@@ -35,7 +34,6 @@ const _insightMemoryCache = new Map<string, CachedPageInsight>();
|
||||
const _insightInFlight = new Map<string, Promise<void>>();
|
||||
|
||||
type CachedPageInsight = AiResult & {
|
||||
source: InsightSource;
|
||||
citations?: InsightCitation[];
|
||||
};
|
||||
|
||||
@@ -69,15 +67,6 @@ const TOPIC_META: Record<InsightTopic, { title: string; icon: string }> = {
|
||||
dashboard: { title: 'AI Insight — Dashboard', icon: 'fa-brain' },
|
||||
};
|
||||
|
||||
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 renderValue = (val: unknown, suffix: string = ''): string => {
|
||||
if (val === undefined || val === null || val === '') return 'N/A';
|
||||
if (val === UNAVAILABLE) return UNAVAILABLE;
|
||||
@@ -433,7 +422,7 @@ export const PageAiInsight: React.FC<PageAiInsightProps> = ({
|
||||
}
|
||||
const parsed = parseAiResult(raw);
|
||||
if (parsed) {
|
||||
const wrapped: CachedPageInsight = { ...parsed, source: 'cache' };
|
||||
const wrapped: CachedPageInsight = { ...parsed };
|
||||
_insightMemoryCache.set(storageKey, wrapped);
|
||||
if (!isCurrent()) return;
|
||||
setResult(wrapped);
|
||||
@@ -596,7 +585,6 @@ export const PageAiInsight: React.FC<PageAiInsightProps> = ({
|
||||
const wrapped: CachedPageInsight = {
|
||||
summary: parsed.summary,
|
||||
insight: parsed.insight,
|
||||
source: apiResult.source ?? (force ? 'generated' : 'cache'),
|
||||
citations: apiResult.citations,
|
||||
};
|
||||
|
||||
@@ -658,8 +646,6 @@ export const PageAiInsight: React.FC<PageAiInsightProps> = ({
|
||||
return () => clearTimeout(timer);
|
||||
}, [scopeKey]);
|
||||
|
||||
const sourceMeta = result ? SOURCE_LABEL[result.source] : null;
|
||||
|
||||
return (
|
||||
<div className="rounded-xl border border-gray-100 bg-white shadow-sm overflow-hidden mb-6">
|
||||
<div className="flex items-center justify-between px-5 py-3.5 border-b border-gray-100 bg-gray-50/80">
|
||||
@@ -691,13 +677,6 @@ export const PageAiInsight: React.FC<PageAiInsightProps> = ({
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
{sourceMeta && (
|
||||
<span
|
||||
className={`hidden sm:inline-flex rounded-full border px-2 py-0.5 text-[10px] font-semibold ${sourceMeta.cls}`}
|
||||
>
|
||||
{sourceMeta.text}
|
||||
</span>
|
||||
)}
|
||||
<button
|
||||
onClick={() => generate(true)}
|
||||
disabled={loading || selectedKandangId == null}
|
||||
|
||||
Reference in new issue
Block a user