diff --git a/src/components/creation/MetafieldResolver.tsx b/src/components/creation/MetafieldResolver.tsx index 719b329..3722768 100644 --- a/src/components/creation/MetafieldResolver.tsx +++ b/src/components/creation/MetafieldResolver.tsx @@ -1,5 +1,5 @@ 'use client' -import { useState, useEffect } from 'react' +import { useState, useEffect, useRef } from 'react' import type { MetafieldDefinition, MetafieldResolution } from '@/types/creation' import { normalizeMetafieldKey } from '@/lib/shopifyMetafields' @@ -15,6 +15,9 @@ export function MetafieldResolver({ specificColumns, onResolved }: Props) { const [resolutions, setResolutions] = useState>({}) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) + const [searches, setSearches] = useState>({}) + const [openDropdown, setOpenDropdown] = useState(null) + const dropdownRef = useRef(null) useEffect(() => { if (specificColumns.length === 0) { setLoading(false); onResolved([]); return } @@ -47,6 +50,16 @@ export function MetafieldResolver({ specificColumns, onResolved }: Props) { setResolutions(prev => ({ ...prev, [col]: { ...prev[col], ...partial } })) } + const filteredDefs = (col: string) => { + const q = (searches[col] ?? '').toLowerCase() + if (!q) return definitions + return definitions.filter(d => + d.name.toLowerCase().includes(q) || + d.key.toLowerCase().includes(q) || + d.namespace.toLowerCase().includes(q) + ) + } + if (loading) return

Analyse des métachamps Shopify…

if (error) return

{error}

if (specificColumns.length === 0) return

Aucune colonne spécifique détectée.

@@ -133,16 +146,45 @@ export function MetafieldResolver({ specificColumns, onResolved }: Props) { )} {res.action === 'map' && ( -
+
- + {res.existingDefinitionId ? ( +
+ + {definitions.find(d => d.id === res.existingDefinitionId)?.name ?? res.key} ({res.namespace}.{res.key}) + + +
+ ) : ( +
+ { setSearches(p => ({ ...p, [col]: e.target.value })); setOpenDropdown(col) }} + onFocus={() => setOpenDropdown(col)} + placeholder="Rechercher un métachamp…" + className="w-full bg-slate-600 border border-slate-500 rounded px-2 py-1 text-xs text-white focus:outline-none focus:ring-1 focus:ring-blue-500" + /> + {openDropdown === col && ( +
+ {filteredDefs(col).length === 0 ? ( +

Aucun résultat

+ ) : filteredDefs(col).map(d => ( + + ))} +
+ )} +
+ )}
)}