From 74454cdc7f46c9aa678f23b56431445da2a45f43 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 8 Mar 2025 14:34:49 -0500 Subject: [PATCH] Show templates from all brands when selected brand has no templates --- .../components/SearchableTemplateSelect.tsx | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/inventory/src/lib/react-spreadsheet-import/src/steps/ValidationStepNew/components/SearchableTemplateSelect.tsx b/inventory/src/lib/react-spreadsheet-import/src/steps/ValidationStepNew/components/SearchableTemplateSelect.tsx index e867565..b3ba9f1 100644 --- a/inventory/src/lib/react-spreadsheet-import/src/steps/ValidationStepNew/components/SearchableTemplateSelect.tsx +++ b/inventory/src/lib/react-spreadsheet-import/src/steps/ValidationStepNew/components/SearchableTemplateSelect.tsx @@ -138,7 +138,11 @@ const SearchableTemplateSelect: React.FC = ({ // First filter by brand if selected let brandFiltered = templates; if (selectedBrand) { - brandFiltered = templates.filter(t => t?.company === selectedBrand); + // Check if the selected brand has any templates + const brandTemplates = templates.filter(t => t?.company === selectedBrand); + + // If the selected brand has templates, use them; otherwise, show all templates + brandFiltered = brandTemplates.length > 0 ? brandTemplates : templates; } // Then filter by search term if provided @@ -268,9 +272,23 @@ const SearchableTemplateSelect: React.FC = ({ {!searchTerm ? ( selectedBrand ? ( - b.id === selectedBrand)?.name || selectedBrand}> - {groupedTemplates[selectedBrand]?.map(template => renderCommandItem(template))} - + groupedTemplates[selectedBrand]?.length > 0 ? ( + b.id === selectedBrand)?.name || selectedBrand}> + {groupedTemplates[selectedBrand]?.map(template => renderCommandItem(template))} + + ) : ( + // If selected brand has no templates, show all brands + Object.entries(groupedTemplates).map(([companyId, companyTemplates]) => { + const brand = brands.find(b => b.id === companyId); + const companyName = brand ? brand.name : companyId; + + return ( + + {companyTemplates.map(template => renderCommandItem(template))} + + ); + }) + ) ) : ( Object.entries(groupedTemplates).map(([companyId, companyTemplates]) => { const brand = brands.find(b => b.id === companyId);