@@ -77,7 +77,8 @@ import { convertToBasePageIdSelector } from "selectors/pageListSelectors";
77
77
import type { ApplicationPayload } from "entities/Application" ;
78
78
import { klonaLiteWithTelemetry } from "utils/helpers" ;
79
79
80
- function * syncApiParamsSaga (
80
+ // Export for testing
81
+ export function * syncApiParamsSaga (
81
82
actionPayload : ReduxActionWithMeta < string , { field : string } > ,
82
83
actionId : string ,
83
84
) {
@@ -110,21 +111,108 @@ function* syncApiParamsSaga(
110
111
const path = values . actionConfiguration . path || "" ;
111
112
const matchGroups = path . match ( queryParamsRegEx ) || [ ] ;
112
113
const currentPath = matchGroups [ 1 ] || "" ;
113
- const paramsString = values . actionConfiguration . queryParameters
114
- . filter ( ( p : Property ) => p . key )
114
+
115
+ // Get all query parameters that have a key
116
+ const validParams = values . actionConfiguration . queryParameters . filter (
117
+ ( p : Property ) => p . key ,
118
+ ) ;
119
+
120
+ // Create the query parameters string representation
121
+ const paramsString = validParams
115
122
. map (
116
123
( p : Property , i : number ) => `${ i === 0 ? "?" : "&" } ${ p . key } =${ p . value } ` ,
117
124
)
118
125
. join ( "" ) ;
119
126
120
- yield put (
121
- autofill (
122
- API_EDITOR_FORM_NAME ,
123
- "actionConfiguration.path" ,
124
- `${ currentPath } ${ paramsString } ` ,
125
- ) ,
126
- ) ;
127
+ // Only update if we have a currentPath to avoid removing the whole URL
128
+ if ( currentPath ) {
129
+ yield put (
130
+ autofill (
131
+ API_EDITOR_FORM_NAME ,
132
+ "actionConfiguration.path" ,
133
+ `${ currentPath } ${ paramsString } ` ,
134
+ ) ,
135
+ ) ;
136
+
137
+ // Also update the action property to ensure consistency
138
+ yield put (
139
+ setActionProperty ( {
140
+ actionId : actionId ,
141
+ propertyName : "actionConfiguration.path" ,
142
+ value : `${ currentPath } ${ paramsString } ` ,
143
+ } ) ,
144
+ ) ;
145
+ }
146
+ }
147
+ }
148
+
149
+ // Export for testing
150
+ export function * changeApiSaga (
151
+ actionPayload : ReduxAction < {
152
+ id : string ;
153
+ isSaas : boolean ;
154
+ action ?: Action ;
155
+ } > ,
156
+ ) {
157
+ const { id, isSaas } = actionPayload . payload ;
158
+ let { action } = actionPayload . payload ;
159
+
160
+ if ( ! action ) action = yield select ( getAction , id ) ;
161
+
162
+ if ( ! action ) return ;
163
+
164
+ if ( isSaas ) {
165
+ yield put ( initialize ( QUERY_EDITOR_FORM_NAME , action ) ) ;
166
+ } else {
167
+ yield put ( initialize ( API_EDITOR_FORM_NAME , action ) ) ;
168
+
169
+ if (
170
+ action . actionConfiguration &&
171
+ action . actionConfiguration . queryParameters ?. length
172
+ ) {
173
+ // Sync the api params by mocking a change action
174
+ yield call (
175
+ syncApiParamsSaga ,
176
+ {
177
+ type : ReduxFormActionTypes . ARRAY_REMOVE ,
178
+ payload : action . actionConfiguration . queryParameters ,
179
+ meta : {
180
+ field : "actionConfiguration.queryParameters" ,
181
+ } ,
182
+ } ,
183
+ id ,
184
+ ) ;
185
+
186
+ // Force a re-sync to ensure the URL is updated with query parameters
187
+ const { values } = yield select ( getFormData , API_EDITOR_FORM_NAME ) ;
188
+
189
+ if (
190
+ values &&
191
+ values . actionConfiguration &&
192
+ values . actionConfiguration . queryParameters ?. length
193
+ ) {
194
+ yield call (
195
+ syncApiParamsSaga ,
196
+ {
197
+ type : ReduxFormActionTypes . ARRAY_REMOVE ,
198
+ payload : values . actionConfiguration . queryParameters ,
199
+ meta : {
200
+ field : "actionConfiguration.queryParameters" ,
201
+ } ,
202
+ } ,
203
+ id ,
204
+ ) ;
205
+ }
206
+ }
127
207
}
208
+
209
+ //Retrieve form data with synced query params to start tracking change history.
210
+ const { values : actionPostProcess } = yield select (
211
+ getFormData ,
212
+ API_EDITOR_FORM_NAME ,
213
+ ) ;
214
+
215
+ yield put ( updateReplayEntity ( id , actionPostProcess , ENTITY_TYPE . ACTION ) ) ;
128
216
}
129
217
130
218
function * handleUpdateBodyContentType ( contentType : string ) {
@@ -216,53 +304,6 @@ function* handleUpdateBodyContentType(contentType: string) {
216
304
}
217
305
}
218
306
219
- function * changeApiSaga (
220
- actionPayload : ReduxAction < {
221
- id : string ;
222
- isSaas : boolean ;
223
- action ?: Action ;
224
- } > ,
225
- ) {
226
- const { id, isSaas } = actionPayload . payload ;
227
- let { action } = actionPayload . payload ;
228
-
229
- if ( ! action ) action = yield select ( getAction , id ) ;
230
-
231
- if ( ! action ) return ;
232
-
233
- if ( isSaas ) {
234
- yield put ( initialize ( QUERY_EDITOR_FORM_NAME , action ) ) ;
235
- } else {
236
- yield put ( initialize ( API_EDITOR_FORM_NAME , action ) ) ;
237
-
238
- if (
239
- action . actionConfiguration &&
240
- action . actionConfiguration . queryParameters ?. length
241
- ) {
242
- // Sync the api params my mocking a change action
243
- yield call (
244
- syncApiParamsSaga ,
245
- {
246
- type : ReduxFormActionTypes . ARRAY_REMOVE ,
247
- payload : action . actionConfiguration . queryParameters ,
248
- meta : {
249
- field : "actionConfiguration.queryParameters" ,
250
- } ,
251
- } ,
252
- id ,
253
- ) ;
254
- }
255
- }
256
-
257
- //Retrieve form data with synced query params to start tracking change history.
258
- const { values : actionPostProcess } = yield select (
259
- getFormData ,
260
- API_EDITOR_FORM_NAME ,
261
- ) ;
262
-
263
- yield put ( updateReplayEntity ( id , actionPostProcess , ENTITY_TYPE . ACTION ) ) ;
264
- }
265
-
266
307
function * setApiBodyTabHeaderFormat ( apiContentType ?: string ) {
267
308
let displayFormat ;
268
309
0 commit comments