@@ -73,6 +73,13 @@ interface GroupedCredentials {
7373 others : string [ ] ;
7474}
7575
76+ interface ScrapeListLimit {
77+ pairIndex : number ;
78+ actionIndex : number ;
79+ argIndex : number ;
80+ currentLimit : number ;
81+ }
82+
7683export const RobotEditModal = ( { isOpen, handleStart, handleClose, initialSettings } : RobotSettingsProps ) => {
7784 const { t } = useTranslation ( ) ;
7885 const [ credentials , setCredentials ] = useState < Credentials > ( { } ) ;
@@ -85,6 +92,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
8592 others : [ ]
8693 } ) ;
8794 const [ showPasswords , setShowPasswords ] = useState < CredentialVisibility > ( { } ) ;
95+ const [ scrapeListLimits , setScrapeListLimits ] = useState < ScrapeListLimit [ ] > ( [ ] ) ;
8896
8997 const isEmailPattern = ( value : string ) : boolean => {
9098 return value . includes ( '@' ) ;
@@ -120,9 +128,36 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
120128 const extractedCredentials = extractInitialCredentials ( robot . recording . workflow ) ;
121129 setCredentials ( extractedCredentials ) ;
122130 setCredentialGroups ( groupCredentialsByType ( extractedCredentials ) ) ;
131+
132+ findScrapeListLimits ( robot . recording . workflow ) ;
123133 }
124134 } , [ robot ] ) ;
125135
136+ const findScrapeListLimits = ( workflow : WhereWhatPair [ ] ) => {
137+ const limits : ScrapeListLimit [ ] = [ ] ;
138+
139+ workflow . forEach ( ( pair , pairIndex ) => {
140+ if ( ! pair . what ) return ;
141+
142+ pair . what . forEach ( ( action , actionIndex ) => {
143+ if ( action . action === 'scrapeList' && action . args && action . args . length > 0 ) {
144+ // Check if first argument has a limit property
145+ const arg = action . args [ 0 ] ;
146+ if ( arg && typeof arg === 'object' && 'limit' in arg ) {
147+ limits . push ( {
148+ pairIndex,
149+ actionIndex,
150+ argIndex : 0 ,
151+ currentLimit : arg . limit
152+ } ) ;
153+ }
154+ }
155+ } ) ;
156+ } ) ;
157+
158+ setScrapeListLimits ( limits ) ;
159+ } ;
160+
126161 function extractInitialCredentials ( workflow : any [ ] ) : Credentials {
127162 const credentials : Credentials = { } ;
128163
@@ -285,20 +320,30 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
285320 } ) ) ;
286321 } ;
287322
288- const handleLimitChange = ( newLimit : number ) => {
323+ const handleLimitChange = ( pairIndex : number , actionIndex : number , argIndex : number , newLimit : number ) => {
289324 setRobot ( ( prev ) => {
290325 if ( ! prev ) return prev ;
291326
292327 const updatedWorkflow = [ ...prev . recording . workflow ] ;
293328 if (
294- updatedWorkflow . length > 0 &&
295- updatedWorkflow [ 0 ] ?. what &&
296- updatedWorkflow [ 0 ] . what . length > 0 &&
297- updatedWorkflow [ 0 ] . what [ 0 ] . args &&
298- updatedWorkflow [ 0 ] . what [ 0 ] . args . length > 0 &&
299- updatedWorkflow [ 0 ] . what [ 0 ] . args [ 0 ]
329+ updatedWorkflow . length > pairIndex &&
330+ updatedWorkflow [ pairIndex ] ?. what &&
331+ updatedWorkflow [ pairIndex ] . what . length > actionIndex &&
332+ updatedWorkflow [ pairIndex ] . what [ actionIndex ] . args &&
333+ updatedWorkflow [ pairIndex ] . what [ actionIndex ] . args . length > argIndex
300334 ) {
301- updatedWorkflow [ 0 ] . what [ 0 ] . args [ 0 ] . limit = newLimit ;
335+ updatedWorkflow [ pairIndex ] . what [ actionIndex ] . args [ argIndex ] . limit = newLimit ;
336+
337+ setScrapeListLimits ( prev => {
338+ return prev . map ( item => {
339+ if ( item . pairIndex === pairIndex &&
340+ item . actionIndex === actionIndex &&
341+ item . argIndex === argIndex ) {
342+ return { ...item , currentLimit : newLimit } ;
343+ }
344+ return item ;
345+ } ) ;
346+ } ) ;
302347 }
303348
304349 return { ...prev , recording : { ...prev . recording , workflow : updatedWorkflow } } ;
@@ -358,9 +403,6 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
358403
359404 return (
360405 < >
361- { /* <Typography variant="h6" style={{ marginBottom: '20px' }}>
362- {headerText}
363- </Typography> */ }
364406 { selectors . map ( ( selector , index ) => {
365407 const isVisible = showPasswords [ selector ] ;
366408
@@ -393,6 +435,40 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
393435 ) ;
394436 } ;
395437
438+ const renderScrapeListLimitFields = ( ) => {
439+ if ( scrapeListLimits . length === 0 ) return null ;
440+
441+ return (
442+ < >
443+ < Typography variant = "body1" style = { { marginBottom : '20px' } } >
444+ { t ( 'List Limits' ) }
445+ </ Typography >
446+
447+ { scrapeListLimits . map ( ( limitInfo , index ) => (
448+ < TextField
449+ key = { `limit-${ limitInfo . pairIndex } -${ limitInfo . actionIndex } ` }
450+ label = { `${ t ( 'List Limit' ) } ${ index + 1 } ` }
451+ type = "number"
452+ value = { limitInfo . currentLimit || '' }
453+ onChange = { ( e ) => {
454+ const value = parseInt ( e . target . value , 10 ) ;
455+ if ( value >= 1 ) {
456+ handleLimitChange (
457+ limitInfo . pairIndex ,
458+ limitInfo . actionIndex ,
459+ limitInfo . argIndex ,
460+ value
461+ ) ;
462+ }
463+ } }
464+ inputProps = { { min : 1 } }
465+ style = { { marginBottom : '20px' } }
466+ />
467+ ) ) }
468+ </ >
469+ ) ;
470+ } ;
471+
396472 const handleSave = async ( ) => {
397473 if ( ! robot ) return ;
398474
@@ -412,7 +488,12 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
412488
413489 const payload = {
414490 name : robot . recording_meta . name ,
415- limit : robot . recording . workflow [ 0 ] ?. what [ 0 ] ?. args ?. [ 0 ] ?. limit ,
491+ limits : scrapeListLimits . map ( limit => ( {
492+ pairIndex : limit . pairIndex ,
493+ actionIndex : limit . actionIndex ,
494+ argIndex : limit . argIndex ,
495+ limit : limit . currentLimit
496+ } ) ) ,
416497 credentials : credentialsForPayload ,
417498 targetUrl : targetUrl ,
418499 } ;
@@ -468,21 +549,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
468549 style = { { marginBottom : '20px' } }
469550 />
470551
471- { robot . recording . workflow ?. [ 0 ] ?. what ?. [ 0 ] ?. args ?. [ 0 ] ?. limit !== undefined && (
472- < TextField
473- label = { t ( 'robot_edit.robot_limit' ) }
474- type = "number"
475- value = { robot . recording . workflow [ 0 ] . what [ 0 ] . args [ 0 ] . limit || '' }
476- onChange = { ( e ) => {
477- const value = parseInt ( e . target . value , 10 ) ;
478- if ( value >= 1 ) {
479- handleLimitChange ( value ) ;
480- }
481- } }
482- inputProps = { { min : 1 } }
483- style = { { marginBottom : '20px' } }
484- />
485- ) }
552+ { renderScrapeListLimitFields ( ) }
486553
487554 { ( Object . keys ( credentials ) . length > 0 ) && (
488555 < >
0 commit comments