fix: fix json stringify bug in response timeline

This commit is contained in:
Anoop M D 2023-01-21 19:54:06 +05:30
parent dd4fecfd1c
commit d01cada16c
3 changed files with 30 additions and 5 deletions

View File

@ -163,7 +163,6 @@ export default class QueryEditor extends React.Component {
let variables = getEnvironmentVariables(this.props.collection);
if (!isEqual(variables, this.variables)) {
this.editor.options.brunoVarInfo.variables = variables;
console.log(variables);
this.addOverlay();
}
}
@ -180,7 +179,6 @@ export default class QueryEditor extends React.Component {
addOverlay = () => {
let variables = getEnvironmentVariables(this.props.collection);
this.variables = variables;
console.log(variables);
defineCodeMirrorBrunoVariablesMode(variables, 'graphql');
this.editor.setOption('mode', 'brunovariables');

View File

@ -1,5 +1,6 @@
import React from 'react';
import forOwn from 'lodash/forOwn';
import { safeStringifyJSON } from 'utils/common';
import StyledWrapper from './StyledWrapper';
const Timeline = ({ item }) => {
@ -15,6 +16,8 @@ const Timeline = ({ item }) => {
});
});
let requestData = safeStringifyJSON(request.data);
return (
<StyledWrapper className="px-3 pb-4 w-full">
<div>
@ -29,9 +32,11 @@ const Timeline = ({ item }) => {
);
})}
<pre className='line request'>
<span className="arrow">{'>'}</span> data {request.data ? request.data : 'null'}
</pre>
{requestData ? (
<pre className='line request'>
<span className="arrow">{'>'}</span> data {requestData}
</pre>
) : null}
</div>
<div className='mt-4'>

View File

@ -24,3 +24,25 @@ export const waitForNextTick = () => {
setTimeout(() => resolve(), 0);
});
};
export const safeParseJSON = (str) => {
if(!str || !str.length || typeof str !== 'string') {
return str;
}
try {
return JSON.parse(str);
} catch (e) {
return str;
}
};
export const safeStringifyJSON = (obj) => {
if(!obj) {
return obj;
}
try {
return JSON.stringify(obj);
} catch (e) {
return obj;
}
}