Skip to content

Commit b9ab9bd

Browse files
committed
fix: add null checks legacy data
1 parent 5367111 commit b9ab9bd

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/components/run/RunContent.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
8787
const hasOldFormat = !row.serializableOutput.scrapeSchema && !row.serializableOutput.scrapeList && Object.keys(row.serializableOutput).length > 0;
8888

8989
if (hasLegacySchema || hasLegacyList || hasOldFormat) {
90-
setIsLegacyData(true);
9190
processLegacyData(row.serializableOutput);
91+
setIsLegacyData(false);
9292
return;
9393
}
9494

@@ -154,11 +154,12 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
154154
const data = legacyOutput[key];
155155

156156
if (Array.isArray(data)) {
157-
const isNestedArray = data.length > 0 && Array.isArray(data[0]);
157+
const firstNonNullElement = data.find(item => item !== null && item !== undefined);
158+
const isNestedArray = firstNonNullElement && Array.isArray(firstNonNullElement);
158159

159160
if (isNestedArray) {
160161
data.forEach((subArray, index) => {
161-
if (Array.isArray(subArray) && subArray.length > 0) {
162+
if (subArray !== null && subArray !== undefined && Array.isArray(subArray) && subArray.length > 0) {
162163
const filteredData = subArray.filter(row =>
163164
row && typeof row === 'object' && Object.values(row).some(value => value !== undefined && value !== "")
164165
);
@@ -171,7 +172,7 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
171172
});
172173
} else {
173174
const filteredData = data.filter(row =>
174-
row && typeof row === 'object' && Object.values(row).some(value => value !== undefined && value !== "")
175+
row && typeof row === 'object' && !Array.isArray(row) && Object.values(row).some(value => value !== undefined && value !== "")
175176
);
176177

177178
if (filteredData.length > 0) {
@@ -208,7 +209,7 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
208209

209210
if (Array.isArray(schemaOutput)) {
210211
const filteredData = schemaOutput.filter(row =>
211-
row && Object.values(row).some(value => value !== undefined && value !== "")
212+
row && typeof row === 'object' && Object.values(row).some(value => value !== undefined && value !== "")
212213
);
213214

214215
if (filteredData.length > 0) {
@@ -231,7 +232,7 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
231232
const data = schemaOutput[key];
232233
if (Array.isArray(data)) {
233234
const filteredData = data.filter(row =>
234-
Object.values(row).some(value => value !== undefined && value !== "")
235+
row && typeof row === 'object' && Object.values(row).some(value => value !== undefined && value !== "")
235236
);
236237

237238
dataByKey[key] = filteredData;
@@ -272,7 +273,7 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
272273
const tableData = scrapeListData[key];
273274
if (Array.isArray(tableData) && tableData.length > 0) {
274275
const filteredData = tableData.filter(row =>
275-
Object.values(row).some(value => value !== undefined && value !== "")
276+
row && typeof row === 'object' && Object.values(row).some(value => value !== undefined && value !== "")
276277
);
277278
if (filteredData.length > 0) {
278279
tablesList.push(filteredData);

0 commit comments

Comments
 (0)