fix: normalize legacy robot names
This commit is contained in:
@@ -115,27 +115,29 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
|
|||||||
const rawKeys = Object.keys(row.binaryOutput);
|
const rawKeys = Object.keys(row.binaryOutput);
|
||||||
|
|
||||||
const isLegacyPattern = rawKeys.every(key => /^item-\d+-\d+$/.test(key));
|
const isLegacyPattern = rawKeys.every(key => /^item-\d+-\d+$/.test(key));
|
||||||
|
|
||||||
|
let normalizedScreenshotKeys: string[];
|
||||||
|
|
||||||
if (isLegacyPattern) {
|
if (isLegacyPattern) {
|
||||||
const renamedKeys = rawKeys.map((_, index) => `Screenshot ${index + 1}`);
|
// Legacy unnamed screenshots → Screenshot 1, Screenshot 2...
|
||||||
const keyMap: Record<string, string> = {};
|
normalizedScreenshotKeys = rawKeys.map((_, index) => `Screenshot ${index + 1}`);
|
||||||
|
|
||||||
renamedKeys.forEach((displayName, index) => {
|
|
||||||
keyMap[displayName] = rawKeys[index];
|
|
||||||
});
|
|
||||||
|
|
||||||
setScreenshotKeys(renamedKeys);
|
|
||||||
setScreenshotKeyMap(keyMap);
|
|
||||||
} else {
|
} else {
|
||||||
const keyMap: Record<string, string> = {};
|
// Same rule as captured lists: if name missing or generic, auto-label
|
||||||
rawKeys.forEach(key => {
|
normalizedScreenshotKeys = rawKeys.map((key, index) => {
|
||||||
keyMap[key] = key;
|
if (!key || key.toLowerCase().includes("screenshot")) {
|
||||||
|
return `Screenshot ${index + 1}`;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
});
|
});
|
||||||
|
|
||||||
setScreenshotKeys(rawKeys);
|
|
||||||
setScreenshotKeyMap(keyMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const keyMap: Record<string, string> = {};
|
||||||
|
normalizedScreenshotKeys.forEach((displayName, index) => {
|
||||||
|
keyMap[displayName] = rawKeys[index];
|
||||||
|
});
|
||||||
|
|
||||||
|
setScreenshotKeys(normalizedScreenshotKeys);
|
||||||
|
setScreenshotKeyMap(keyMap);
|
||||||
setCurrentScreenshotIndex(0);
|
setCurrentScreenshotIndex(0);
|
||||||
} else {
|
} else {
|
||||||
setScreenshotKeys([]);
|
setScreenshotKeys([]);
|
||||||
@@ -202,7 +204,14 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
|
|||||||
|
|
||||||
const processSchemaData = (schemaOutput: any) => {
|
const processSchemaData = (schemaOutput: any) => {
|
||||||
const keys = Object.keys(schemaOutput);
|
const keys = Object.keys(schemaOutput);
|
||||||
setSchemaKeys(keys);
|
const normalizedKeys = keys.map((key, index) => {
|
||||||
|
if (!key || key.toLowerCase().includes("scrapeschema")) {
|
||||||
|
return keys.length === 1 ? "Texts" : `Text ${index + 1}`;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
});
|
||||||
|
|
||||||
|
setSchemaKeys(normalizedKeys);
|
||||||
|
|
||||||
const dataByKey: Record<string, any[]> = {};
|
const dataByKey: Record<string, any[]> = {};
|
||||||
const columnsByKey: Record<string, string[]> = {};
|
const columnsByKey: Record<string, string[]> = {};
|
||||||
@@ -248,8 +257,17 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setSchemaDataByKey(dataByKey);
|
const remappedDataByKey: Record<string, any[]> = {};
|
||||||
setSchemaColumnsByKey(columnsByKey);
|
const remappedColumnsByKey: Record<string, string[]> = {};
|
||||||
|
|
||||||
|
normalizedKeys.forEach((newKey, idx) => {
|
||||||
|
const oldKey = keys[idx];
|
||||||
|
remappedDataByKey[newKey] = dataByKey[oldKey];
|
||||||
|
remappedColumnsByKey[newKey] = columnsByKey[oldKey];
|
||||||
|
});
|
||||||
|
|
||||||
|
setSchemaDataByKey(remappedDataByKey);
|
||||||
|
setSchemaColumnsByKey(remappedColumnsByKey);
|
||||||
|
|
||||||
if (allData.length > 0) {
|
if (allData.length > 0) {
|
||||||
const allColumns = new Set<string>();
|
const allColumns = new Set<string>();
|
||||||
@@ -290,7 +308,14 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
|
|||||||
|
|
||||||
setListData(tablesList);
|
setListData(tablesList);
|
||||||
setListColumns(columnsList);
|
setListColumns(columnsList);
|
||||||
setListKeys(keys);
|
const normalizedListKeys = keys.map((key, index) => {
|
||||||
|
if (!key || key.toLowerCase().includes("scrapelist")) {
|
||||||
|
return `List ${index + 1}`;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
});
|
||||||
|
|
||||||
|
setListKeys(normalizedListKeys);
|
||||||
setCurrentListIndex(0);
|
setCurrentListIndex(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user