From 7057ac4f963798cb7a548f6930c5345168dccea1 Mon Sep 17 00:00:00 2001 From: MMD Date: Sun, 20 Sep 2026 21:01:16 +0330 Subject: [PATCH] fix(suppliers): read the supplier's own category instead of inferring it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Supplier topic/categories were derived from quote line items' material category and topic. The catalog v2.7 refactor decoupled materials from categories, so that derivation now yields nothing and every supplier lost its topic/category — the suppliers dashboard rendered without names, because it groups topic → category → supplier. The backend already returns the supplier's own category (category_id FK + nested category{id,slug,name}); adaptSupplier simply never read it. Now it is the primary source, with quote-derived values and the local registry still taking precedence when present. Verified against the live stack: all 7 suppliers return their category from /suppliers, and the suppliers page renders names again. --- frontend/src/lib/api.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 9f9fb63..869747c 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -323,6 +323,9 @@ interface RawSupplier { contact_person?: string | null; tax_id?: string | null; categories?: string[] | null; // متریال‌های تأمین‌شده + // v2.6: هر تأمین‌کننده دقیقاً یک دسته دارد (FK) — بک‌اند این را می‌فرستد + category_id?: string | null; + category?: { id: string; slug: string; name: string } | null; } interface RawProject { id: string; @@ -676,14 +679,24 @@ function deriveSupplierTopics( return rawSuppliers.map((s) => { const t = topics.get(s.id); const c = cats.get(s.id); - // اگر از quotes topic/category پیدا نشد، registry را چک کن - if (!t || t.size === 0) { + const derivedTopic = t && t.size ? [...t][0] : ""; + const derivedCats = c ? [...c].sort((a, b) => a.localeCompare(b, "fa")) : []; + // اگر از quotes چیزی پیدا نشد، registry را چک کن + if (!derivedTopic && !derivedCats.length) { const reg = supplierTopicRegistry.get(s.id); if (reg) { return adaptSupplier(s, reg.topic, reg.categories); } } - return adaptSupplier(s, t ? [...t][0] : "", c ? [...c].sort((a, b) => a.localeCompare(b, "fa")) : []); + // v2.7: متریال‌ها از دسته جدا شدند، پس استنتاج از اقلام پیشنهاد معمولاً + // دسته‌ای نمی‌دهد و صفحه‌ی تأمین‌کننده‌ها بی‌نام می‌شد. دستهٔ ثبت‌شده روی + // خودِ تأمین‌کننده (FK بک‌اند) منبع اصلی است؛ نامش با نام تاپیک‌ها یکی است. + const backendCat = s.category?.name || ""; + return adaptSupplier( + s, + derivedTopic || backendCat, + derivedCats.length ? derivedCats : backendCat ? [backendCat] : [], + ); }); }