@@ -22,6 +22,8 @@ import {
22
22
Network ,
23
23
ReqResRequest ,
24
24
ReqResResponse } from '../../../types.js' ;
25
+ import { request } from 'http' ;
26
+ import { graphql } from 'graphql' ;
25
27
26
28
interface NewRequestCookiesSet {
27
29
cookiesArr : CookieOrHeader [ ] ;
@@ -117,45 +119,73 @@ interface Props {
117
119
}
118
120
119
121
const History = ( props : Props ) => {
122
+ //destructuring props
120
123
const {
121
- newRequestFields,
122
- newRequestsOpenAPI,
123
124
content,
124
- connectContent,
125
125
fieldsReplaced,
126
126
newRequestHeadersSet,
127
127
newRequestCookiesSet,
128
128
newRequestBodySet,
129
129
newRequestStreamsSet,
130
- network,
131
- isSSE,
130
+ newRequestFields
131
+ } = props ;
132
+
133
+ //destructuring nested props within content
134
+ const {
135
+ gRPC,
136
+ graphQL,
137
+ protoPath,
138
+ protocol,
139
+ request,
140
+ response,
141
+ tab,
142
+ timeReceived,
143
+ timeSent,
132
144
url,
145
+ webrtc
146
+ } = content ;
147
+
148
+ //destructuring nested props within content.request
149
+ const {
150
+ body,
151
+ bodyType,
152
+ bodyVariables,
153
+ cookies,
154
+ grpcUrl,
155
+ isSSE,
156
+ headers,
157
+ method,
158
+ messages,
159
+ network,
160
+ rawType,
133
161
restUrl,
162
+ testContent,
163
+ testResults,
164
+ webRtc,
165
+ webRtcUrl,
166
+ ws,
134
167
wsUrl,
135
- gqlUrl,
136
- webrtcUrl,
137
- grpcUrl,
138
- method
139
- } = props ;
140
-
168
+ } = request ;
169
+
141
170
const dispatch = useDispatch ( ) ;
142
171
const setSidebarTab = ( tabName : string ) => dispatch ( setSidebarActiveTab ( tabName ) ) ;
143
172
const setNewRequestSSE = ( bool : boolean ) => dispatch ( newRequestSSESet ( bool ) ) ;
144
173
145
174
const addHistoryToNewRequest = ( ) => {
175
+
146
176
let requestFieldObj = { } ;
147
177
if ( network === 'rest' ) {
148
178
requestFieldObj = {
149
179
...newRequestFields ,
150
- isSSE : isSSE || false ,
151
- method : connectContent . request . method || 'GET' ,
152
- protocol : connectContent . protocol || 'http://' ,
153
- url,
154
- restUrl,
155
- graphQL : connectContent . graphQL || false ,
156
- gRPC : connectContent . gRPC || false ,
157
- webrtc : connectContent . webrtc || false ,
158
- network,
180
+ isSSE : request . isSSE ,
181
+ method : request . method ,
182
+ protocol : content . protocol ,
183
+ url : url ,
184
+ restUrl : request . restUrl ,
185
+ graphQL : content . graphQL ,
186
+ gRPC : content . gRPC ,
187
+ webrtc : content . webrtc ,
188
+ network : request . network ,
159
189
testContent : content . request . testContent ,
160
190
} ;
161
191
}
@@ -170,47 +200,47 @@ const History = (props: Props)=> {
170
200
restUrl,
171
201
graphQL : connectContent . graphQL || false ,
172
202
gRPC : connectContent . gRPC || false ,
173
- webrtc : connectContent . webrtc || false ,
203
+ webrtc : content . webrtc ,
174
204
network,
175
205
} ;
176
206
}
177
207
if ( network === 'ws' ) {
178
208
requestFieldObj = {
179
209
...newRequestFields ,
180
- method : connectContent . request . method || 'GET' ,
181
- protocol : connectContent . protocol || 'http://' ,
182
- url,
210
+ method : request . method || 'GET' ,
211
+ protocol : protocol || 'http://' ,
212
+ url : content . url ,
183
213
wsUrl,
184
- graphQL : connectContent . graphQL || false ,
185
- gRPC : connectContent . gRPC || false ,
186
- webrtc : connectContent . webrtc || false ,
214
+ graphQL : graphql || false ,
215
+ gRPC : gRPC || false ,
216
+ webrtc : webrtc || false ,
187
217
network,
188
218
} ;
189
219
}
190
220
if ( network === 'graphQL' ) {
191
221
requestFieldObj = {
192
222
...newRequestFields ,
193
- method : connectContent . request . method || 'GET' ,
194
- protocol : connectContent . protocol || 'http://' ,
195
- url,
223
+ method : content . request . method || 'GET' ,
224
+ protocol : content . protocol || 'http://' ,
225
+ url : content . url ,
196
226
gqlUrl,
197
- graphQL : connectContent . graphQL || false ,
198
- gRPC : connectContent . gRPC || false ,
199
- webrtc : connectContent . webrtc || false ,
227
+ graphQL : content . graphQL || false ,
228
+ gRPC : content . gRPC || false ,
229
+ webrtc : content . webrtc || false ,
200
230
network,
201
231
} ;
202
232
}
203
233
if ( network === 'webRtc' ) {
204
234
requestFieldObj = {
205
235
...newRequestFields ,
206
- method : connectContent . request . method || 'GET' ,
207
- protocol : connectContent . protocol || 'http://' ,
236
+ method : content . request . method || 'GET' ,
237
+ protocol : content . protocol || 'http://' ,
208
238
url,
209
239
webrtcUrl,
210
240
grpcUrl,
211
- graphQL : connectContent . graphQL || false ,
212
- gRPC : connectContent . gRPC || false ,
213
- webrtc : connectContent . webrtc || false ,
241
+ graphQL : content . graphQL || false ,
242
+ gRPC : content . gRPC || false ,
243
+ webrtc : content . webrtc || false ,
214
244
network,
215
245
} ;
216
246
}
@@ -227,20 +257,20 @@ const History = (props: Props)=> {
227
257
} ;
228
258
}
229
259
let headerDeeperCopy ;
230
- if ( connectContent . request . headers ) {
231
- headerDeeperCopy = JSON . parse ( JSON . stringify ( connectContent . request . headers ) ) ;
260
+ if ( content ? .request ? .headers ) {
261
+ headerDeeperCopy = JSON . parse ( JSON . stringify ( content . request . headers ) ) ;
232
262
headerDeeperCopy . push ( {
233
- id : headers . length + 1 ,
263
+ id : request . headers . length + 1 ,
234
264
active : false ,
235
265
key : '' ,
236
266
value : '' ,
237
267
} ) ;
238
268
}
239
269
let cookieDeeperCopy ;
240
- if ( connectContent . request . cookies && ! / w s / . test ( connectContent . protocol ) ) {
241
- cookieDeeperCopy = JSON . parse ( JSON . stringify ( connectContent . request . cookies ) ) ;
270
+ if ( request . cookies && ! / w s / . test ( content . protocol ) ) {
271
+ cookieDeeperCopy = JSON . parse ( JSON . stringify ( content . request . cookies ) ) ;
242
272
cookieDeeperCopy . push ( {
243
- id : cookies . length + 1 ,
273
+ id : request . cookies . length + 1 ,
244
274
active : false ,
245
275
key : '' ,
246
276
value : '' ,
@@ -255,13 +285,15 @@ const History = (props: Props)=> {
255
285
count : cookieDeeperCopy ? cookieDeeperCopy . length : 1 ,
256
286
} ;
257
287
const requestBodyObj = {
258
- bodyType : bodyType || 'raw' ,
259
- bodyContent : body || '' ,
260
- bodyVariables : bodyVariables || '' ,
261
- rawType : rawType || 'text/plain' ,
262
- JSONFormatted : JSONFormatted || true ,
288
+ bodyType : request . bodyType ,
289
+ bodyContent : request . body ,
290
+ bodyVariables : request . bodyVariables ,
291
+ rawType : rawType ,
292
+ JSONFormatted : request . JSONFormatted ,
263
293
bodyIsNew : false ,
264
294
} ;
295
+ //call newRequestFieldsByProtocol to update protocol field to match history item selected before populating request
296
+ //newRequestFieldsByProtocol(state, action)
265
297
fieldsReplaced ( requestFieldObj ) ;
266
298
newRequestHeadersSet ( requestHeadersObj ) ;
267
299
newRequestCookiesSet ( requestCookiesObj ) ;
@@ -289,9 +321,11 @@ const History = (props: Props)=> {
289
321
newRequestStreamsSet ( requestStreamsObj ) ;
290
322
}
291
323
setSidebarTab ( 'composer' ) ;
324
+ console . log ( 'requestFieldObj: ' , requestFieldObj )
292
325
} ;
293
326
294
327
let colorClass ;
328
+
295
329
switch ( network ) {
296
330
case 'gRpc' :
297
331
colorClass = 'is-grpc-color' ;
@@ -300,12 +334,12 @@ const History = (props: Props)=> {
300
334
colorClass = 'is-rest-color' ;
301
335
break ;
302
336
case 'graphQL' :
303
- colorClass = 'is-graphQL-color' ;
337
+ colorClass = 'is -graphQL-color' ;
304
338
break ;
305
339
case 'ws' :
306
340
colorClass = 'is-ws-color' ;
307
341
break ;
308
- case 'openApi' :
342
+ case 'openApi' :;
309
343
colorClass = 'is-openapi-color' ;
310
344
break ;
311
345
case 'webRtc' :
@@ -314,19 +348,19 @@ const History = (props: Props)=> {
314
348
}
315
349
316
350
const deleteHistory = ( event : any ) => {
317
- dispatch ( historyDeleted ( props . content ) ) ;
351
+ dispatch ( historyDeleted ( content ) ) ;
318
352
historyController . deleteHistoryFromIndexedDb ( event . target . id ) ;
319
353
} ;
320
354
321
- const urlDisplay = url && url . length > 32 ? url . slice ( 0 , 32 ) + '...' : url ;
355
+ const urlDisplay = content . url && content . url . length > 32 ? content . url . slice ( 0 , 32 ) + '...' : content . url ;
322
356
323
357
return (
324
358
< div className = "history-container is-flex is-justify-content-space-between m-3" >
325
359
< div
326
360
className = "is-clickable is-primary-link is-flex"
327
361
onClick = { ( ) => addHistoryToNewRequest ( ) }
328
362
>
329
- < div className = { `history-method mr-2 ${ colorClass } ` } > { method } </ div >
363
+ < div className = { `history-method mr-2 ${ colorClass } ` } > { content . request . method } </ div >
330
364
< div className = "history-url" > { urlDisplay || '-' } </ div >
331
365
</ div >
332
366
< div className = "history-delete-container" >
0 commit comments