feat(units): global-material conversion workspace (no category landing)
- «ضرایب تبدیل» opens directly on the global materials list (no topic/category page); sidebar accordion: unique base materials (brand/spec prefixes stripped) with expandable spec variants; search toolbar filters live. - Detail binds to the selected material: reference unit (editable combobox over global units, changes canonical_unit_id), conversion factors from material_units incl. optional brand scope (restored برند field), add/edit/ delete with live preview (canonical-first wording), unassigned-units warning section, global standard conversions kept. - Self-referencing children excluded (only base+spec variants listed); groups without variants selectable via their representative material. - New lib/units.ts uniqueUnits(): unit dropdowns show each name once, preferring the canonical coded row (kg/piece) over duplicate custom rows with identical Persian names.
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
import { normalize } from "./normalize";
|
||||||
|
|
||||||
|
export interface UnitLike {
|
||||||
|
id: number;
|
||||||
|
code: string;
|
||||||
|
name_fa: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unitDisplayName(u: UnitLike): string {
|
||||||
|
return u.name_fa || u.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
// واحدها با «نام نمایشی» یکتا میشوند: وقتی دو ردیف نام فارسی یکسان دارند
|
||||||
|
// (مثلاً ردیف سفارشی «عدد» و ردیف پایهی piece/عدد)، ردیفی که کد استاندارد
|
||||||
|
// دارد (code ≠ نام فارسی، مثل kg یا piece) ارجح است.
|
||||||
|
export function uniqueUnits(units: UnitLike[]): UnitLike[] {
|
||||||
|
const best = new Map<string, UnitLike>();
|
||||||
|
units.forEach((u) => {
|
||||||
|
const display = unitDisplayName(u);
|
||||||
|
const key = normalize(display);
|
||||||
|
if (!key) return;
|
||||||
|
const cur = best.get(key);
|
||||||
|
const isCanonical = u.code !== display;
|
||||||
|
if (!cur || (isCanonical && cur.code === display)) best.set(key, u);
|
||||||
|
});
|
||||||
|
return [...best.values()].sort((a, b) => unitDisplayName(a).localeCompare(unitDisplayName(b), "fa"));
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user