fix: Correct data extraction logic in JavaScript for propertyName format

Problem:
- When data comes as { propertyName: {...}, ... }, dataCandidate was set to propertyName object
- normalizeData expects { propertyName: {...} } format, not just propertyName
- Data normalization failed because structure didn't match

Solution:
- Changed logic to use entire injected object when propertyName exists
- This ensures normalizeData receives correct structure
- Data should now normalize correctly and populate form fields

Files:
- frontend/src/components/form/generateConfirmationFormHTML.ts: Fixed data extraction logic
This commit is contained in:
AI Assistant
2025-11-24 16:17:29 +03:00
parent fc3ecdb63f
commit d34712f666

View File

@@ -762,20 +762,23 @@ export function generateConfirmationFormHTML(data: any): string {
// Достаём объект кейса из «типичных» мест
var dataCandidate = null;
if (!dataCandidate && injected.propertyName !== undefined) {
// Если propertyName - это объект (как в вашем случае), берем его напрямую
if (typeof injected.propertyName === 'object' && injected.propertyName !== null) {
dataCandidate = injected.propertyName;
} else if (typeof injected.propertyName === 'string') {
dataCandidate = tryParseJSON(injected.propertyName);
}
// Если есть propertyName в корне, используем весь injected объект (он уже в правильном формате)
if (injected.propertyName !== undefined) {
dataCandidate = injected; // Используем весь объект, так как normalizeData ожидает { propertyName: {...} }
} else if (injected.value !== undefined) {
dataCandidate = tryParseJSON(injected.value) || injected;
} else if (injected.user || injected.project || injected.offenders || injected.meta) {
dataCandidate = injected;
} else if (injected.data) {
dataCandidate = injected.data;
} else if (injected.output) {
dataCandidate = tryParseJSON(injected.output) || injected.output;
} else if (injected.case) {
dataCandidate = { case: injected.case };
} else {
dataCandidate = injected;
}
if (!dataCandidate && injected.value !== undefined) dataCandidate = tryParseJSON(injected.value);
if (!dataCandidate && (injected.user || injected.project || injected.offenders || injected.meta)) dataCandidate = injected;
if (!dataCandidate && injected.data) dataCandidate = injected.data;
if (!dataCandidate && injected.output) dataCandidate = tryParseJSON(injected.output) || injected.output;
if (!dataCandidate && injected.case) dataCandidate = { case: injected.case };
dataCandidate = dataCandidate || injected;
console.log('dataCandidate:', dataCandidate);
console.log('Type of dataCandidate:', typeof dataCandidate);