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({ ...@@ -193,5 +193,5 @@ export default defineConfig({
strategy: 'normal' strategy: 'normal'
}, },
// requestRecord: {}, // requestRecord: {},
dva: {}, dva: {}
}); });
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
"lodash": "^4.17.21", "lodash": "^4.17.21",
"million": "^2.6.1", "million": "^2.6.1",
"moment": "^2.29.4", "moment": "^2.29.4",
"monaco-editor": "^0.43.0", "monaco-editor": "^0.44.0",
"omit.js": "^2.0.2", "omit.js": "^2.0.2",
"rc-menu": "^9.12.0", "rc-menu": "^9.12.0",
"rc-util": "^5.37.0", "rc-util": "^5.37.0",
...@@ -93,6 +93,7 @@ ...@@ -93,6 +93,7 @@
"prettier": "^2", "prettier": "^2",
"react-dev-inspector": "^2.0.0", "react-dev-inspector": "^2.0.0",
"react-inspector": "^6.0.2", "react-inspector": "^6.0.2",
"sql-formatter": "^13.0.1",
"swagger-ui-dist": "^4.16.1", "swagger-ui-dist": "^4.16.1",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^4", "typescript": "^4",
......
...@@ -18,16 +18,15 @@ ...@@ -18,16 +18,15 @@
*/ */
import EditorFloatBtn from '@/components/CustomEditor/EditorFloatBtn'; import EditorFloatBtn from '@/components/CustomEditor/EditorFloatBtn';
import {CODE_EDIT_THEME, MonacoEditorOptions, THEME} from '@/types/Public/data'; import { LogLanguage } from '@/components/CustomEditor/languages/javalog';
import {convertCodeEditTheme} from '@/utils/function'; import useThemeValue from '@/hooks/useThemeValue';
import {Editor, loader} from '@monaco-editor/react'; import { MonacoEditorOptions } from '@/types/Public/data';
import * as monaco from 'monaco-editor'; import { convertCodeEditTheme } from '@/utils/function';
import {editor} from 'monaco-editor'; import { Editor, useMonaco } from '@monaco-editor/react';
import {EditorLanguage} from 'monaco-editor/esm/metadata'; import { editor } from 'monaco-editor';
import {useEffect, useState} from 'react'; import { EditorLanguage } from 'monaco-editor/esm/metadata';
import { useEffect, useState } from 'react';
import FullscreenBtn from '../FullscreenBtn'; import FullscreenBtn from '../FullscreenBtn';
import useThemeValue from "@/hooks/useThemeValue";
import {JavaLog} from "@/components/CustomEditor/languages/javalog";
// loader.config({monaco}); // loader.config({monaco});
/** /**
...@@ -38,234 +37,235 @@ import {JavaLog} from "@/components/CustomEditor/languages/javalog"; ...@@ -38,234 +37,235 @@ import {JavaLog} from "@/components/CustomEditor/languages/javalog";
* 2. Callback for right-clicking to clear logs (optional, not required) * 2. Callback for right-clicking to clear logs (optional, not required)
*/ */
export type CodeShowFormProps = { export type CodeShowFormProps = {
height?: string | number; height?: string | number;
width?: string; width?: string;
language?: EditorLanguage | string; language?: EditorLanguage | string;
options?: any; options?: any;
code: string; code: string;
lineNumbers?: string; lineNumbers?: string;
autoWrap?: string; autoWrap?: string;
showFloatButton?: boolean; showFloatButton?: boolean;
refreshLogCallback?: () => void; refreshLogCallback?: () => void;
fullScreenBtn?: boolean; fullScreenBtn?: boolean;
style?: React.CSSProperties; style?: React.CSSProperties;
}; };
const CodeShow = (props: CodeShowFormProps) => { const CodeShow = (props: CodeShowFormProps) => {
/** /**
* 1. height: edit height * 1. height: edit height
* 2. width: edit width * 2. width: edit width
* 3. language: edit language * 3. language: edit language
* 4. options: edit options * 4. options: edit options
* 5. code: content * 5. code: content
* 6. readOnly: is readOnly, value: true | false * 6. readOnly: is readOnly, value: true | false
* 7. lineNumbers: is show lineNumbers, value: on | off | relative | interval * 7. lineNumbers: is show lineNumbers, value: on | off | relative | interval
* 8. theme: edit theme , value: vs-dark | vs | hc-black * 8. theme: edit theme , value: vs-dark | vs | hc-black
* 9. autoWrap: is auto wrap, value: on | off | wordWrapColumn | bounded * 9. autoWrap: is auto wrap, value: on | off | wordWrapColumn | bounded
*/ */
const { const {
height = '30vh', // if null or undefined, set default value height = '30vh', // if null or undefined, set default value
width = '100%', // if null or undefined, set default value width = '100%', // if null or undefined, set default value
language, language,
options = { options = {
...MonacoEditorOptions // set default options ...MonacoEditorOptions // set default options
}, },
code, // content code, // content
lineNumbers, // show lineNumbers lineNumbers, // show lineNumbers
autoWrap = 'on', // auto wrap autoWrap = 'on', // auto wrap
showFloatButton = false, showFloatButton = false,
refreshLogCallback, refreshLogCallback,
fullScreenBtn = false fullScreenBtn = false
} = props; } = props;
const {ScrollType} = editor; const { ScrollType } = editor;
const [scrollBeyondLastLine] = useState<boolean>(options.scrollBeyondLastLine); const [scrollBeyondLastLine] = useState<boolean>(options.scrollBeyondLastLine);
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
const [stopping, setStopping] = useState<boolean>(false); const [stopping, setStopping] = useState<boolean>(false);
const [autoRefresh, setAutoRefresh] = useState<boolean>(false); const [autoRefresh, setAutoRefresh] = useState<boolean>(false);
const [fullScreen, setFullScreen] = useState<boolean>(false); const [fullScreen, setFullScreen] = useState<boolean>(false);
const [editorRef, setEditorRef] = useState<any>(); const [editorRef, setEditorRef] = useState<any>();
const [timer, setTimer] = useState<NodeJS.Timer>(); const [timer, setTimer] = useState<NodeJS.Timer>();
const themeValue = useThemeValue(); const themeValue = useThemeValue();
useEffect(() => {
JavaLog();
}, [])
// // register TypeScript language service, if language is not set default value is typescript! // 使用编辑器钩子, 拿到编辑器实例
// monaco.languages.register({ const monaco = useMonaco();
// id: language || "typescript",
// });
/** useEffect(() => {
* handle sync log convertCodeEditTheme(monaco?.editor);
* @returns {Promise<void>} // 需要调用 手动注册下自定义语言
*/ LogLanguage(monaco);
const handleSyncLog = async () => { }, [monaco]);
setLoading(true);
setInterval(() => {
refreshLogCallback?.();
setLoading(false);
}, 1000);
};
/** /**
* handle stop auto refresh log * handle sync log
*/ * @returns {Promise<void>}
const handleStopAutoRefresh = () => { */
setStopping(true); const handleSyncLog = async () => {
setInterval(() => { setLoading(true);
clearInterval(timer); setInterval(() => {
setStopping(false); refreshLogCallback?.();
setAutoRefresh(false); setLoading(false);
}, 1000); }, 1000);
}; };
/** /**
* handle stop auto refresh log * handle stop auto refresh log
*/ */
const handleStartAutoRefresh = async () => { const handleStopAutoRefresh = () => {
setAutoRefresh(true); setStopping(true);
const timerSync = setInterval(() => { setInterval(() => {
handleSyncLog(); clearInterval(timer);
}, 5000); setStopping(false);
setTimer(timerSync); setAutoRefresh(false);
}; }, 1000);
};
/** /**
* handle scroll to top * handle stop auto refresh log
*/ */
const handleBackTop = () => { const handleStartAutoRefresh = async () => {
editorRef.revealLine(1); setAutoRefresh(true);
}; const timerSync = setInterval(() => {
handleSyncLog();
}, 5000);
setTimer(timerSync);
};
/** /**
* handle scroll to bottom * handle scroll to top
*/ */
const handleBackBottom = () => { const handleBackTop = () => {
editorRef.revealLine(editorRef.getModel().getLineCount()); editorRef.revealLine(1);
}; };
/** /**
* handle scroll to down * handle scroll to bottom
*/ */
const handleDownScroll = () => { const handleBackBottom = () => {
editorRef.setScrollPosition({scrollTop: editorRef.getScrollTop() + 500}, ScrollType.Smooth); editorRef.revealLine(editorRef.getModel().getLineCount());
}; };
/** /**
* handle scroll to up * handle scroll to down
*/ */
const handleUpScroll = () => { const handleDownScroll = () => {
editorRef?.setScrollPosition({scrollTop: editorRef.getScrollTop() - 500}, ScrollType.Smooth); editorRef.setScrollPosition({ scrollTop: editorRef.getScrollTop() + 500 }, ScrollType.Smooth);
}; };
/** /**
* editorDidMount * handle scroll to up
* @param {editor.IStandaloneCodeEditor} editor */
*/ const handleUpScroll = () => {
const editorDidMount = (editor: editor.IStandaloneCodeEditor) => { editorRef?.setScrollPosition({ scrollTop: editorRef.getScrollTop() - 500 }, ScrollType.Smooth);
setEditorRef(editor); };
editor.layout();
editor.focus(); /**
if (scrollBeyondLastLine) { * editorDidMount
editor.onDidChangeModelContent(() => { * @param {editor.IStandaloneCodeEditor} editor
const lineCount = editor.getModel()?.getLineCount() as number; */
if (lineCount > 20) { const editorDidMount = (editor: editor.IStandaloneCodeEditor) => {
editor.revealLine(lineCount); setEditorRef(editor);
} else { editor.layout();
editor.revealLine(1); editor.focus();
} if (scrollBeyondLastLine) {
}); editor.onDidChangeModelContent(() => {
const lineCount = editor.getModel()?.getLineCount() as number;
if (lineCount > 20) {
editor.revealLine(lineCount);
} else {
editor.revealLine(1);
} }
}; });
}
};
const restEditBtnProps = { const restEditBtnProps = {
refreshLogCallback, refreshLogCallback,
autoRefresh, autoRefresh,
stopping, stopping,
loading, loading,
handleSyncLog, handleSyncLog,
handleStopAutoRefresh, handleStopAutoRefresh,
handleStartAutoRefresh, handleStartAutoRefresh,
handleBackTop, handleBackTop,
handleBackBottom, handleBackBottom,
handleUpScroll, handleUpScroll,
handleDownScroll handleDownScroll
}; };
/** /**
* render * render
*/ */
return ( return (
<div className={'monaco-float'} style={props.style}> <div className={'monaco-float'} style={props.style}>
{/* fullScreen button */} {/* fullScreen button */}
{fullScreenBtn && ( {fullScreenBtn && (
<FullscreenBtn <FullscreenBtn
isFullscreen={fullScreen} isFullscreen={fullScreen}
fullScreenCallBack={() => setFullScreen(!fullScreen)} fullScreenCallBack={() => setFullScreen(!fullScreen)}
/> />
)} )}
{/* editor */} {/* editor */}
<Editor <Editor
width={width} width={width}
height={height} height={height}
value={loading ? 'loading...' : code} value={loading ? 'loading...' : code}
language={language} language={language}
options={{ options={{
...options, ...options,
scrollBeyondLastLine: false, scrollBeyondLastLine: false,
readOnly: true, readOnly: true,
wordWrap: autoWrap, wordWrap: autoWrap,
autoDetectHighContrast: true, autoDetectHighContrast: true,
selectOnLineNumbers: true, selectOnLineNumbers: true,
fixedOverflowWidgets: true, fixedOverflowWidgets: true,
autoClosingDelete: 'always', autoClosingDelete: 'always',
lineNumbers, lineNumbers,
minimap: {enabled: false}, minimap: { enabled: false },
scrollbar: { scrollbar: {
// Subtle shadows to the left & top. Defaults to true. // Subtle shadows to the left & top. Defaults to true.
useShadows: false, useShadows: false,
// Render vertical arrows. Defaults to false. // Render vertical arrows. Defaults to false.
// verticalHasArrows: true, // verticalHasArrows: true,
// Render horizontal arrows. Defaults to false. // Render horizontal arrows. Defaults to false.
// horizontalHasArrows: true, // horizontalHasArrows: true,
// Render vertical scrollbar. // Render vertical scrollbar.
// Accepted values: 'auto', 'visible', 'hidden'. // Accepted values: 'auto', 'visible', 'hidden'.
// Defaults to 'auto' // Defaults to 'auto'
vertical: 'visible', vertical: 'visible',
// Render horizontal scrollbar. // Render horizontal scrollbar.
// Accepted values: 'auto', 'visible', 'hidden'. // Accepted values: 'auto', 'visible', 'hidden'.
// Defaults to 'auto' // Defaults to 'auto'
horizontal: 'visible', horizontal: 'visible',
verticalScrollbarSize: 8, verticalScrollbarSize: 8,
horizontalScrollbarSize: 8, horizontalScrollbarSize: 8,
arrowSize: 30 arrowSize: 30
} }
}} }}
onMount={editorDidMount} onMount={editorDidMount}
theme={convertCodeEditTheme()} theme={convertCodeEditTheme()}
/> />
{/* float button */} {/* float button */}
{showFloatButton && ( {showFloatButton && (
<div <div
style={{ style={{
width: 35, width: 35,
height: height, height: height,
backgroundColor: themeValue.borderColor, backgroundColor: themeValue.borderColor,
paddingBlock: 10 paddingBlock: 10
}} }}
> >
<EditorFloatBtn {...restEditBtnProps} /> <EditorFloatBtn {...restEditBtnProps} />
</div>
)}
</div> </div>
); )}
</div>
);
}; };
export default CodeShow; export default CodeShow;
import {editor} from "monaco-editor";
import {languages} from "monaco-editor";
// todo 自定义语言不生效 // todo 自定义语言不生效
export const JavaLog = () => { export function LogLanguage(monaco: any) {
// Register a new language // Register a new language
languages.register({ id: "java-log" }); monaco?.languages.register({
id: 'javalog',
// Register a tokens provider for the language extensions: ['.log'],
languages.setMonarchTokensProvider("java-log", { aliases: ['javalog', 'Javalog', 'Javalog', 'jl', 'log']
tokenizer: { });
root: [ monaco?.languages.setMonarchTokensProvider('javalog', {
[/\[error.*/, "custom-error"], // todo: 如果需要分段展示不同的颜色 则需要在这里添加规则, 且正则必须是严格模式, 否则会匹配一整行,无法达到预期效果
[/\[notice.*/, "custom-notice"], tokenizer: {
[/.*/, "custom-info"], root: [
[/\[[a-zA-Z 0-9:]+\]/, "custom-date"], // 默认不区分大小写 //
], [/\[(\w*-\d*)+\]/, 'custom-thread'],
}, [/\s+(\w.+):$/, 'custom-class'],
}); [/error/, 'custom-error'],
} [/warring/, 'custom-warning'],
\ No newline at end of file [/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
});
}
...@@ -19,167 +19,172 @@ ...@@ -19,167 +19,172 @@
import CodeShow from '@/components/CustomEditor/CodeShow'; import CodeShow from '@/components/CustomEditor/CodeShow';
import MovableSidebar from '@/components/Sidebar/MovableSidebar'; import MovableSidebar from '@/components/Sidebar/MovableSidebar';
import {SseData} from '@/models/Sse'; import useThemeValue from '@/hooks/useThemeValue';
import {DataStudioTabsItemType, StateType} from '@/pages/DataStudio/model'; import { SseData } from '@/models/Sse';
import {SSE_TOPIC} from '@/pages/DevOps/constants'; import { DataStudioTabsItemType, StateType } from '@/pages/DataStudio/model';
import {API_CONSTANTS} from '@/services/endpoints'; import { SSE_TOPIC } from '@/pages/DevOps/constants';
import {parseMilliSecondStr} from '@/utils/function'; import { API_CONSTANTS } from '@/services/endpoints';
import {connect, useModel, useRequest} from '@@/exports'; import { parseMilliSecondStr } from '@/utils/function';
import {CheckOutlined, CloseCircleFilled, LoadingOutlined} from '@ant-design/icons'; import { connect, useModel, useRequest } from '@@/exports';
import {Empty, Space, Typography} from 'antd'; import { CheckOutlined, CloseCircleFilled, LoadingOutlined } from '@ant-design/icons';
import {DataNode} from 'antd/es/tree'; import { Empty, Space, Typography } from 'antd';
import { DataNode } from 'antd/es/tree';
import DirectoryTree from 'antd/es/tree/DirectoryTree'; import DirectoryTree from 'antd/es/tree/DirectoryTree';
import {Key, useEffect, useState} from 'react'; import { Key, useEffect, useState } from 'react';
import useThemeValue from "@/hooks/useThemeValue";
const {Text} = Typography; const { Text } = Typography;
export type ConsoleProps = { export type ConsoleProps = {
tab: DataStudioTabsItemType; tab: DataStudioTabsItemType;
height: number; height: number;
}; };
export interface ProcessStep extends DataNode { export interface ProcessStep extends DataNode {
status: string; status: string;
type: string; type: string;
startTime: string; startTime: string;
endTime: string; endTime: string;
time: number; time: number;
log: string; log: string;
lastUpdateStep: ProcessStep; lastUpdateStep: ProcessStep;
children: ProcessStep[]; children: ProcessStep[];
} }
const buildExpandKeys = (node: ProcessStep) => { const buildExpandKeys = (node: ProcessStep) => {
const keys: Key[] = []; const keys: Key[] = [];
keys.push(node.key); keys.push(node.key);
if (node.children.length > 0) { if (node.children.length > 0) {
node.children.forEach((item: ProcessStep) => { node.children.forEach((item: ProcessStep) => {
keys.push(...buildExpandKeys(item)); keys.push(...buildExpandKeys(item));
}); });
} }
return keys; return keys;
}; };
const ConsoleContent = (props: ConsoleProps) => { const ConsoleContent = (props: ConsoleProps) => {
const {tab} = props; const { tab } = props;
const [selectNode, setSelectNode] = useState<ProcessStep>(); const [selectNode, setSelectNode] = useState<ProcessStep>();
const [processNode, setProcessNode] = useState<ProcessStep>(); const [processNode, setProcessNode] = useState<ProcessStep>();
const [expandedKeys, setExpandedKeys] = useState<Key[]>([]); const [expandedKeys, setExpandedKeys] = useState<Key[]>([]);
const process = `FlinkSubmit/${tab.params.taskId}`; const process = `FlinkSubmit/${tab.params.taskId}`;
const topic = `${SSE_TOPIC.PROCESS_CONSOLE}/${process}`; const topic = `${SSE_TOPIC.PROCESS_CONSOLE}/${process}`;
const {subscribeTopic} = useModel('Sse', (model: any) => ({ const { subscribeTopic } = useModel('Sse', (model: any) => ({
subscribeTopic: model.subscribeTopic subscribeTopic: model.subscribeTopic
})); }));
const themeValue = useThemeValue(); const themeValue = useThemeValue();
const onUpdate = (data: ProcessStep) => { const onUpdate = (data: ProcessStep) => {
setProcessNode((prevState: any) => { setProcessNode((prevState: any) => {
//如果key不一致代表重新提交了任务,清空旧状态 //如果key不一致代表重新提交了任务,清空旧状态
if (prevState && prevState.key != data.key) { if (prevState && prevState.key != data.key) {
setSelectNode(undefined); setSelectNode(undefined);
} }
return data; return data;
}); });
setSelectNode((prevState: any) => { setSelectNode((prevState: any) => {
if (prevState && prevState.key == data.lastUpdateStep.key) { if (prevState && prevState.key == data.lastUpdateStep.key) {
//更新当前节点 //更新当前节点
return data.lastUpdateStep; return data.lastUpdateStep;
} else if (!prevState || prevState.key == data.key) { } else if (!prevState || prevState.key == data.key) {
//未选择节点状态下选择根节点 //未选择节点状态下选择根节点
return data; return data;
} }
return prevState; return prevState;
}); });
}; };
useRequest( useRequest(
{url: API_CONSTANTS.PROCESS_LOG, params: {processName: process}}, { url: API_CONSTANTS.PROCESS_LOG, params: { processName: process } },
{onSuccess: async (res) => onUpdate(res)} { onSuccess: async (res) => onUpdate(res) }
); );
useEffect(() => subscribeTopic([topic], (data: SseData) => onUpdate(data.data)), []); useEffect(() => subscribeTopic([topic], (data: SseData) => onUpdate(data.data)), []);
const onSelect = (_selectedKeys: Key[], info: { const onSelect = (
node: ProcessStep _selectedKeys: Key[],
}) => setSelectNode(info.node); info: {
node: ProcessStep;
}
) => setSelectNode(info.node);
const renderTitle = (node: any) => { const renderTitle = (node: any) => {
const startDate = new Date(node.startTime); const startDate = new Date(node.startTime);
const endDate = new Date(); const endDate = new Date();
const duration = node.time ? node.time : endDate.getTime() - startDate.getTime(); const duration = node.time ? node.time : endDate.getTime() - startDate.getTime();
return ( return (
<Space size={5}> <Space size={5}>
{node.status == 'RUNNING' && <LoadingOutlined/>} {node.status == 'RUNNING' && <LoadingOutlined />}
{node.status == 'FINISHED' && ( {node.status == 'FINISHED' && (
<CheckOutlined style={{color: 'green', fontWeight: 'bold'}}/> <CheckOutlined style={{ color: 'green', fontWeight: 'bold' }} />
)} )}
{node.status == 'FAILED' && ( {node.status == 'FAILED' && (
<CloseCircleFilled style={{color: 'red', fontWeight: 'bold'}}/> <CloseCircleFilled style={{ color: 'red', fontWeight: 'bold' }} />
)} )}
<Text>{node.title}</Text> <Text>{node.title}</Text>
<Text type={'secondary'} style={{marginLeft: 'auto'}}> <Text type={'secondary'} style={{ marginLeft: 'auto' }}>
{parseMilliSecondStr(duration)} {parseMilliSecondStr(duration)}
</Text> </Text>
</Space> </Space>
); );
}; };
useEffect(() => { useEffect(() => {
if (processNode) { if (processNode) {
setExpandedKeys(buildExpandKeys(processNode)); setExpandedKeys(buildExpandKeys(processNode));
} }
}, [processNode]); }, [processNode]);
const handleExpand = (expandedKeys: Key[]) => { const handleExpand = (expandedKeys: Key[]) => {
setExpandedKeys(expandedKeys); setExpandedKeys(expandedKeys);
}; };
return ( return (
<div style={{overflow: 'hidden'}}> <div style={{ overflow: 'hidden' }}>
<MovableSidebar <MovableSidebar
defaultSize={{ defaultSize={{
width: 300, width: 300,
height: props.height - 53 height: props.height - 53
}} }}
minWidth={20} minWidth={20}
visible={true} visible={true}
enable={{right: true}} enable={{ right: true }}
headerVisible={false} headerVisible={false}
style={{ float: 'left',borderInlineEnd:`1px solid ${themeValue.borderColor}`,paddingInline:10}} style={{
> float: 'left',
{processNode ? ( borderInlineEnd: `1px solid ${themeValue.borderColor}`,
<DirectoryTree paddingInline: 10
className={'treeList'} }}
showIcon={false} >
titleRender={renderTitle} {processNode ? (
onSelect={onSelect} <DirectoryTree
treeData={[processNode]} className={'treeList'}
expandedKeys={expandedKeys} showIcon={false}
onExpand={handleExpand} titleRender={renderTitle}
/> onSelect={onSelect}
) : ( treeData={[processNode]}
<Empty/> expandedKeys={expandedKeys}
)} onExpand={handleExpand}
</MovableSidebar> />
<div style={{display:"inline",width:1500}}> ) : (
<CodeShow <Empty />
code={selectNode?.log ? selectNode.log : ''} )}
height={props.height - 53} </MovableSidebar>
language={'java-log'} <div style={{ display: 'inline', width: 1500 }}>
lineNumbers={"off"} <CodeShow
autoWrap={"off"} code={selectNode?.log ? selectNode.log : ''}
//TODO 按钮显示有问题,先注释 height={props.height - 53}
// showFloatButton language={'javalog'}
/> lineNumbers={'off'}
</div> autoWrap={'off'}
</div> //TODO 按钮显示有问题,先注释
); // showFloatButton
/>
</div>
</div>
);
}; };
export default connect(({Studio}: { export default connect(({ Studio }: { Studio: StateType }) => ({
Studio: StateType height: Studio.bottomContainer.height,
}) => ({ console: Studio.bottomContainerContent.console
height: Studio.bottomContainer.height,
console: Studio.bottomContainerContent.console
}))(ConsoleContent); }))(ConsoleContent);
...@@ -24,8 +24,7 @@ import { ...@@ -24,8 +24,7 @@ import {
} from '@/pages/DataStudio/function'; } from '@/pages/DataStudio/function';
import { isSql } from '@/pages/DataStudio/HeaderContainer/service'; import { isSql } from '@/pages/DataStudio/HeaderContainer/service';
import { StateType } from '@/pages/DataStudio/model'; 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 { API_CONSTANTS } from '@/services/endpoints';
import { transformTableDataToCsv } from '@/utils/function'; import { transformTableDataToCsv } from '@/utils/function';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
...@@ -238,7 +237,7 @@ const Result = (props: any) => { ...@@ -238,7 +237,7 @@ const Result = (props: any) => {
{data.columns ? ( {data.columns ? (
<Table <Table
columns={getColumns(data.columns)} columns={getColumns(data.columns)}
size="small" size='small'
dataSource={data.rowData?.map((item: any, index: number) => { dataSource={data.rowData?.map((item: any, index: number) => {
return { ...item, key: index }; return { ...item, key: index };
})} })}
......
...@@ -24,7 +24,7 @@ import { StateType } from '@/pages/DataStudio/model'; ...@@ -24,7 +24,7 @@ import { StateType } from '@/pages/DataStudio/model';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { ConsoleSqlOutlined } from '@ant-design/icons'; import { ConsoleSqlOutlined } from '@ant-design/icons';
import ProList from '@ant-design/pro-list'; 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 React, { useEffect, useState } from 'react';
import { connect } from 'umi'; import { connect } from 'umi';
...@@ -48,8 +48,8 @@ export type ExplainProps = { ...@@ -48,8 +48,8 @@ export type ExplainProps = {
const Explain: React.FC<ExplainProps> = (props: any) => { const Explain: React.FC<ExplainProps> = (props: any) => {
const [explainData, setExplainData] = useState([]); const [explainData, setExplainData] = useState([]);
const [result, setResult] = useState(<Text>{l('pages.datastudio.explain.validate')}</Text>); const [result, setResult] = useState(<Text>{l('pages.datastudio.explain.validate')}</Text>);
const [showModal,setShowModal] = useState(false); const [showModal, setShowModal] = useState(false);
const [explainInfo,setExplainInfo] = useState(""); const [explainInfo, setExplainInfo] = useState('');
const { const {
tabs: { panes, activeKey } tabs: { panes, activeKey }
} = props; } = props;
...@@ -105,9 +105,9 @@ const Explain: React.FC<ExplainProps> = (props: any) => { ...@@ -105,9 +105,9 @@ const Explain: React.FC<ExplainProps> = (props: any) => {
} }
}); });
}, []); }, []);
const showPlanDrawer = (info:string) => { const showPlanDrawer = (info: string) => {
setShowModal(true); setShowModal(true);
setExplainInfo(info) setExplainInfo(info);
}; };
const renderContent = () => { const renderContent = () => {
return ( return (
...@@ -147,18 +147,28 @@ const Explain: React.FC<ExplainProps> = (props: any) => { ...@@ -147,18 +147,28 @@ const Explain: React.FC<ExplainProps> = (props: any) => {
return ( return (
<> <>
{row.sql ? ( {row.sql ? (
<> <>
<Paragraph ellipsis={{ rows: 2, expandable: true, symbol: 'more' }}> <Paragraph ellipsis={{ rows: 2, expandable: true, symbol: 'more' }}>
{row.sql} {row.sql}
</Paragraph> </Paragraph>
</> </>
) : null} ) : null}
{row.error ? ( {row.error ? (
<Paragraph> <Paragraph>
<CodeShow code={row.error} language='java' height='500px' /> <CodeShow code={row.error} language='java' height='500px' />
</Paragraph> </Paragraph>
) : null} ) : 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) => { ...@@ -207,8 +217,19 @@ const Explain: React.FC<ExplainProps> = (props: any) => {
<blockquote>{result}</blockquote> <blockquote>{result}</blockquote>
</Paragraph> </Paragraph>
{renderContent()} {renderContent()}
<Drawer width={"50%"} title="Show Plan" placement="right" onClose={()=>setShowModal(false)} open={showModal}> <Drawer
<CodeShow style={{alignItems:"inherit"}} code={explainInfo} language='java' height='500px' /> width={'50%'}
title='Show Plan'
placement='right'
onClose={() => setShowModal(false)}
open={showModal}
>
<CodeShow
style={{ alignItems: 'inherit' }}
code={explainInfo}
language='java'
height='500px'
/>
</Drawer> </Drawer>
</> </>
); );
......
...@@ -123,40 +123,48 @@ export function getLocalTheme(): string { ...@@ -123,40 +123,48 @@ export function getLocalTheme(): string {
* get code edit theme by localStorage's theme * get code edit theme by localStorage's theme
* @constructor * @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 base: 'vs', // 指定基础主题 , 可选值: 'vs', 'vs-dark', 'hc-black' , base theme
inherit: true, // 是否继承基础主题配置 , 默认为 true, is to inherit the base theme inherit: true, // 是否继承主题配置
// rules is an array of rules. The array must not be sparse (i.e. do not use holes).
rules: [ rules: [
{ token: 'comment', foreground: '#008800', fontStyle: 'italic' }, // 注意,默认的不做修改 因为上边继承了父主题, 只添加自己定义的 , 否则会覆盖默认的 , 导致编辑器样式不一致
{ token: 'keyword', foreground: '#064cff', fontStyle: 'bold' }, { token: 'custom-info', foreground: '#808080' },
{ token: 'string', foreground: '#507dee' }, { token: 'custom-thread', foreground: '#07f313' },
{ token: 'delimiter', foreground: '#041d81' }, { token: 'custom-class', foreground: '#1060d9' },
{ { token: 'custom-error', foreground: '#ff0000', fontStyle: 'bold' },
token: 'readonly', { token: 'custom-warning', foreground: '#FFA500', fontStyle: 'bold' },
foreground: '#e73a6e', { token: 'custom-date', foreground: '#008800' },
background: '#141414', { token: 'custom-process', foreground: '#07f313' }
fontStyle: 'italic'
},
{ token: 'number', foreground: '#ffffff' }
], ],
// colors is an object of color identifiers and their color values. colors: {},
colors: { encodedTokensColors: []
// '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 * 定义暗色 覆盖vs-dark主题,增加扩展规则
// 'editorIndentGuide.background': '#ffffff', // editor indent guide color */
// 'editor.foreground': '#ffffff', // editor selection highlight border color editorInstance.defineTheme(CODE_EDIT_THEME.DARK, {
// 'editor.selectionBackground': '#4ba1ef', // editor selection highlight color base: 'vs-dark', // 指定基础主题 , 可选值: 'vs', 'vs-dark', 'hc-black' , base theme
// 'editor.selectionHighlightBorder': '#4ba1ef', // editor selection highlight border color inherit: true, // 是否继承主题配置
// 'editor.findMatchBackground': '#4ba1ef', // editor find match highlight color rules: [
// 'editor.wordHighlightBackground': '#8bb2d2' // editor word highlight color // 注意,默认的不做修改 因为上边继承了父主题, 只添加自己定义的 , 否则会覆盖默认的 , 导致编辑器样式不一致
} { 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(); const theme = getLocalTheme();
...@@ -164,9 +172,9 @@ export function convertCodeEditTheme() { ...@@ -164,9 +172,9 @@ export function convertCodeEditTheme() {
case THEME.dark: case THEME.dark:
return CODE_EDIT_THEME.DARK; return CODE_EDIT_THEME.DARK;
case THEME.light: case THEME.light:
return CODE_EDIT_THEME.VS_CUSTOME; return CODE_EDIT_THEME.VS;
default: 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