|
1 | | -import React from 'react'; |
2 | | -import SSERow from './SSERow.jsx'; |
3 | | -import JSONPretty from 'react-json-pretty'; |
4 | | -import createDOMPurify from 'dompurify'; |
5 | | - |
6 | | - |
| 1 | +import React from "react"; |
| 2 | +import JSONPretty from "react-json-pretty"; |
| 3 | +import createDOMPurify from "dompurify"; |
| 4 | +import SSERow from "./SSERow.jsx"; |
7 | 5 |
|
8 | 6 | const ResponseEventsDisplay = ({ response }) => { |
9 | 7 | const { events, headers } = response; |
10 | 8 | const displayContents = []; |
11 | 9 |
|
12 | 10 | // If it's an SSE, render event rows |
13 | | - |
14 | | - if (headers && headers['content-type'] && headers['content-type'].includes('text/event-stream')) { |
| 11 | + |
| 12 | + if ( |
| 13 | + headers && |
| 14 | + headers["content-type"] && |
| 15 | + headers["content-type"].includes("text/event-stream") |
| 16 | + ) { |
15 | 17 | events.forEach((cur, idx) => { |
16 | 18 | displayContents.push(<SSERow key={idx} content={cur} />); |
17 | 19 | }); |
18 | 20 | } |
19 | 21 | // if the response content-type, purify and render html |
20 | | - else if (headers && headers['content-type'] && headers['content-type'].includes('text/html')) { |
| 22 | + else if ( |
| 23 | + headers && |
| 24 | + headers["content-type"] && |
| 25 | + headers["content-type"].includes("text/html") |
| 26 | + ) { |
| 27 | + // console.log("headers:content-type ->", headers["content-type"]); |
| 28 | + // console.log("events0 -> ", events[0]); |
21 | 29 | displayContents.push( |
22 | | - <div className="okay" dangerouslySetInnerHTML={{__html: createDOMPurify.sanitize(events[0])}} /> |
23 | | - ) |
24 | | - } |
25 | | - else if (events && events.length > 1) { |
| 30 | + <div |
| 31 | + className="okay" |
| 32 | + key="http2_html_content" |
| 33 | + dangerouslySetInnerHTML={{ |
| 34 | + __html: createDOMPurify.sanitize(events[0]), |
| 35 | + }} |
| 36 | + /> |
| 37 | + ); |
| 38 | + } else if (events && events.length > 1) { |
26 | 39 | if (events) { |
27 | | - let resEvents = ''; |
| 40 | + let resEvents = ""; |
28 | 41 | let eventJSON; |
29 | 42 | for (const event of events) { |
30 | 43 | eventJSON = JSON.stringify(event, null, 4); |
31 | 44 | resEvents = `${resEvents} |
32 | | -${eventJSON}` |
| 45 | +${eventJSON}`; |
33 | 46 | } |
34 | 47 | displayContents.push( |
35 | 48 | <div className="json-response" key="jsonresponsediv"> |
36 | | - <JSONPretty data={resEvents} space="4" theme={{ |
37 | | - main: 'line-height:1.3; color: midnightblue; background:#RRGGBB; overflow:auto;', |
38 | | - key: 'color:#0089D0;', // bluetwo |
39 | | - string: 'color:#15B78F;',// greenone |
40 | | - value: 'color:#fd971f;', // a nice orange |
41 | | - boolean: 'color:#E00198;', // gqlpink |
42 | | - }} |
| 49 | + <JSONPretty |
| 50 | + data={resEvents} |
| 51 | + space="4" |
| 52 | + theme={{ |
| 53 | + main: |
| 54 | + "line-height:1.3; color: midnightblue; background:#RRGGBB; overflow:auto;", |
| 55 | + key: "color:#0089D0;", // bluetwo |
| 56 | + string: "color:#15B78F;", // greenone |
| 57 | + value: "color:#fd971f;", // a nice orange |
| 58 | + boolean: "color:#E00198;", // gqlpink |
| 59 | + }} |
43 | 60 | /> |
44 | 61 | </div> |
45 | 62 | ); |
46 | 63 | } |
47 | | - |
48 | 64 | } |
49 | 65 |
|
50 | 66 | // Otherwise, render a single display |
51 | | - else { |
52 | | - if (events) { |
53 | | - displayContents.push( |
54 | | - <div className="json-response" key="jsonresponsediv"> |
55 | | - <JSONPretty data={events[0]} space="4" theme={{ |
56 | | - main: 'line-height:1.3; color: midnightblue; background:#RRGGBB; overflow:auto;', |
57 | | - key: 'color:#0089D0;', // bluetwo |
58 | | - string: 'color:#15B78F;',// greenone |
59 | | - value: 'color:#fd971f;', // a nice orange |
60 | | - boolean: 'color:#E00198;', // gqlpink |
| 67 | + else if (events) { |
| 68 | + displayContents.push( |
| 69 | + <div className="json-response" key="jsonresponsediv"> |
| 70 | + <JSONPretty |
| 71 | + data={events[0]} |
| 72 | + space="4" |
| 73 | + theme={{ |
| 74 | + main: |
| 75 | + "line-height:1.3; color: midnightblue; background:#RRGGBB; overflow:auto;", |
| 76 | + key: "color:#0089D0;", // bluetwo |
| 77 | + string: "color:#15B78F;", // greenone |
| 78 | + value: "color:#fd971f;", // a nice orange |
| 79 | + boolean: "color:#E00198;", // gqlpink |
61 | 80 | }} |
62 | | - /> |
63 | | - </div> |
64 | | - ); |
65 | | - } |
| 81 | + /> |
| 82 | + </div> |
| 83 | + ); |
66 | 84 | } |
67 | 85 |
|
68 | 86 | return <div className="tab_content-response">{displayContents}</div>; |
69 | | -} |
| 87 | +}; |
70 | 88 |
|
71 | 89 | export default ResponseEventsDisplay; |
0 commit comments