Skip to content

Commit 5932215

Browse files
authored
Merge pull request #10 from oslabs-beta/esa/subscriptions
Esa/subscriptions
2 parents 11204f3 + deeddb4 commit 5932215

File tree

2 files changed

+89
-57
lines changed

2 files changed

+89
-57
lines changed

src/client/components/workspace/History.tsx

Lines changed: 88 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
Network,
2323
ReqResRequest,
2424
ReqResResponse } from '../../../types.js';
25+
import { request } from 'http';
26+
import { graphql } from 'graphql';
2527

2628
interface NewRequestCookiesSet {
2729
cookiesArr: CookieOrHeader[];
@@ -117,45 +119,73 @@ interface Props {
117119
}
118120

119121
const History = (props: Props)=> {
122+
//destructuring props
120123
const {
121-
newRequestFields,
122-
newRequestsOpenAPI,
123124
content,
124-
connectContent,
125125
fieldsReplaced,
126126
newRequestHeadersSet,
127127
newRequestCookiesSet,
128128
newRequestBodySet,
129129
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,
132144
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,
133161
restUrl,
162+
testContent,
163+
testResults,
164+
webRtc,
165+
webRtcUrl,
166+
ws,
134167
wsUrl,
135-
gqlUrl,
136-
webrtcUrl,
137-
grpcUrl,
138-
method
139-
} = props;
140-
168+
} = request;
169+
141170
const dispatch = useDispatch();
142171
const setSidebarTab = (tabName: string) => dispatch(setSidebarActiveTab(tabName));
143172
const setNewRequestSSE = (bool: boolean) => dispatch(newRequestSSESet(bool));
144173

145174
const addHistoryToNewRequest = () => {
175+
146176
let requestFieldObj = {};
147177
if (network === 'rest') {
148178
requestFieldObj = {
149179
...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,
159189
testContent: content.request.testContent,
160190
};
161191
}
@@ -170,47 +200,47 @@ const History = (props: Props)=> {
170200
restUrl,
171201
graphQL: connectContent.graphQL || false,
172202
gRPC: connectContent.gRPC || false,
173-
webrtc: connectContent.webrtc || false,
203+
webrtc: content.webrtc,
174204
network,
175205
};
176206
}
177207
if (network === 'ws') {
178208
requestFieldObj = {
179209
...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,
183213
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,
187217
network,
188218
};
189219
}
190220
if (network === 'graphQL') {
191221
requestFieldObj = {
192222
...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,
196226
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,
200230
network,
201231
};
202232
}
203233
if (network === 'webRtc') {
204234
requestFieldObj = {
205235
...newRequestFields,
206-
method: connectContent.request.method || 'GET',
207-
protocol: connectContent.protocol || 'http://',
236+
method: content.request.method || 'GET',
237+
protocol: content.protocol || 'http://',
208238
url,
209239
webrtcUrl,
210240
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,
214244
network,
215245
};
216246
}
@@ -227,20 +257,20 @@ const History = (props: Props)=> {
227257
};
228258
}
229259
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));
232262
headerDeeperCopy.push({
233-
id: headers.length + 1,
263+
id: request.headers.length + 1,
234264
active: false,
235265
key: '',
236266
value: '',
237267
});
238268
}
239269
let cookieDeeperCopy;
240-
if (connectContent.request.cookies && !/ws/.test(connectContent.protocol)) {
241-
cookieDeeperCopy = JSON.parse(JSON.stringify(connectContent.request.cookies));
270+
if (request.cookies && !/ws/.test(content.protocol)) {
271+
cookieDeeperCopy = JSON.parse(JSON.stringify(content.request.cookies));
242272
cookieDeeperCopy.push({
243-
id: cookies.length + 1,
273+
id: request.cookies.length + 1,
244274
active: false,
245275
key: '',
246276
value: '',
@@ -255,13 +285,15 @@ const History = (props: Props)=> {
255285
count: cookieDeeperCopy ? cookieDeeperCopy.length : 1,
256286
};
257287
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,
263293
bodyIsNew: false,
264294
};
295+
//call newRequestFieldsByProtocol to update protocol field to match history item selected before populating request
296+
//newRequestFieldsByProtocol(state, action)
265297
fieldsReplaced(requestFieldObj);
266298
newRequestHeadersSet(requestHeadersObj);
267299
newRequestCookiesSet(requestCookiesObj);
@@ -289,9 +321,11 @@ const History = (props: Props)=> {
289321
newRequestStreamsSet(requestStreamsObj);
290322
}
291323
setSidebarTab('composer');
324+
console.log('requestFieldObj: ',requestFieldObj)
292325
};
293326

294327
let colorClass;
328+
295329
switch (network) {
296330
case 'gRpc':
297331
colorClass = 'is-grpc-color';
@@ -300,12 +334,12 @@ const History = (props: Props)=> {
300334
colorClass = 'is-rest-color';
301335
break;
302336
case 'graphQL':
303-
colorClass = 'is-graphQL-color';
337+
colorClass = 'is -graphQL-color';
304338
break;
305339
case 'ws':
306340
colorClass = 'is-ws-color';
307341
break;
308-
case 'openApi':
342+
case 'openApi':;
309343
colorClass = 'is-openapi-color';
310344
break;
311345
case 'webRtc':
@@ -314,19 +348,19 @@ const History = (props: Props)=> {
314348
}
315349

316350
const deleteHistory = (event: any) => {
317-
dispatch(historyDeleted(props.content));
351+
dispatch(historyDeleted(content));
318352
historyController.deleteHistoryFromIndexedDb(event.target.id);
319353
};
320354

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;
322356

323357
return (
324358
<div className="history-container is-flex is-justify-content-space-between m-3">
325359
<div
326360
className="is-clickable is-primary-link is-flex"
327361
onClick={() => addHistoryToNewRequest()}
328362
>
329-
<div className={`history-method mr-2 ${colorClass}`}> {method} </div>
363+
<div className={`history-method mr-2 ${colorClass}`}> {content.request.method} </div>
330364
<div className="history-url"> {urlDisplay || '-'} </div>
331365
</div>
332366
<div className="history-delete-container">

src/client/components/workspace/HistoryDate.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ export default function HistoryDate(props: Props) {
6565
const histArray = current.history.map((history: [], i: number) => {
6666
return (
6767
<History
68+
key={i}
6869
content={history}
69-
key={i}
70-
focusOnForm={focusOnForm}
71-
historyDeleted={historyDeleted}
7270
fieldsReplaced={fieldsReplaced}
7371
newRequestHeadersSet={newRequestHeadersSet}
7472
newRequestCookiesSet={newRequestCookiesSet}

0 commit comments

Comments
 (0)