Skip to content

Commit 8c7153e

Browse files
authored
[optimize]: the brief page (#479)
1 parent 2175edc commit 8c7153e

File tree

10 files changed

+363
-173
lines changed

10 files changed

+363
-173
lines changed

packages/components/src/components/CodeViewer/viewer.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@ import type { editor } from 'monaco-editor';
88
import { getOriginalLanguage, getSelectionRange } from '../../utils';
99
import { DefaultEditorConfig } from './config';
1010
import { TextDrawer } from '../TextDrawer';
11+
import { Empty } from 'antd';
1112

1213
interface CodeViewerProps {
1314
path: string;
1415
content: string;
1516
defaultLine?: number;
1617
ranges?: SDK.SourceRange[];
1718
editorConfig?: editor.IStandaloneEditorConstructionOptions;
19+
emptyReason?: string;
1820
}
1921

20-
export const CodeViewer: React.FC<CodeViewerProps> = ({ content, ranges, path, defaultLine, editorConfig = {} }) => {
22+
export const CodeViewer: React.FC<CodeViewerProps> = ({
23+
content,
24+
ranges,
25+
path,
26+
defaultLine,
27+
editorConfig = {},
28+
emptyReason,
29+
}) => {
2130
const handleEditorDidMount: OnMount = (editor, monaco) => {
2231
if (isNumber(defaultLine)) {
2332
editor.revealLine(defaultLine);
@@ -36,7 +45,7 @@ export const CodeViewer: React.FC<CodeViewerProps> = ({ content, ranges, path, d
3645
}
3746
};
3847

39-
return (
48+
return content ? (
4049
<Editor
4150
theme="vs-dark"
4251
language={getOriginalLanguage(path)}
@@ -46,6 +55,8 @@ export const CodeViewer: React.FC<CodeViewerProps> = ({ content, ranges, path, d
4655
options={{ ...DefaultEditorConfig, ...editorConfig }}
4756
onMount={handleEditorDidMount}
4857
/>
58+
) : (
59+
<Empty description={emptyReason} />
4960
);
5061
};
5162

0 commit comments

Comments
 (0)