Skip to content

Commit 5367111

Browse files
committed
fix: add default names for captured action data
1 parent f5e9cec commit 5367111

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
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

0 commit comments

Comments
 (0)