mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
feat: Introduce product assortment grid client and direct PostgreSQL data access for FF Nancy.
This commit is contained in:
1 parent
2e1988a6f5
commit
e391550a30
2 files changed
+20
-9
No files matched your search
@@ -23,9 +23,10 @@ interface GridClientProps {
|
||||
magasin: string;
|
||||
}
|
||||
|
||||
export function GridClient({ initialRows, nomFournisseur, fournisseurs, magasins, magasin }: GridClientProps) {
|
||||
export function GridClient({ initialRows, codeFournisseur, nomFournisseur, fournisseurs, magasins, magasin }: GridClientProps) {
|
||||
const setRows = useGridStore((s) => s.setRows);
|
||||
const setActiveGridQuery = useGridStore((s) => s.setActiveGridQuery);
|
||||
const setFilter = useGridStore((s) => s.setFilter);
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const [selectedCodeins, setSelectedCodeins] = useState<string[]>([]);
|
||||
@@ -52,12 +53,15 @@ export function GridClient({ initialRows, nomFournisseur, fournisseurs, magasins
|
||||
useEffect(() => {
|
||||
if (!isMounted) return;
|
||||
|
||||
// Optimisation : On évite le JSON.parse(JSON.stringify()) qui est très lourd sur 1000 lignes
|
||||
// On passe directement les initialRows au moteur de score, ou on fait une copie superficielle si nécessaire.
|
||||
// Le moteur de score doit idéalement retourner de nouveaux objets.
|
||||
// Réinitialiser les filtres gamme et code3 lors du changement de fournisseur.
|
||||
// Ces filtres sont persistés en localStorage (Zustand persist) et s'appliquent
|
||||
// au nouveau fournisseur, cachant toutes les lignes si le filtre ne correspond pas.
|
||||
setFilter("codeGamme", null);
|
||||
setFilter("code3", null);
|
||||
|
||||
const scoredRows = computeProductScores([...initialRows]);
|
||||
setRows(scoredRows);
|
||||
}, [initialRows, setRows, isMounted]);
|
||||
}, [codeFournisseur, initialRows, setRows, setFilter, isMounted]);
|
||||
|
||||
const handleSave = () => {
|
||||
startTransition(async () => {
|
||||
|
||||
+11
-4
@@ -267,12 +267,19 @@ export async function pgGetNomenclatureByFournisseur(codefou: string): Promise<M
|
||||
// Découverte de la colonne parent : mise en cache module-level (1 seule fois par process)
|
||||
if (_nomenclatureParentCol === undefined) {
|
||||
const metaResult = await db.execute(sql`
|
||||
SELECT column_name FROM information_schema.columns
|
||||
SELECT column_name, data_type FROM information_schema.columns
|
||||
WHERE table_name = 'nomenclature' ORDER BY ordinal_position
|
||||
`);
|
||||
const nomCols = (metaResult.rows as { column_name: string }[]).map(r => r.column_name);
|
||||
console.log("[pg-ff] Nomenclature colonnes:", nomCols.join(", "));
|
||||
_nomenclatureParentCol = nomCols.find(c => /parent/i.test(c) || (c !== "no_id" && /no_id$/i.test(c))) ?? null;
|
||||
const nomCols = (metaResult.rows as { column_name: string; data_type: string }[]);
|
||||
console.log("[pg-ff] Nomenclature colonnes:", nomCols.map(r => `${r.column_name}(${r.data_type})`).join(", "));
|
||||
// Cherche une colonne "parent" qui soit un entier (FK vers no_id du parent)
|
||||
// "chemin_pere" = chemin vers le père en français
|
||||
// On vérifie le data_type : integer/bigint/smallint uniquement (pas text/varchar qui serait un chemin matérialisé)
|
||||
const parentRow = nomCols.find(r =>
|
||||
(/parent|pere|father/i.test(r.column_name) || (r.column_name !== "no_id" && /no_id$/i.test(r.column_name)))
|
||||
&& /int|serial/i.test(r.data_type)
|
||||
);
|
||||
_nomenclatureParentCol = parentRow?.column_name ?? null;
|
||||
console.log("[pg-ff] Nomenclature parentCol:", _nomenclatureParentCol);
|
||||
}
|
||||
const parentCol = _nomenclatureParentCol;
|
||||
|
||||
Reference in new issue
Block a user