@@ -62,26 +62,35 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
6262 const addListStep = ( listSelector : string , newFields : { [ key : string ] : TextStep } , listId : number , pagination ?: { type : string ; selector : string } , limit ?: number ) => {
6363 setBrowserSteps ( prevSteps => {
6464 const existingListStepIndex = prevSteps . findIndex ( step => step . type === 'list' && step . id === listId ) ;
65+
6566 if ( existingListStepIndex !== - 1 ) {
6667 const updatedSteps = [ ...prevSteps ] ;
6768 const existingListStep = updatedSteps [ existingListStepIndex ] as ListStep ;
68-
69- const filteredNewFields = Object . entries ( newFields ) . reduce ( ( acc , [ key , value ] ) => {
69+
70+ // Preserve existing labels for fields
71+ const mergedFields = Object . entries ( newFields ) . reduce ( ( acc , [ key , field ] ) => {
7072 if ( ! discardedFields . has ( `${ listId } -${ key } ` ) ) {
71- acc [ key ] = value ;
73+ // If field exists, preserve its label
74+ if ( existingListStep . fields [ key ] ) {
75+ acc [ key ] = {
76+ ...field ,
77+ label : existingListStep . fields [ key ] . label
78+ } ;
79+ } else {
80+ acc [ key ] = field ;
81+ }
7282 }
7383 return acc ;
7484 } , { } as { [ key : string ] : TextStep } ) ;
75-
85+
7686 updatedSteps [ existingListStepIndex ] = {
7787 ...existingListStep ,
78- fields : { ... existingListStep . fields , ... filteredNewFields } ,
79- pagination : pagination ,
80- limit : limit ,
88+ fields : mergedFields ,
89+ pagination : pagination || existingListStep . pagination ,
90+ limit : limit
8191 } ;
8292 return updatedSteps ;
8393 } else {
84- // Create a new ListStep
8594 return [
8695 ...prevSteps ,
8796 { id : listId , type : 'list' , listSelector, fields : newFields , pagination, limit }
0 commit comments