Unverified Commit c3effadc authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

[Feature][Web]support custom editor language height light (#2451)

* Spotless Apply * support custom editor language height light * Spotless Apply --------- Co-authored-by: 's avatarzhu-mingye <zhu-mingye@users.noreply.github.com>
parent d9edebed
......@@ -193,5 +193,5 @@ export default defineConfig({
strategy: 'normal'
},
// requestRecord: {},
dva: {},
dva: {}
});
......@@ -54,7 +54,7 @@
"lodash": "^4.17.21",
"million": "^2.6.1",
"moment": "^2.29.4",
"monaco-editor": "^0.43.0",
"monaco-editor": "^0.44.0",
"omit.js": "^2.0.2",
"rc-menu": "^9.12.0",
"rc-util": "^5.37.0",
......@@ -93,6 +93,7 @@
"prettier": "^2",
"react-dev-inspector": "^2.0.0",
"react-inspector": "^6.0.2",
"sql-formatter": "^13.0.1",
"swagger-ui-dist": "^4.16.1",
"ts-node": "^10.9.1",
"typescript": "^4",
......
import {editor} from "monaco-editor";
import {languages} from "monaco-editor";
// todo 自定义语言不生效
export const JavaLog = () => {
// Register a new language
languages.register({ id: "java-log" });
// Register a tokens provider for the language
languages.setMonarchTokensProvider("java-log", {
tokenizer: {
root: [
[/\[error.*/, "custom-error"],
[/\[notice.*/, "custom-notice"],
[/.*/, "custom-info"],
[/\[[a-zA-Z 0-9:]+\]/, "custom-date"],
],
},
});
}
\ No newline at end of file
export function LogLanguage(monaco: any) {
// Register a new language
monaco?.languages.register({
id: 'javalog',
extensions: ['.log'],
aliases: ['javalog', 'Javalog', 'Javalog', 'jl', 'log']
});
monaco?.languages.setMonarchTokensProvider('javalog', {
// todo: 如果需要分段展示不同的颜色 则需要在这里添加规则, 且正则必须是严格模式, 否则会匹配一整行,无法达到预期效果
tokenizer: {
root: [
// 默认不区分大小写 //
[/\[(\w*-\d*)+\]/, 'custom-thread'],
[/\s+(\w.+):$/, 'custom-class'],
[/error/, 'custom-error'],
[/warring/, 'custom-warning'],
[/warn/, 'custom-warning'],
[/info/, 'custom-info'],
[
/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d\.\d{3}/,
'custom-date'
]
]
},
ignoreCase: true,
unicode: true
});
}
......@@ -24,8 +24,7 @@ import {
} from '@/pages/DataStudio/function';
import { isSql } from '@/pages/DataStudio/HeaderContainer/service';
import { StateType } from '@/pages/DataStudio/model';
import { postAll } from '@/services/api';
import {handleGetOption, handleGetOptionWithoutMsg} from '@/services/BusinessCrud';
import { handleGetOption, handleGetOptionWithoutMsg } from '@/services/BusinessCrud';
import { API_CONSTANTS } from '@/services/endpoints';
import { transformTableDataToCsv } from '@/utils/function';
import { l } from '@/utils/intl';
......@@ -238,7 +237,7 @@ const Result = (props: any) => {
{data.columns ? (
<Table
columns={getColumns(data.columns)}
size="small"
size='small'
dataSource={data.rowData?.map((item: any, index: number) => {
return { ...item, key: index };
})}
......
......@@ -24,7 +24,7 @@ import { StateType } from '@/pages/DataStudio/model';
import { l } from '@/utils/intl';
import { ConsoleSqlOutlined } from '@ant-design/icons';
import ProList from '@ant-design/pro-list';
import {Button, Drawer, Space, Tag, Typography} from 'antd';
import { Drawer, Space, Tag, Typography } from 'antd';
import React, { useEffect, useState } from 'react';
import { connect } from 'umi';
......@@ -48,8 +48,8 @@ export type ExplainProps = {
const Explain: React.FC<ExplainProps> = (props: any) => {
const [explainData, setExplainData] = useState([]);
const [result, setResult] = useState(<Text>{l('pages.datastudio.explain.validate')}</Text>);
const [showModal,setShowModal] = useState(false);
const [explainInfo,setExplainInfo] = useState("");
const [showModal, setShowModal] = useState(false);
const [explainInfo, setExplainInfo] = useState('');
const {
tabs: { panes, activeKey }
} = props;
......@@ -105,9 +105,9 @@ const Explain: React.FC<ExplainProps> = (props: any) => {
}
});
}, []);
const showPlanDrawer = (info:string) => {
const showPlanDrawer = (info: string) => {
setShowModal(true);
setExplainInfo(info)
setExplainInfo(info);
};
const renderContent = () => {
return (
......@@ -147,18 +147,28 @@ const Explain: React.FC<ExplainProps> = (props: any) => {
return (
<>
{row.sql ? (
<>
<Paragraph ellipsis={{ rows: 2, expandable: true, symbol: 'more' }}>
{row.sql}
</Paragraph>
</>
<>
<Paragraph ellipsis={{ rows: 2, expandable: true, symbol: 'more' }}>
{row.sql}
</Paragraph>
</>
) : null}
{row.error ? (
<Paragraph>
<CodeShow code={row.error} language='java' height='500px' />
</Paragraph>
) : null}
{row.explain ? <a onClick={()=>showPlanDrawer(row.explain)} style={{float:"right"}} type={"link"}>Show Plan</a> :<></>}
{row.explain ? (
<a
onClick={() => showPlanDrawer(row.explain)}
style={{ float: 'right' }}
type={'link'}
>
Show Plan
</a>
) : (
<></>
)}
</>
);
}
......@@ -207,8 +217,19 @@ const Explain: React.FC<ExplainProps> = (props: any) => {
<blockquote>{result}</blockquote>
</Paragraph>
{renderContent()}
<Drawer width={"50%"} title="Show Plan" placement="right" onClose={()=>setShowModal(false)} open={showModal}>
<CodeShow style={{alignItems:"inherit"}} code={explainInfo} language='java' height='500px' />
<Drawer
width={'50%'}
title='Show Plan'
placement='right'
onClose={() => setShowModal(false)}
open={showModal}
>
<CodeShow
style={{ alignItems: 'inherit' }}
code={explainInfo}
language='java'
height='500px'
/>
</Drawer>
</>
);
......
......@@ -123,40 +123,48 @@ export function getLocalTheme(): string {
* get code edit theme by localStorage's theme
* @constructor
*/
export function convertCodeEditTheme() {
export function convertCodeEditTheme(editorInstance?: any) {
if (!editorInstance) {
editorInstance = editor;
}
/**
* user can define a new theme by calling the defineTheme method on the editor.
* 定义亮色 覆盖vs主题,增加扩展规则
*/
editor.defineTheme(CODE_EDIT_THEME.VS_CUSTOME, {
editorInstance.defineTheme(CODE_EDIT_THEME.VS, {
base: 'vs', // 指定基础主题 , 可选值: 'vs', 'vs-dark', 'hc-black' , base theme
inherit: true, // 是否继承基础主题配置 , 默认为 true, is to inherit the base theme
// rules is an array of rules. The array must not be sparse (i.e. do not use holes).
inherit: true, // 是否继承主题配置
rules: [
{ token: 'comment', foreground: '#008800', fontStyle: 'italic' },
{ token: 'keyword', foreground: '#064cff', fontStyle: 'bold' },
{ token: 'string', foreground: '#507dee' },
{ token: 'delimiter', foreground: '#041d81' },
{
token: 'readonly',
foreground: '#e73a6e',
background: '#141414',
fontStyle: 'italic'
},
{ token: 'number', foreground: '#ffffff' }
// 注意,默认的不做修改 因为上边继承了父主题, 只添加自己定义的 , 否则会覆盖默认的 , 导致编辑器样式不一致
{ token: 'custom-info', foreground: '#808080' },
{ token: 'custom-thread', foreground: '#07f313' },
{ token: 'custom-class', foreground: '#1060d9' },
{ token: 'custom-error', foreground: '#ff0000', fontStyle: 'bold' },
{ token: 'custom-warning', foreground: '#FFA500', fontStyle: 'bold' },
{ token: 'custom-date', foreground: '#008800' },
{ token: 'custom-process', foreground: '#07f313' }
],
// colors is an object of color identifiers and their color values.
colors: {
// 'editor.background': '#2f2e2e', // editor background color
// 'editor.lineHighlightBackground': '#959cb6', // editor line highlight background color
// 'editorLineNumber.foreground': '#ffffff', // editor line number color
// 'editorCursor.foreground': '#ffffff', // editor cursor color
// 'editorIndentGuide.background': '#ffffff', // editor indent guide color
// 'editor.foreground': '#ffffff', // editor selection highlight border color
// 'editor.selectionBackground': '#4ba1ef', // editor selection highlight color
// 'editor.selectionHighlightBorder': '#4ba1ef', // editor selection highlight border color
// 'editor.findMatchBackground': '#4ba1ef', // editor find match highlight color
// 'editor.wordHighlightBackground': '#8bb2d2' // editor word highlight color
}
colors: {},
encodedTokensColors: []
});
/**
* 定义暗色 覆盖vs-dark主题,增加扩展规则
*/
editorInstance.defineTheme(CODE_EDIT_THEME.DARK, {
base: 'vs-dark', // 指定基础主题 , 可选值: 'vs', 'vs-dark', 'hc-black' , base theme
inherit: true, // 是否继承主题配置
rules: [
// 注意,默认的不做修改 因为上边继承了父主题, 只添加自己定义的 , 否则会覆盖默认的 , 导致编辑器样式不一致
{ token: 'custom-info', foreground: '#008800' },
{ token: 'custom-thread', foreground: '#07f313' },
{ token: 'custom-class', foreground: '#1060d9' },
{ token: 'custom-error', foreground: '#ff0000', fontStyle: 'bold' },
{ token: 'custom-warning', foreground: '#FFA500', fontStyle: 'bold' },
{ token: 'custom-date', foreground: '#008800' },
{ token: 'custom-process', foreground: '#07f313' }
],
colors: {},
encodedTokensColors: []
});
const theme = getLocalTheme();
......@@ -164,9 +172,9 @@ export function convertCodeEditTheme() {
case THEME.dark:
return CODE_EDIT_THEME.DARK;
case THEME.light:
return CODE_EDIT_THEME.VS_CUSTOME;
return CODE_EDIT_THEME.VS;
default:
return CODE_EDIT_THEME.VS_CUSTOME;
return CODE_EDIT_THEME.VS;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment