From 3624acbcf84781f1e9780aeea28c8d6d6ccf44b3 Mon Sep 17 00:00:00 2001 From: Yi Yuan <269081523@qq.com> Date: Sat, 9 Jan 2021 06:55:55 +0800 Subject: [PATCH] fix web-console show json bug (#10710) * fix web-console show json bug * replace all JSON.stringify Co-authored-by: yuanyi --- .../components/json-collapse/json-collapse.spec.tsx | 3 ++- .../src/components/json-collapse/json-collapse.tsx | 3 ++- web-console/src/components/json-input/json-input.tsx | 5 +++-- .../src/components/show-history/show-history.tsx | 3 ++- web-console/src/components/show-json/show-json.tsx | 3 ++- web-console/src/components/show-log/show-log.tsx | 3 ++- web-console/src/components/table-cell/table-cell.tsx | 3 ++- .../edit-context-dialog/edit-context-dialog.tsx | 3 ++- .../dialogs/history-dialog/history-dialog.spec.tsx | 5 +++-- .../dialogs/query-plan-dialog/query-plan-dialog.tsx | 11 ++++++++--- .../src/dialogs/snitch-dialog/snitch-dialog.spec.tsx | 5 +++-- web-console/src/dialogs/spec-dialog/spec-dialog.tsx | 5 ++++- web-console/src/utils/local-storage-backed-array.tsx | 4 +++- web-console/src/utils/local-storage-keys.tsx | 4 +++- web-console/src/utils/object-change.spec.ts | 4 +++- web-console/src/utils/query-history.ts | 4 +++- web-console/src/utils/sampler.ts | 4 +++- .../src/views/load-data-view/load-data-view.tsx | 9 +++++---- .../parse-data-table/parse-data-table.tsx | 3 ++- .../views/query-view/query-output/query-output.tsx | 3 ++- web-console/src/views/query-view/query-view.tsx | 5 +++-- web-console/src/views/segments-view/segments-view.tsx | 5 +++-- 22 files changed, 65 insertions(+), 32 deletions(-) diff --git a/web-console/src/components/json-collapse/json-collapse.spec.tsx b/web-console/src/components/json-collapse/json-collapse.spec.tsx index 33dbd8b8907..a78e3ba4f1d 100644 --- a/web-console/src/components/json-collapse/json-collapse.spec.tsx +++ b/web-console/src/components/json-collapse/json-collapse.spec.tsx @@ -17,6 +17,7 @@ */ import { shallow } from 'enzyme'; +import * as JSONBig from 'json-bigint-native'; import React from 'react'; import { JsonCollapse } from './json-collapse'; @@ -24,7 +25,7 @@ import { JsonCollapse } from './json-collapse'; describe('JsonCollapse', () => { it('matches snapshot', () => { const jsonCollapse = shallow( - , + , ); expect(jsonCollapse).toMatchSnapshot(); }); diff --git a/web-console/src/components/json-collapse/json-collapse.tsx b/web-console/src/components/json-collapse/json-collapse.tsx index 09b4ee27c98..3a92db4db63 100644 --- a/web-console/src/components/json-collapse/json-collapse.tsx +++ b/web-console/src/components/json-collapse/json-collapse.tsx @@ -17,6 +17,7 @@ */ import { Button, Collapse, TextArea } from '@blueprintjs/core'; +import * as JSONBig from 'json-bigint-native'; import React, { useState } from 'react'; import './json-collapse.scss'; @@ -30,7 +31,7 @@ export const JsonCollapse = React.memo(function JsonCollapse(props: JsonCollapse const { stringValue, buttonText } = props; const [isOpen, setIsOpen] = useState(false); - const prettyValue = JSON.stringify(JSON.parse(stringValue), undefined, 2); + const prettyValue = JSONBig.stringify(JSON.parse(stringValue), undefined, 2); return (
diff --git a/web-console/src/components/json-input/json-input.tsx b/web-console/src/components/json-input/json-input.tsx index ff08db2940c..3da21edb5aa 100644 --- a/web-console/src/components/json-input/json-input.tsx +++ b/web-console/src/components/json-input/json-input.tsx @@ -19,6 +19,7 @@ import { Editor } from 'brace'; import classNames from 'classnames'; import Hjson from 'hjson'; +import * as JSONBig from 'json-bigint-native'; import React, { useEffect, useRef, useState } from 'react'; import AceEditor from 'react-ace'; @@ -44,7 +45,7 @@ export function extractRowColumnFromHjsonError( function stringifyJson(item: any): string { if (item != null) { - const str = JSON.stringify(item, null, 2); + const str = JSONBig.stringify(item, undefined, 2); if (str === '{}') return '{\n\n}'; // Very special case for an empty object to make it more beautiful return str; } else { @@ -54,7 +55,7 @@ function stringifyJson(item: any): string { // Not the best way to check for deep equality but good enough for what we need function deepEqual(a: any, b: any): boolean { - return JSON.stringify(a) === JSON.stringify(b); + return JSONBig.stringify(a) === JSONBig.stringify(b); } interface InternalValue { diff --git a/web-console/src/components/show-history/show-history.tsx b/web-console/src/components/show-history/show-history.tsx index a6086e66117..dfad3e0a7e8 100644 --- a/web-console/src/components/show-history/show-history.tsx +++ b/web-console/src/components/show-history/show-history.tsx @@ -17,6 +17,7 @@ */ import { Tab, Tabs } from '@blueprintjs/core'; +import * as JSONBig from 'json-bigint-native'; import React from 'react'; import { useQueryManager } from '../../hooks'; @@ -59,7 +60,7 @@ export const ShowHistory = React.memo(function ShowHistory(props: ShowHistoryPro { ); const data = resp.data; - let logValue = typeof data === 'string' ? data : JSON.stringify(data, undefined, 2); + let logValue = typeof data === 'string' ? data : JSONBig.stringify(data, undefined, 2); if (tailOffset) logValue = removeFirstPartialLine(logValue); return logValue; }, diff --git a/web-console/src/components/table-cell/table-cell.tsx b/web-console/src/components/table-cell/table-cell.tsx index 99bcb4227c4..5fd4bf63712 100644 --- a/web-console/src/components/table-cell/table-cell.tsx +++ b/web-console/src/components/table-cell/table-cell.tsx @@ -17,6 +17,7 @@ */ import { IconNames } from '@blueprintjs/icons'; +import * as JSONBig from 'json-bigint-native'; import React, { useState } from 'react'; import { ShowValueDialog } from '../../dialogs/show-value-dialog/show-value-dialog'; @@ -98,7 +99,7 @@ export const TableCell = React.memo(function TableCell(props: TableCellProps) { } else if (Array.isArray(value)) { return renderTruncated(`[${value.join(', ')}]`); } else if (typeof value === 'object') { - return renderTruncated(JSON.stringify(value)); + return renderTruncated(JSONBig.stringify(value)); } else { return renderTruncated(String(value)); } diff --git a/web-console/src/dialogs/edit-context-dialog/edit-context-dialog.tsx b/web-console/src/dialogs/edit-context-dialog/edit-context-dialog.tsx index 4e0cad0e29f..c9545296516 100644 --- a/web-console/src/dialogs/edit-context-dialog/edit-context-dialog.tsx +++ b/web-console/src/dialogs/edit-context-dialog/edit-context-dialog.tsx @@ -18,6 +18,7 @@ import { Button, Callout, Classes, Dialog, Intent, TextArea } from '@blueprintjs/core'; import Hjson from 'hjson'; +import * as JSONBig from 'json-bigint-native'; import React, { useState } from 'react'; import { QueryContext } from '../../utils/query-context'; @@ -43,7 +44,7 @@ export const EditContextDialog = React.memo(function EditContextDialog( const [state, setState] = useState(() => ({ queryContext: props.queryContext, queryContextString: Object.keys(props.queryContext).length - ? JSON.stringify(props.queryContext, undefined, 2) + ? JSONBig.stringify(props.queryContext, undefined, 2) : '{\n\n}', })); diff --git a/web-console/src/dialogs/history-dialog/history-dialog.spec.tsx b/web-console/src/dialogs/history-dialog/history-dialog.spec.tsx index 9ed39eeeb43..e7f53798dff 100644 --- a/web-console/src/dialogs/history-dialog/history-dialog.spec.tsx +++ b/web-console/src/dialogs/history-dialog/history-dialog.spec.tsx @@ -17,6 +17,7 @@ */ import { render } from '@testing-library/react'; +import * as JSONBig from 'json-bigint-native'; import React from 'react'; import { HistoryDialog } from './history-dialog'; @@ -26,8 +27,8 @@ describe('history dialog', () => { const historyDialog = ( ); diff --git a/web-console/src/dialogs/query-plan-dialog/query-plan-dialog.tsx b/web-console/src/dialogs/query-plan-dialog/query-plan-dialog.tsx index b55df8059fc..7a01dd1db08 100644 --- a/web-console/src/dialogs/query-plan-dialog/query-plan-dialog.tsx +++ b/web-console/src/dialogs/query-plan-dialog/query-plan-dialog.tsx @@ -25,6 +25,7 @@ import { Intent, TextArea, } from '@blueprintjs/core'; +import * as JSONBig from 'json-bigint-native'; import React from 'react'; import { BasicQueryExplanation, SemiJoinQueryExplanation } from '../../utils'; @@ -59,7 +60,11 @@ export const QueryPlanDialog = React.memo(function QueryPlanDialog(props: QueryP ); } - queryString = JSON.stringify((explainResult as BasicQueryExplanation).query[0], undefined, 2); + queryString = JSONBig.stringify( + (explainResult as BasicQueryExplanation).query[0], + undefined, + 2, + ); content = (
@@ -98,7 +103,7 @@ export const QueryPlanDialog = React.memo(function QueryPlanDialog(props: QueryP