fix: debug order composition parsing and add visible error info
This commit is contained in:
parent
458414636d
commit
874e9b3885
|
|
@ -39,23 +39,39 @@ const renderList = (values) => {
|
||||||
const renderValue = (value) => value || "Нет данных";
|
const renderValue = (value) => value || "Нет данных";
|
||||||
|
|
||||||
const parseOrderList = (order) => {
|
const parseOrderList = (order) => {
|
||||||
if (!order) return [];
|
if (!order) return { items: [], debug: "order is null" };
|
||||||
|
|
||||||
// Try source_orders first (from 1C exchange data)
|
// Try source_orders first (from 1C exchange data)
|
||||||
if (order.sourceOrders) {
|
if (order.sourceOrders) {
|
||||||
|
let parsed = order.sourceOrders;
|
||||||
|
let debugInfo = "sourceOrders exists, type: " + typeof parsed;
|
||||||
|
// If it's a string, try to parse JSON
|
||||||
|
if (typeof parsed === 'string') {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(order.sourceOrders);
|
parsed = JSON.parse(parsed);
|
||||||
if (Array.isArray(parsed) && parsed.length > 0 && parsed[0].orderList) {
|
debugInfo += ", parsed JSON";
|
||||||
return parsed[0].orderList;
|
} catch (e) {
|
||||||
|
debugInfo += ", JSON parse failed: " + e.message;
|
||||||
|
return { items: [], debug: debugInfo };
|
||||||
}
|
}
|
||||||
if (Array.isArray(parsed)) {
|
|
||||||
return parsed;
|
|
||||||
}
|
}
|
||||||
} catch {
|
// Now parsed should be an array
|
||||||
/* ignore */
|
if (Array.isArray(parsed) && parsed.length > 0) {
|
||||||
|
debugInfo += ", is array, length: " + parsed.length;
|
||||||
|
debugInfo += ", first keys: " + Object.keys(parsed[0]).join(", ");
|
||||||
|
// If first item has orderList, return it
|
||||||
|
if (parsed[0].orderList && Array.isArray(parsed[0].orderList)) {
|
||||||
|
return { items: parsed[0].orderList, debug: debugInfo + ", returning orderList" };
|
||||||
}
|
}
|
||||||
|
debugInfo += ", no orderList found";
|
||||||
|
return { items: parsed, debug: debugInfo };
|
||||||
|
} else {
|
||||||
|
debugInfo += ", not array or empty";
|
||||||
|
}
|
||||||
|
return { items: [], debug: debugInfo };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { items: [], debug: "sourceOrders is empty" };
|
||||||
};
|
};
|
||||||
|
|
||||||
const getErrorMessage = (error, fallbackMessage) => {
|
const getErrorMessage = (error, fallbackMessage) => {
|
||||||
|
|
@ -678,9 +694,15 @@ export const OrderDetailPanel = ({
|
||||||
<strong>Состав заказа</strong>
|
<strong>Состав заказа</strong>
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{(() => {
|
{(() => {
|
||||||
const orders = parseOrderList(order);
|
const result = parseOrderList(order);
|
||||||
|
const orders = result.items;
|
||||||
if (!orders.length) {
|
if (!orders.length) {
|
||||||
return <p className="text-sm text-[var(--color-text-muted)]">Нет данных</p>;
|
return (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-[var(--color-text-muted)]">Нет данных</p>
|
||||||
|
<p className="text-xs text-[var(--color-text-muted)] mt-1">{result.debug}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return orders.map((orderItem, idx) => (
|
return orders.map((orderItem, idx) => (
|
||||||
<div key={idx} className="rounded-[20px] border border-[var(--color-border)] bg-[var(--color-surface-strong)] p-4">
|
<div key={idx} className="rounded-[20px] border border-[var(--color-border)] bg-[var(--color-surface-strong)] p-4">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue