Skip to content

Commit 9f79c79

Browse files
committed
chore: timeline log response viewer added
1 parent 6bc970a commit 9f79c79

File tree

2 files changed

+64
-11
lines changed

2 files changed

+64
-11
lines changed

frontend-dev/src/components/AllIntegrations/Log.jsx

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import Table from '../Utilities/Table'
66
import bitsFetch from '../../Utils/bitsFetch'
77
import CopyText from '../Utilities/CopyText'
88
import noData from '../../resource/img/nodata.svg'
9+
import Button from '../Utilities/Button'
10+
import CloseIcn from '../../Icons/CloseIcn'
11+
import Modal from '../Utilities/Modal'
12+
import { json } from 'react-router'
13+
import EyeIcn from '../Utilities/EyeIcn'
914

1015
function Log({ allIntegURL }) {
1116
const { id, type } = useParams()
@@ -16,6 +21,7 @@ function Log({ allIntegURL }) {
1621
const [countEntries, setCountEntries] = useState(0)
1722
const [isLoading, setIsLoading] = useState(false)
1823
const [refreshLog, setRefreshLog] = useState(0)
24+
const [response, setResponse] = useState(false)
1925

2026
const [log, setLog] = useState([])
2127
const [cols, setCols] = useState([
@@ -36,17 +42,18 @@ function Log({ allIntegURL }) {
3642
minWidth: 200,
3743
Header: __('Response', 'bit-integrations'),
3844
accessor: 'response_obj',
39-
Cell: (val) => (
40-
<CopyText
41-
value={val.row.values.response_obj}
42-
setSnackbar={setSnackbar}
43-
className="cpyTxt"
44-
/>
45+
Cell: val => (
46+
<>
47+
<CopyText value={val.row.values.response_obj} setSnackbar={setSnackbar} className="cpyTxt" />
48+
<Button className="icn-btn" onClick={() => setResponse(val.row.values.response_obj)}>
49+
<EyeIcn size="14" className="icn-rotate-45" />
50+
</Button>
51+
</>
4552
)
4653
},
4754
{ width: 220, minWidth: 200, Header: __('Date', 'bit-integrations'), accessor: 'created_at' }
4855
])
49-
const setTableCols = useCallback((newCols) => {
56+
const setTableCols = useCallback(newCols => {
5057
setCols(newCols)
5158
}, [])
5259
// route is info/:id but for redirect uri need to make new/:type
@@ -73,7 +80,7 @@ function Log({ allIntegURL }) {
7380
entries.push(rows.original.id)
7481
}
7582
const ajaxData = { id: entries }
76-
bitsFetch(ajaxData, 'log/delete').then((res) => {
83+
bitsFetch(ajaxData, 'log/delete').then(res => {
7784
if (res.success) {
7885
if (action && action.fetchData && action.data) {
7986
action.fetchData(action.data)
@@ -128,7 +135,7 @@ function Log({ allIntegURL }) {
128135
pageSize
129136
},
130137
'log/get'
131-
).then((res) => {
138+
).then(res => {
132139
if (res?.success) {
133140
setPageCount(Math.ceil(res.data.count / pageSize))
134141
setCountEntries(res.data.count)
@@ -189,8 +196,47 @@ function Log({ allIntegURL }) {
189196
</div>
190197
)}
191198
</div>
199+
200+
{response && (
201+
<Modal
202+
sm
203+
closeIcon
204+
show={response}
205+
setModal={setResponse}
206+
style={{ maxWidth: '900px' }}
207+
title={__('Response', 'bit-integrations')}>
208+
<div className="flx flx-around mr-1 mt-1">
209+
<div
210+
className="txt-dp"
211+
style={{
212+
background: '#1e293b',
213+
borderRadius: '8px',
214+
padding: '16px',
215+
color: '#f8fafc',
216+
fontFamily: "'Fira Code', monospace",
217+
fontSize: '14px',
218+
overflow: 'auto',
219+
maxWidth: '800px',
220+
maxHeight: '500px',
221+
boxShadow: '0 2px 8px rgba(0,0,0,0.15)'
222+
}}>
223+
<pre style={{ margin: 0 }}>
224+
<code className="">{jsonPrint(response)}</code>
225+
</pre>
226+
</div>
227+
</div>
228+
</Modal>
229+
)}
192230
</>
193231
)
194232
}
195233

196234
export default memo(Log)
235+
236+
const jsonPrint = data => {
237+
try {
238+
return JSON.stringify(JSON.parse(data), null, 2)
239+
} catch (e) {
240+
return data
241+
}
242+
}

frontend-dev/src/components/Utilities/CopyText.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ export default function CopyText({ value, setSnackbar, toastShow, className, rea
1313
text.setSelectionRange(0, 99999)
1414
document.execCommand('copy')
1515
toastShow && toast.success(__('Copied on Clipboard.'))
16-
setTimeout(() => { cpyBtn.setAttribute('style', '--tooltip-txt: "Copy"') }, 2000)
16+
setTimeout(() => {
17+
cpyBtn.setAttribute('style', '--tooltip-txt: "Copy"')
18+
}, 2000)
1719
}
1820

1921
return (
2022
<div className={className}>
2123
<label htmlFor={value} className="flx">
2224
<input id="copy-input-fld" className={`w-10 ${readOnly && 'readonly'}`} value={value} readOnly />
23-
<button onClick={copyText} className="tooltip" style={{ '--tooltip-txt': '"Copy"' }} aria-label="Copy" type="button">
25+
<button
26+
onClick={copyText}
27+
className="tooltip"
28+
style={{ '--tooltip-txt': '"Copy"' }}
29+
aria-label="Copy"
30+
type="button">
2431
<CopyIcn size="14" />
2532
</button>
2633
</label>

0 commit comments

Comments
 (0)