forked from ToolJet/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added a feature to show raw query responses (ToolJet#2562)
* Implemented json/raw preview modes * Added dark theme * Changed some bg colors * made text copiable Co-authored-by: Sherfin Shamsudeen <sherfin94@gmail.com>
- Loading branch information
Showing
4 changed files
with
146 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useEffect } from 'react'; | ||
import { JSONTree } from 'react-json-tree'; | ||
import { Tab, ListGroup, Row } from 'react-bootstrap'; | ||
|
||
const Preview = ({ previewPanelRef, previewLoading, queryPreviewData, theme, darkMode }) => { | ||
const [key, setKey] = React.useState('raw'); | ||
const [isJson, setIsJson] = React.useState(false); | ||
const tabs = ['Json', 'Raw']; | ||
|
||
useEffect(() => { | ||
if (typeof queryPreviewData === 'object') { | ||
setKey('json'); | ||
} else { | ||
setKey('raw'); | ||
} | ||
setIsJson(typeof queryPreviewData === 'object'); | ||
}, [queryPreviewData]); | ||
|
||
const renderRawData = () => { | ||
if (queryPreviewData) { | ||
return isJson ? JSON.stringify(queryPreviewData).toString() : queryPreviewData.toString(); | ||
} | ||
return ''; | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className="row preview-header border-top" ref={previewPanelRef}> | ||
<div className="py-2" style={{ fontWeight: 600 }}> | ||
Preview | ||
</div> | ||
</div> | ||
<Tab.Container activeKey={key} onSelect={(k) => setKey(k)} defaultActiveKey="raw"> | ||
<Row> | ||
<div className="keys"> | ||
<ListGroup className={`query-preview-list-group ${darkMode ? 'dark' : ''}`} variant="flush"> | ||
{tabs.map((tab) => ( | ||
<ListGroup.Item key={tab} eventKey={tab.toLowerCase()}> | ||
<span>{tab}</span> | ||
</ListGroup.Item> | ||
))} | ||
</ListGroup> | ||
</div> | ||
{previewLoading && ( | ||
<center> | ||
<div className="spinner-border text-azure mt-5" role="status"></div> | ||
</center> | ||
)} | ||
<div className="col" style={{ userSelect: 'text' }}> | ||
<Tab.Content> | ||
<Tab.Pane eventKey="json" transition={false}> | ||
<div className="mb-3 mt-2"> | ||
{previewLoading === false && isJson && ( | ||
<div> | ||
<JSONTree theme={theme} data={queryPreviewData} invertTheme={!darkMode} collectionLimit={100} /> | ||
</div> | ||
)} | ||
</div> | ||
</Tab.Pane> | ||
<Tab.Pane eventKey="raw" transition={false}> | ||
<div className={`mb-3 mt-2 raw-container ${darkMode ? 'dark' : ''}`}>{renderRawData()}</div> | ||
</Tab.Pane> | ||
</Tab.Content> | ||
</div> | ||
</Row> | ||
</Tab.Container> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Preview; |
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