fix: PopFieldComponent preview fetch에 json_extract_lookup 처리 추가
컴포넌트 마운트 시 cart_items.row_data에서 코드값을 추출한 후 참조 테이블에서 표시값을 조회하는 json_extract_lookup을 preview fetch에도 추가한다.
This commit is contained in:
parent
dd3b226917
commit
49da393f17
|
|
@ -362,6 +362,7 @@ export function PopFieldComponent({
|
|||
const row = res.data[0] as Record<string, unknown>;
|
||||
|
||||
const extracted: Record<string, unknown> = {};
|
||||
const previewLookupQueue: { fieldId: string; codeValue: string; table: string; codeCol: string; displayCol: string }[] = [];
|
||||
for (const mapping of cfg.readSource!.fieldMappings || []) {
|
||||
if (mapping.valueSource === "json_extract" && mapping.columnName && mapping.jsonKey) {
|
||||
const rawVal = row[mapping.columnName];
|
||||
|
|
@ -372,11 +373,48 @@ export function PopFieldComponent({
|
|||
parsed = rawVal as Record<string, unknown>;
|
||||
}
|
||||
extracted[mapping.fieldId] = parsed[mapping.jsonKey] ?? "";
|
||||
} else if (mapping.valueSource === "json_extract_lookup" && mapping.columnName && mapping.jsonKey && mapping.lookupTable && mapping.lookupCodeColumn && mapping.lookupDisplayColumn) {
|
||||
const rawVal = row[mapping.columnName];
|
||||
let parsed: Record<string, unknown> = {};
|
||||
if (typeof rawVal === "string") {
|
||||
try { parsed = JSON.parse(rawVal); } catch { /* ignore */ }
|
||||
} else if (typeof rawVal === "object" && rawVal !== null) {
|
||||
parsed = rawVal as Record<string, unknown>;
|
||||
}
|
||||
const codeValue = String(parsed[mapping.jsonKey] ?? "");
|
||||
if (codeValue) {
|
||||
previewLookupQueue.push({ fieldId: mapping.fieldId, codeValue, table: mapping.lookupTable, codeCol: mapping.lookupCodeColumn, displayCol: mapping.lookupDisplayColumn });
|
||||
} else {
|
||||
extracted[mapping.fieldId] = "";
|
||||
}
|
||||
} else if (mapping.valueSource === "db_column" && mapping.columnName) {
|
||||
extracted[mapping.fieldId] = row[mapping.columnName] ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
// json_extract_lookup: 코드 값으로 참조 테이블 조회하여 표시명 획득 (미리보기)
|
||||
if (previewLookupQueue.length > 0) {
|
||||
const previewLookupResults = await Promise.allSettled(
|
||||
previewLookupQueue.map(async (lq) => {
|
||||
const lookupRes = await dataApi.getTableData(lq.table, {
|
||||
page: 1,
|
||||
size: 1,
|
||||
filters: { [lq.codeCol]: lq.codeValue },
|
||||
});
|
||||
if (Array.isArray(lookupRes.data) && lookupRes.data.length > 0) {
|
||||
const lookupRow = lookupRes.data[0] as Record<string, unknown>;
|
||||
return { fieldId: lq.fieldId, value: lookupRow[lq.displayCol] ?? lq.codeValue };
|
||||
}
|
||||
return { fieldId: lq.fieldId, value: lq.codeValue };
|
||||
}),
|
||||
);
|
||||
for (const result of previewLookupResults) {
|
||||
if (result.status === "fulfilled") {
|
||||
extracted[result.value.fieldId] = result.value.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const allFieldsInConfig = cfg.sections.flatMap((s) => s.fields || []);
|
||||
const valuesUpdate: Record<string, unknown> = {};
|
||||
for (const [fieldId, val] of Object.entries(extracted)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue