Skip to content

Commit 56aeb5e

Browse files
authored
Merge pull request #859 from getmaxun/edit-page
fix: add default names for captured action data
2 parents 9cf8537 + 9066ff6 commit 56aeb5e

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
@@ -552,17 +552,50 @@ export const RobotEditPage = ({ handleStart }: RobotSettingsProps) => {
552552
const screenshotInputs: JSX.Element[] = [];
553553
const listInputs: JSX.Element[] = [];
554554

555+
let textCount = 0;
556+
let screenshotCount = 0;
557+
let listCount = 0;
558+
555559
robot.recording.workflow.forEach((pair, pairIndex) => {
556560
if (!pair.what) return;
557561

558562
pair.what.forEach((action, actionIndex) => {
559563
if (!editableActions.has(String(action.action))) return;
560564

561-
const currentName =
565+
let currentName =
562566
action.name ||
563567
(action.args && action.args[0] && typeof action.args[0] === 'object' && action.args[0].__name) ||
564568
'';
565569

570+
if (!currentName) {
571+
switch (action.action) {
572+
case 'scrapeSchema':
573+
textCount++;
574+
currentName = `Text ${textCount}`;
575+
break;
576+
case 'screenshot':
577+
screenshotCount++;
578+
currentName = `Screenshot ${screenshotCount}`;
579+
break;
580+
case 'scrapeList':
581+
listCount++;
582+
currentName = `List ${listCount}`;
583+
break;
584+
}
585+
} else {
586+
switch (action.action) {
587+
case 'scrapeSchema':
588+
textCount++;
589+
break;
590+
case 'screenshot':
591+
screenshotCount++;
592+
break;
593+
case 'scrapeList':
594+
listCount++;
595+
break;
596+
}
597+
}
598+
566599
const textField = (
567600
<TextField
568601
key={`action-name-${pairIndex}-${actionIndex}`}
@@ -588,6 +621,34 @@ export const RobotEditPage = ({ handleStart }: RobotSettingsProps) => {
588621
});
589622
});
590623

624+
if (textInputs.length === 1 && textCount === 1) {
625+
robot.recording.workflow.forEach((pair, pairIndex) => {
626+
if (!pair.what) return;
627+
628+
pair.what.forEach((action, actionIndex) => {
629+
if (action.action === 'scrapeSchema') {
630+
const existingName =
631+
action.name ||
632+
(action.args && action.args[0] && typeof action.args[0] === 'object' && action.args[0].__name) ||
633+
'';
634+
635+
const currentName = !existingName ? 'Texts' : existingName;
636+
637+
textInputs[0] = (
638+
<TextField
639+
key={`action-name-${pairIndex}-${actionIndex}`}
640+
type="text"
641+
value={currentName}
642+
onChange={(e) => handleActionNameChange(pairIndex, actionIndex, e.target.value)}
643+
style={{ marginBottom: '12px' }}
644+
fullWidth
645+
/>
646+
);
647+
}
648+
});
649+
});
650+
}
651+
591652
const hasAnyInputs = textInputs.length > 0 || screenshotInputs.length > 0 || listInputs.length > 0;
592653
if (!hasAnyInputs) return null;
593654

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)