Skip to content

Commit 9066ff6

Browse files
authored
Merge pull request #855 from RohitR311/edit-page
fix: add default names for captured action data
2 parents f5e9cec + f39195a commit 9066ff6

File tree

3 files changed

+76
-13
lines changed

3 files changed

+76
-13
lines changed

src/components/robot/pages/RobotEditPage.tsx

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,17 +543,50 @@ export const RobotEditPage = ({ handleStart }: RobotSettingsProps) => {
543543
const screenshotInputs: JSX.Element[] = [];
544544
const listInputs: JSX.Element[] = [];
545545

546+
let textCount = 0;
547+
let screenshotCount = 0;
548+
let listCount = 0;
549+
546550
robot.recording.workflow.forEach((pair, pairIndex) => {
547551
if (!pair.what) return;
548552

549553
pair.what.forEach((action, actionIndex) => {
550554
if (!editableActions.has(String(action.action))) return;
551555

552-
const currentName =
556+
let currentName =
553557
action.name ||
554558
(action.args && action.args[0] && typeof action.args[0] === 'object' && action.args[0].__name) ||
555559
'';
556560

561+
if (!currentName) {
562+
switch (action.action) {
563+
case 'scrapeSchema':
564+
textCount++;
565+
currentName = `Text ${textCount}`;
566+
break;
567+
case 'screenshot':
568+
screenshotCount++;
569+
currentName = `Screenshot ${screenshotCount}`;
570+
break;
571+
case 'scrapeList':
572+
listCount++;
573+
currentName = `List ${listCount}`;
574+
break;
575+
}
576+
} else {
577+
switch (action.action) {
578+
case 'scrapeSchema':
579+
textCount++;
580+
break;
581+
case 'screenshot':
582+
screenshotCount++;
583+
break;
584+
case 'scrapeList':
585+
listCount++;
586+
break;
587+
}
588+
}
589+
557590
const textField = (
558591
<TextField
559592
key={`action-name-${pairIndex}-${actionIndex}`}
@@ -579,6 +612,34 @@ export const RobotEditPage = ({ handleStart }: RobotSettingsProps) => {
579612
});
580613
});
581614

615+
if (textInputs.length === 1 && textCount === 1) {
616+
robot.recording.workflow.forEach((pair, pairIndex) => {
617+
if (!pair.what) return;
618+
619+
pair.what.forEach((action, actionIndex) => {
620+
if (action.action === 'scrapeSchema') {
621+
const existingName =
622+
action.name ||
623+
(action.args && action.args[0] && typeof action.args[0] === 'object' && action.args[0].__name) ||
624+
'';
625+
626+
const currentName = !existingName ? 'Texts' : existingName;
627+
628+
textInputs[0] = (
629+
<TextField
630+
key={`action-name-${pairIndex}-${actionIndex}`}
631+
type="text"
632+
value={currentName}
633+
onChange={(e) => handleActionNameChange(pairIndex, actionIndex, e.target.value)}
634+
style={{ marginBottom: '12px' }}
635+
fullWidth
636+
/>
637+
);
638+
}
639+
});
640+
});
641+
}
642+
582643
const hasAnyInputs = textInputs.length > 0 || screenshotInputs.length > 0 || listInputs.length > 0;
583644
if (!hasAnyInputs) return null;
584645

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);

src/helpers/clientSelectorGenerator.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,17 @@ class ClientSelectorGenerator {
564564
return true;
565565
}
566566

567-
if (element.children.length > 0) {
568-
return false;
569-
}
570-
571567
const text = (element.textContent || "").trim();
568+
const hasVisibleText = text.length > 0;
572569

573-
if (text.length > 0) {
570+
if (hasVisibleText || element.querySelector("svg")) {
574571
return true;
575572
}
576573

574+
if (element.children.length > 0) {
575+
return false;
576+
}
577+
577578
return false;
578579
}
579580

0 commit comments

Comments
 (0)