feat(m02-df): 입력 판 조건 찾기 단위 · 재료 요소 검사 보정
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ACSGaHdLgnkEkoA4LDtMU
This commit is contained in:
@@ -227,7 +227,11 @@ export function checkMaterial(el: CfElementRef, others: CfElementRef[]): string
|
||||
if (!el.name) return "자리 이름을 적어 주세요";
|
||||
if (others.some((o) => o.name === el.name)) return "같은 이름의 알약이 이미 있음";
|
||||
if (el.mode === "rule" && !el.rule?.from.name) return "규칙에 쓸 변수 알약을 골라 주세요";
|
||||
if (el.mode !== "fixed" && !Object.keys(el.scope ?? {}).length)
|
||||
if (
|
||||
el.mode !== "fixed" &&
|
||||
!(el.mode === "choice" && el.default) &&
|
||||
!Object.keys(el.scope ?? {}).length
|
||||
)
|
||||
return "범위(구분 · 상세구분 · 찾는 말) 하나는 정해 주세요";
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ function itemList(
|
||||
export async function previewOf(
|
||||
el1: CfElementRef,
|
||||
lg: CfLogic,
|
||||
): Promise<{ found: number; names: string[]; cheapest: MatItem | null }> {
|
||||
): Promise<{ found: number; names: string[]; cheapest: MatItem | null; unit: string }> {
|
||||
const scope = el1.scope ?? {};
|
||||
const word = scope.찾는말 ?? "";
|
||||
if (el1.mode === "rule" && el1.rule) {
|
||||
@@ -300,7 +300,7 @@ export async function previewOf(
|
||||
);
|
||||
const value = pill?.example;
|
||||
if (value === null || value === undefined || value === "")
|
||||
return { found: 0, names: [], cheapest: null };
|
||||
return { found: 0, names: [], cheapest: null, unit: "" };
|
||||
const r = await searchMaterials({
|
||||
q: `${word} ${value}`.trim(),
|
||||
sub: scope.구분,
|
||||
@@ -313,6 +313,7 @@ export async function previewOf(
|
||||
found: hit.length,
|
||||
names: hit.slice(0, 3).map((i) => `${i.name} ${i.spec}`.trim()),
|
||||
cheapest: cheapestOf(hit),
|
||||
unit: commonUnit(hit),
|
||||
};
|
||||
}
|
||||
const r = await searchMaterials({
|
||||
@@ -326,9 +327,14 @@ export async function previewOf(
|
||||
found: r.total,
|
||||
names: r.items.slice(0, 3).map((i) => `${i.name} ${i.spec}`.trim()),
|
||||
cheapest: cheapestOf(r.items),
|
||||
unit: commonUnit(r.items),
|
||||
};
|
||||
}
|
||||
|
||||
/** 잡힌 품목 단위가 모두 같으면 그 단위 · 아니면 빈 글 */
|
||||
const commonUnit = (items: MatItem[]): string =>
|
||||
items.length && items.every((i) => i.unit === items[0].unit) ? items[0].unit : "";
|
||||
|
||||
const cheapestOf = (items: MatItem[]): MatItem | null =>
|
||||
items
|
||||
.filter((i) => i.price !== null)
|
||||
@@ -541,7 +547,11 @@ export function renderMaterial(
|
||||
const why = checkMaterial(cand, els);
|
||||
name.setError(why ?? undefined);
|
||||
if (why) return void showToast(why, "error");
|
||||
on.change(addEl(lg, cand));
|
||||
// 잡히는 재료의 단위가 하나로 같으면 그 단위를 알약 단위로
|
||||
void previewOf(cand, lg).then(
|
||||
(p) => on.change(addEl(lg, p.unit ? { ...cand, unit: p.unit } : cand)),
|
||||
() => on.change(addEl(lg, cand)),
|
||||
);
|
||||
},
|
||||
});
|
||||
const clear = createButton({
|
||||
|
||||
Reference in New Issue
Block a user