-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from oslabs-beta/subscription
Simplified ResponseEventsDisplay
- Loading branch information
Showing
7 changed files
with
46 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,34 @@ | ||
import React, { Component } from 'react'; | ||
import SSERow from './SSERow.jsx'; | ||
import EventRow from './EventRow.jsx'; | ||
import JSONPretty from 'react-json-pretty'; | ||
|
||
class ResponseEventsDisplay extends Component { | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
render() { | ||
const tabContentShownEvents = []; | ||
|
||
// Step 1 - Locate responses from store add them to cache array | ||
const responsesCache = []; | ||
responsesCache.push(this.props); | ||
|
||
// Step 2 - Increment across all responses in array | ||
responsesCache.forEach((cur, idx) => { | ||
const responseEvents = cur.responseContent.events; | ||
if (this.props.responseContent.headers) { | ||
const responseContentType = this.props.responseContent.headers['content-type']; | ||
const ResponseEventsDisplay = ({ props }) => { | ||
const { events, headers } = props; | ||
const displayContents = []; | ||
|
||
// Check content type of each response Update to use includes | ||
if (responseContentType && responseContentType.includes('text/event-stream')) { | ||
responseEvents.forEach((cur, idx) => { | ||
tabContentShownEvents.push(<SSERow key={idx} content={cur} />); | ||
}); | ||
} | ||
else { | ||
responseEvents.forEach((cur, idx) => { | ||
tabContentShownEvents.push( | ||
<div className="json-response" key={`jsonresponsediv+${idx}`}> | ||
<JSONPretty data={cur} space="4" theme={{ | ||
main: 'line-height:1.3; color: midnightblue; background:#RRGGBB; overflow:auto;', | ||
key: 'color:#0089D0;', //bluetwo | ||
string: 'color:#15B78F;',//greenone | ||
value: 'color:#fd971f;', //a nice orange | ||
boolean: 'color:#E00198;', //gqlpink | ||
}} | ||
/> | ||
</div> | ||
); | ||
}); | ||
} | ||
} | ||
// If it's an SSE, render event rows | ||
if (headers['content-type'] && headers['content-type'].includes('text/event-stream')) { | ||
events.forEach((cur, idx) => { | ||
displayContents.push(<EventRow key={idx} content={cur} />); | ||
}); | ||
|
||
return <div className="tab_content-response">{tabContentShownEvents}</div>; | ||
} | ||
// Otherwise, render a single display | ||
else { | ||
displayContents.push( | ||
<div className="json-response" key="jsonresponsediv"> | ||
<JSONPretty data={events[0]} space="4" theme={{ | ||
main: 'line-height:1.3; color: midnightblue; background:#RRGGBB; overflow:auto;', | ||
key: 'color:#0089D0;', // bluetwo | ||
string: 'color:#15B78F;',// greenone | ||
value: 'color:#fd971f;', // a nice orange | ||
boolean: 'color:#E00198;', // gqlpink | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
return <div className="tab_content-response">{displayContents}</div>; | ||
} | ||
|
||
export default ResponseEventsDisplay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters