feat(ai): bulk analysis now populates AI insight column with justification and duplicate flag

This commit is contained in:
Michael committed 2026-02-21 21:38:27 +01:00
1 parent a07bad60b2
commit 09f9c0b097
3 files changed
+25 -2

No files matched your search

@@ -59,11 +59,18 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
}
return (
<div className="flex items-start gap-1.5 group cursor-pointer" onClick={handleAnalyze} title="Cliquer pour re-analyser">
<div className="flex flex-col gap-1 group cursor-pointer" onClick={handleAnalyze} title="Cliquer pour re-analyser">
<div className="flex items-start gap-1.5">
<Bot className="w-3.5 h-3.5 mt-0.5 text-indigo-600 dark:text-indigo-400 shrink-0" />
<span className={cn("text-[11px] italic line-clamp-2 leading-[1.3]")} style={{ color: "var(--text-secondary)" }}>
{insight?.insight}
</span>
</div>
{insight?.isDuplicate && (
<span className="inline-flex items-center gap-1 text-[10px] font-bold text-amber-700 dark:text-amber-400 bg-amber-100 dark:bg-amber-900/30 border border-amber-300 dark:border-amber-700 px-1.5 py-0.5 rounded-full w-fit">
⚠️ Doublon probable
</span>
)}
</div>
);
}
@@ -6,10 +6,12 @@ interface AiInsight {
codein: string;
insight: string;
status: "idle" | "loading" | "done" | "error";
isDuplicate?: boolean;
}
interface AiCopilotState {
insights: Record<string, AiInsight>;
setInsight: (codein: string, insight: string, isDuplicate?: boolean) => void;
analyzeProduct: (payload: {
codein: string;
libelle1: string;
@@ -24,6 +26,15 @@ interface AiCopilotState {
export const useAiCopilotStore = create<AiCopilotState>((set) => ({
insights: {},
setInsight: (codein, insight, isDuplicate = false) => {
set((s) => ({
insights: {
...s.insights,
[codein]: { codein, insight, status: "done", isDuplicate },
},
}));
},
analyzeProduct: async (payload) => {
const { codein } = payload;
@@ -2,6 +2,7 @@
import React, { useState } from "react";
import { useGridStore } from "@/features/grid/store/use-grid-store";
import { useAiCopilotStore } from "@/features/ai-copilot/store/use-ai-copilot-store";
import { Sparkles, Loader2, CheckCircle2 } from "lucide-react";
import { ProductRow } from "@/types/grid";
@@ -9,6 +10,7 @@ export function BulkAiAnalyzer() {
const [isAnalyzing, setIsAnalyzing] = useState(false);
const [progress, setProgress] = useState({ current: 0, total: 0, message: "" });
const setDraftGamme = useGridStore(state => state.setDraftGamme);
const setInsight = useAiCopilotStore(state => state.setInsight);
const handleAnalyze = async () => {
const { rows } = useGridStore.getState();
@@ -76,8 +78,11 @@ export function BulkAiAnalyzer() {
if (data && Array.isArray(data.results)) {
data.results.forEach((reco: any) => {
if (reco.codein && reco.recommandationGamme) {
// Add it to the store drafts
// Update the gamme draft
setDraftGamme(reco.codein, reco.recommandationGamme);
// Inject the justification into the AI insight column
const justification = reco.justificationCourte || `Recommandation: Gamme ${reco.recommandationGamme}`;
setInsight(reco.codein, justification, reco.isDuplicate ?? false);
}
});
}