- {row.original.workingStores.map((magasin) => (
-
- {magasin.charAt(0).toUpperCase()}
-
- ))}
+ {row.original.workingStores.map((magasin) => {
+ const colors = getStoreColor(magasin);
+ return (
+
+ {magasin.charAt(0).toUpperCase()}
+
+ );
+ })}
),
diff --git a/src/features/grid/components/nomenclature-filter.tsx b/src/features/grid/components/nomenclature-filter.tsx
new file mode 100644
index 0000000..925df43
--- /dev/null
+++ b/src/features/grid/components/nomenclature-filter.tsx
@@ -0,0 +1,115 @@
+"use client";
+
+import * as React from "react";
+import { ChevronRight, Search, X } from "lucide-react";
+import { cn } from "@/lib/utils";
+import { useRouter, useSearchParams } from "next/navigation";
+
+interface NomenclatureFilterProps {
+ hierarchy: any;
+ className?: string;
+}
+
+export function NomenclatureFilter({ hierarchy, className }: NomenclatureFilterProps) {
+ const router = useRouter();
+ const searchParams = useSearchParams();
+
+ const selected1 = searchParams.get("code1");
+ const selected2 = searchParams.get("code2");
+ const selected3 = searchParams.get("code3");
+
+ const updateFilter = (params: Record) => {
+ const nextParams = new URLSearchParams(searchParams.toString());
+ Object.entries(params).forEach(([key, value]) => {
+ if (value) nextParams.set(key, value);
+ else nextParams.delete(key);
+ });
+
+ // Reset children if parent changes
+ if (params.code1 !== undefined) {
+ nextParams.delete("code2");
+ nextParams.delete("code3");
+ }
+ if (params.code2 !== undefined) {
+ nextParams.delete("code3");
+ }
+
+ router.push(`/grid?${nextParams.toString()}`);
+ };
+
+ const l1Options = Object.entries(hierarchy).map(([code, data]: [string, any]) => ({
+ code,
+ label: data.label
+ })).sort((a, b) => a.code.localeCompare(b.code));
+
+ const l2Options = selected1 && hierarchy[selected1]
+ ? Object.entries(hierarchy[selected1].children).map(([code, data]: [string, any]) => ({
+ code,
+ label: data.label
+ })).sort((a, b) => a.code.localeCompare(b.code))
+ : [];
+
+ const l3Options = selected1 && selected2 && hierarchy[selected1]?.children[selected2]
+ ? hierarchy[selected1].children[selected2].children
+ .sort((a: any, b: any) => a.code.localeCompare(b.code))
+ : [];
+
+ return (
+
+ {/* Level 1 */}
+
+
+
+
+ {/* Level 2 */}
+
+
+
+
+ {/* Level 3 */}
+
+
+ {(selected1 || selected2 || selected3) && (
+
+ )}
+
+ );
+}
diff --git a/src/features/grid/store/use-grid-store.ts b/src/features/grid/store/use-grid-store.ts
index 9647e4c..487f3e7 100644
--- a/src/features/grid/store/use-grid-store.ts
+++ b/src/features/grid/store/use-grid-store.ts
@@ -45,6 +45,8 @@ export const useGridStore = create()(
filters: {
magasin: null,
codeFournisseur: null,
+ code1: null,
+ code2: null,
code3: null,
codeGamme: null,
search: "",
diff --git a/src/types/grid.ts b/src/types/grid.ts
index e0f80bc..8121dc2 100644
--- a/src/types/grid.ts
+++ b/src/types/grid.ts
@@ -13,6 +13,10 @@ export interface VenteProduit {
gtin: string | null;
reference: string | null;
codeGamme: GammeCode | null;
+ code1: string | null;
+ libelleNiveau1: string | null;
+ code2: string | null;
+ libelleNiveau2: string | null;
code3: string | null;
libelle3: string | null;
magasin: string;
@@ -36,6 +40,10 @@ export interface ProductRow {
libelle1: string;
gtin: string;
reference: string;
+ code1: string;
+ libelleNiveau1: string;
+ code2: string;
+ libelleNiveau2: string;
code3: string;
libelle3: string;
codeGamme: GammeCode | null;
@@ -66,6 +74,8 @@ export interface GridSummary {
export interface GridFilters {
magasin: string | null;
codeFournisseur: string | null;
+ code1: string | null;
+ code2: string | null;
code3: string | null;
codeGamme: GammeCode | null;
search: string;