fix(suppliers): read the supplier's own category instead of inferring it
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.
This commit is contained in:
+16
-3
@@ -323,6 +323,9 @@ interface RawSupplier {
|
|||||||
contact_person?: string | null;
|
contact_person?: string | null;
|
||||||
tax_id?: string | null;
|
tax_id?: string | null;
|
||||||
categories?: string[] | null; // متریالهای تأمینشده
|
categories?: string[] | null; // متریالهای تأمینشده
|
||||||
|
// v2.6: هر تأمینکننده دقیقاً یک دسته دارد (FK) — بکاند این را میفرستد
|
||||||
|
category_id?: string | null;
|
||||||
|
category?: { id: string; slug: string; name: string } | null;
|
||||||
}
|
}
|
||||||
interface RawProject {
|
interface RawProject {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -676,14 +679,24 @@ function deriveSupplierTopics(
|
|||||||
return rawSuppliers.map((s) => {
|
return rawSuppliers.map((s) => {
|
||||||
const t = topics.get(s.id);
|
const t = topics.get(s.id);
|
||||||
const c = cats.get(s.id);
|
const c = cats.get(s.id);
|
||||||
// اگر از quotes topic/category پیدا نشد، registry را چک کن
|
const derivedTopic = t && t.size ? [...t][0] : "";
|
||||||
if (!t || t.size === 0) {
|
const derivedCats = c ? [...c].sort((a, b) => a.localeCompare(b, "fa")) : [];
|
||||||
|
// اگر از quotes چیزی پیدا نشد، registry را چک کن
|
||||||
|
if (!derivedTopic && !derivedCats.length) {
|
||||||
const reg = supplierTopicRegistry.get(s.id);
|
const reg = supplierTopicRegistry.get(s.id);
|
||||||
if (reg) {
|
if (reg) {
|
||||||
return adaptSupplier(s, reg.topic, reg.categories);
|
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] : [],
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user