Skip to content

Commit fd338eb

Browse files
committed
1 parent 06a6924 commit fd338eb

1 file changed

Lines changed: 27 additions & 26 deletions

File tree

src/component/SQLCodePreviewer/index.tsx

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,33 @@
1919
* 说明:当前odc编辑器在(只读)模式下,不具备可编辑的原生能力(格式化)
2020
* 场景:仅需要查看格式化后的 SQL,不需要具备编辑能力的场景
2121
*/
22-
import React from 'react';
2322
import MonacoEditor, { IEditor, IProps } from '../MonacoEditor';
2423

25-
export class SQLCodePreviewer extends React.PureComponent<IProps> {
26-
render() {
27-
return (
28-
<>
29-
<MonacoEditor
30-
{...this.props}
31-
onEditorCreated={(editor: IEditor) => {
32-
const newEditor = Object.create(editor);
33-
this.props.onEditorCreated?.(
34-
Object.assign(newEditor, {
35-
doFormat() {
36-
import('@oceanbase-odc/ob-parser-js').then((module) => {
37-
const doc = new module.SQLDocument({
38-
text: editor.getValue(),
39-
});
40-
editor.setValue(doc.getFormatText());
41-
});
42-
},
43-
}),
44-
);
45-
}}
46-
/>
47-
</>
48-
);
49-
}
24+
export function SQLCodePreviewer(props: IProps) {
25+
return (
26+
<MonacoEditor
27+
{...props}
28+
onEditorCreated={(editor: IEditor) => {
29+
const newEditor = Object.create(editor);
30+
props.onEditorCreated?.(
31+
Object.assign(newEditor, {
32+
doFormat() {
33+
import('@oceanbase-odc/ob-parser-js').then((module) => {
34+
const map = {
35+
obmysql: module.SQLType.OBMySQL,
36+
mysql: module.SQLType.MySQL,
37+
oboracle: module.SQLType.Oracle,
38+
};
39+
const formatted = module.plugins.format({
40+
sql: editor.getValue(),
41+
type: map[props.language],
42+
});
43+
editor.setValue(formatted);
44+
});
45+
},
46+
}),
47+
);
48+
}}
49+
/>
50+
);
5051
}

0 commit comments

Comments
 (0)