Skip to content

Commit fdca984

Browse files
authored
Merge pull request #241 from HuolalaTech/feat/support-serialized-in-console
feat: support serialized data in console panel
2 parents 6f11185 + ed73a8b commit fdca984

File tree

8 files changed

+43
-11
lines changed

8 files changed

+43
-11
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@huolala-tech/page-spy-plugin-data-harbor": "^1.3.0",
4949
"@huolala-tech/page-spy-plugin-rrweb": "^1.2.0",
5050
"@huolala-tech/page-spy-types": "^1.9.0",
51-
"@huolala-tech/react-json-view": "^1.2.4",
51+
"@huolala-tech/react-json-view": "^1.2.5",
5252
"@huolala-tech/request": "^1.1.2",
5353
"acorn": "^8.11.3",
5454
"ahooks": "^3.1.9",

src/assets/locales/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@
146146
"failed-advice": "Here are some suggestions to fix and improve the situation:",
147147
"fix-suggestion-1": "<0>1. Ensure file existence: When locating the source code for each error stack, two files need to be requested - the compressed file and the sourcemap file. The rule for obtaining the sourcemap file is based on the address indicated by</0> <1>//# sourceMappingURL=*</1> <2>in the contents of the compressed file;</2>",
148148
"fix-suggestion-2": "2. Troubleshoot network issues: If there are access restrictions on the server where your source files are located, it may lead to failed requests when trying to access the resources. You can open the devtool to check if the network is working properly."
149-
}
149+
},
150+
"non-serializable": "<non-serializable>"
150151
},
151152
"network": {
152153
"open-in-new-tab": "Open in new tab",

src/assets/locales/ja.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@
145145
"failed-advice": "以下は修正と改善の提案です:",
146146
"fix-suggestion-1": "<0>1. ファイルの存在を確認:各エラースタックでソースコードを特定するためには、2つのファイル(圧縮ファイルとソースマップファイル)が要求されます。ソースマップファイルの取得規則は圧縮ファイル内の</0><1>//# sourceMappingURL=*</1><2>に指定されたアドレスに従います;</2>",
147147
"fix-suggestion-2": "2. ネットワークの問題を除外:ソースファイルが存在するサーバーにアクセス制限がある場合、リソースの取得に失敗する可能性があるため、ネットワークリクエストが正常かどうかをコンソールで確認できます。"
148-
}
148+
},
149+
"non-serializable": "<non-serializable>"
149150
},
150151
"network": {
151152
"open-in-new-tab": "新しいタブで開く",

src/assets/locales/ko.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@
145145
"failed-advice": "다음은 수정 및 개선 제안입니다:",
146146
"fix-suggestion-1": "<0>1. 파일이 존재하는지 확인하십시오. 각 오류 스택은 소스 코드를 확인하기 위해 2 개의 파일 (압축 파일 및 소스 맵 파일)을 요청합니다. 소스 맵 파일 가져오기 규칙은 압축 파일 내</0><1>//# sourceMappingURL=*</1><2>에 지정된 주소를 기준으로합니다.</2>",
147147
"fix-suggestion-2": "2. 네트워크 문제 제외: 원본 파일이있는 서버에 액세스 제한이있는 경우 리소스 가져오기 실패가 발생할 수 있으므로 네트워크 요청이 정상적인지 확인하려면 콘솔을 열 수 있습니다."
148-
}
148+
},
149+
"non-serializable": "<non-serializable>"
149150
},
150151
"network": {
151152
"open-in-new-tab": "새 탭에서 열기",

src/assets/locales/zh.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@
145145
"failed-advice": "以下是修复和改进的建议:",
146146
"fix-suggestion-1": "<0>1. 确保文件存在:每个错误栈定位源码时都需要请求两个文件,分别是压缩文件和 sourcemap 文件,sourcemap 文件的获取规则是根据压缩文件内容中的</0><1>//# sourceMappingURL=*</1><2>所指向的地址;</2>",
147147
"fix-suggestion-2": "2. 排除网络故障:如果你的源文件所在服务器有限制访问规则,则可能导致请求资源时出现失败,你可以打开控制台查看网络请求是否正常。"
148-
}
148+
},
149+
"non-serializable": "<数据序列化失败>"
149150
},
150151
"network": {
151152
"open-in-new-tab": "新窗口打开",

src/components/ConsoleItem/index.less

+13
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,17 @@
4343
color: #000;
4444
}
4545
}
46+
.rjv {
47+
font-size: 12px;
48+
svg {
49+
&.rjv-ref-arrow {
50+
width: 8px;
51+
height: 8px;
52+
}
53+
}
54+
}
55+
.non-serializable {
56+
font-size: 12px;
57+
color: #aaa;
58+
}
4659
}

src/components/ConsoleItem/index.tsx

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import { getLogUrl } from '@/utils';
1515
import './index.less';
1616
import Timestamp from '../Timestamp';
1717
import { useMemo } from 'react';
18+
import ReactJsonView from '@huolala-tech/react-json-view';
19+
import { useTranslation } from 'react-i18next';
1820

1921
interface Props {
2022
data: SpyConsole.DataItem;
2123
}
2224

2325
export const ConsoleItem = ({ data }: Props) => {
26+
const { t } = useTranslation();
2427
const content = useMemo(() => {
2528
if (isPlaceholderNode(data)) {
2629
return <PlaceholderNode data={data.logs} />;
@@ -34,9 +37,19 @@ export const ConsoleItem = ({ data }: Props) => {
3437
if (framesOfErrorConsole) {
3538
return <ErrorTraceNode data={framesOfErrorConsole} key={log.id} />;
3639
}
40+
if (log.type === 'json') {
41+
if (log.value === null) {
42+
return (
43+
<code key={log.id} className="non-serializable">
44+
{t('console.non-serializable')}
45+
</code>
46+
);
47+
}
48+
return <ReactJsonView source={JSON.parse(log.value)} key={log.id} />;
49+
}
3750
return <ConsoleNode data={log} key={log.id} />;
3851
});
39-
}, [data]);
52+
}, [data, t]);
4053
return (
4154
<div className={`console-item ${data.logType}`} key={data.id}>
4255
<div className="console-item__title">
@@ -47,7 +60,9 @@ export const ConsoleItem = ({ data }: Props) => {
4760
<Col style={{ flexShrink: 0 }}>
4861
<Timestamp time={data.time} />
4962
</Col>
50-
<Col flex={1}>{content}</Col>
63+
<Col flex={1} style={{ display: 'flex' }}>
64+
{content}
65+
</Col>
5166
</Row>
5267
</div>
5368
<div className="console-item__url" title={data.url}>

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,10 @@
766766
resolved "https://registry.npmjs.org/@huolala-tech/page-spy-types/-/page-spy-types-1.9.0.tgz#d09cc0b4702bb38f5d4620a80fdbd27db75a9253"
767767
integrity sha512-1WouAJF+WAHBhG2y/xRpENF+g9Y7gfYmb1BVE/73fyyLRrHYb1mUIk7j/QTlqFi7v5/p2j7yLOmAV3xVS469+w==
768768

769-
"@huolala-tech/react-json-view@^1.2.4":
770-
version "1.2.4"
771-
resolved "https://registry.npmjs.org/@huolala-tech/react-json-view/-/react-json-view-1.2.4.tgz#7e8bec7fa16a42d90ffc406f327848b116d4efe0"
772-
integrity sha512-90Oc40JUm4TZnjNzcu3BECk9Rs1nkciGiOsdjuCJFsXntKeLTpp7S0xNxISvr3+R/PsGdlb1c9HWvBp7EYUSpw==
769+
"@huolala-tech/react-json-view@^1.2.5":
770+
version "1.2.5"
771+
resolved "https://registry.yarnpkg.com/@huolala-tech/react-json-view/-/react-json-view-1.2.5.tgz#fa593f8bff9ac30a4c21f7f9cd5987d7f9ed3199"
772+
integrity sha512-54KSj2BHLPzWpRhPaLO9k6COgrcLkU8XN8HYaP0KHWBnrdjdwCv8Ola4R8il+iC1UxDcR0KLLzSA+ze51XgLFg==
773773
dependencies:
774774
copy-to-clipboard "^3.3.3"
775775

0 commit comments

Comments
 (0)