From 8fb9867902c1eab92285a5401b63395fdb689088 Mon Sep 17 00:00:00 2001 From: Bruce Date: Tue, 28 Nov 2023 15:34:26 +0800 Subject: [PATCH] New Console (#674) * New Console (#665) * mod: update fetch space list logic * feat: add schema in console * mod: remove * feat: add editor hightlight * mod: update monaco editor * mod: update drawer * feat: add / history provider * feat: support running select rows * mod: code review --------- Co-authored-by: Nut He <18328704+hetao92@users.noreply.github.com> * feat: monaco-editor worker * fix: rebase * mod: remove npmrc * fix: explain * chore: remove console doc sider --------- Co-authored-by: Nut He <18328704+hetao92@users.noreply.github.com> --- .npmrc | 1 - app/components/CodeMirror/index.less | 37 -- app/components/CodeMirror/index.tsx | 192 ---------- app/components/GQLCodeMirror/index.tsx | 11 +- app/components/MonacoEditor/index.module.less | 32 ++ app/components/MonacoEditor/index.tsx | 354 ++++++++++++++++++ app/config/locale/en-US.ts | 6 + app/config/locale/zh-CN.ts | 6 + app/config/nebulaQL.ts | 130 ++++++- app/pages/Console/Drawer/NgqlDrawer.tsx | 107 ++++++ app/pages/Console/Drawer/SchemaDrawer.tsx | 198 ++++++++++ app/pages/Console/Drawer/index.module.less | 179 +++++++++ app/pages/Console/HistoryBtn.tsx | 24 +- .../OutputBox/ForceGraph/index.module.less | 5 + .../Console/OutputBox/ForceGraph/index.tsx | 42 ++- app/pages/Console/OutputBox/index.module.less | 47 ++- app/pages/Console/OutputBox/index.tsx | 52 ++- app/pages/Console/index.module.less | 185 ++++++++- app/pages/Console/index.tsx | 256 +++++++++---- app/pages/MainPage/index.tsx | 2 +- .../Schema/SchemaConfig/DDLModal/index.tsx | 15 +- app/stores/console.ts | 13 + app/stores/graph.ts | 10 + app/stores/schema.ts | 46 ++- app/stores/twoGraph.ts | 9 +- index.html | 8 + package-lock.json | 88 ++++- package.json | 4 +- tsconfig.json | 1 + 29 files changed, 1636 insertions(+), 424 deletions(-) delete mode 100644 .npmrc delete mode 100644 app/components/CodeMirror/index.less delete mode 100644 app/components/CodeMirror/index.tsx create mode 100644 app/components/MonacoEditor/index.module.less create mode 100644 app/components/MonacoEditor/index.tsx create mode 100644 app/pages/Console/Drawer/NgqlDrawer.tsx create mode 100644 app/pages/Console/Drawer/SchemaDrawer.tsx create mode 100644 app/pages/Console/Drawer/index.module.less diff --git a/.npmrc b/.npmrc deleted file mode 100644 index e7afe103..00000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -registry=https://registry.npm.taobao.org \ No newline at end of file diff --git a/app/components/CodeMirror/index.less b/app/components/CodeMirror/index.less deleted file mode 100644 index 1db08138..00000000 --- a/app/components/CodeMirror/index.less +++ /dev/null @@ -1,37 +0,0 @@ -@import '@app/common.less'; - -.CodeMirror-wrap pre.CodeMirror-line, -.CodeMirror-wrap pre.CodeMirror-line-like { - word-break: break-all !important; -} - -.CodeMirror { - resize: vertical; - overflow: auto !important; - .notes { - color: gray; - .cm-keyword { - color: gray; - } - } - pre, span { - font-family: Roboto-Mono,sans-serif; - } -} - -.CodeMirror { - font-family: Roboto-Mono, sans-serif; - .CodeMirror-gutters { - background: @lightBlue; - } - .CodeMirror-linenumber { - display: flex; - justify-content: center; - color: @darkGray; - } - .CodeMirror-scroll { - padding-bottom: 0; - margin-right: 0; - overflow: auto !important; - } -} \ No newline at end of file diff --git a/app/components/CodeMirror/index.tsx b/app/components/CodeMirror/index.tsx deleted file mode 100644 index 792b482c..00000000 --- a/app/components/CodeMirror/index.tsx +++ /dev/null @@ -1,192 +0,0 @@ -import { PureComponent } from 'react'; -import CodeMirror from 'codemirror'; -import 'codemirror/addon/comment/comment'; -import 'codemirror/addon/display/autorefresh'; -import 'codemirror/addon/edit/matchbrackets'; -import 'codemirror/addon/hint/show-hint'; -import 'codemirror/addon/hint/show-hint.css'; -import 'codemirror/keymap/sublime'; -import 'codemirror/lib/codemirror.css'; -import 'codemirror/mode/meta'; -import 'codemirror/theme/monokai.css'; - -import { ban, keyWords, operators } from '@app/config/nebulaQL'; - -import './index.less'; - -interface IProps { - options?: object; - value: string; - ref?: any; - width?: string; - height?: string; - onShiftEnter?: () => void; - onChange?: (value: string) => void; - onBlur?: (value: string) => void; - onChangeLine?: () => void; -} - -export default class ReactCodeMirror extends PureComponent { - codemirror; - editor; - textarea; - constructor(props) { - super(props); - } - public componentDidMount() { - CodeMirror.defineMode('nebula', () => { - return { - token: stream => { - if (stream.eatSpace()) { - return null; - } - stream.eatWhile(/[\$:\w\u4e00-\u9fa5]/); - const cur = stream.current(); - if (keyWords.some(item => item === cur)) { - return 'keyword'; - } else if (operators.some(item => item === cur)) { - return 'def'; - } else if (ban.some(item => item === cur)) { - return 'error'; - } - stream.next(); - }, - }; - }); - - CodeMirror.registerHelper('hint', 'nebula', cm => { - const cur = cm.getCursor(); - const token = cm.getTokenAt(cur); - const str = token.string; - const start = token.start; - const end = cur.ch; - - if (str === '') { - return; - } - - const list = [...keyWords, ...operators, ...ban].filter(item => { - return item.indexOf(str) === 0; - }); - - if (list.length) { - return { - list, - from: CodeMirror.Pos(cur.line, start), - to: CodeMirror.Pos(cur.line, end), - }; - } - }); - this.renderCodeMirror(); - } - renderCodeMirror() { - // parameters of the combined - const options = { - tabSize: 2, - fontSize: '14px', - autoCloseBrackets: true, - matchBrackets: true, - showCursorWhenSelecting: true, - lineWrapping: true, - // show number of rows - lineNumbers: true, - fullScreen: true, - mode: 'nebula', - ...this.props.options, - }; - this.editor = CodeMirror.fromTextArea(this.textarea, options); - // Getting CodeMirror is used to get some of these constants - this.codemirror = CodeMirror; - // event - this.editor.on('change', this.codemirrorValueChange); - this.editor.on('keydown', this.keydown); - this.editor.on('blur', this.blur); - const { value, width, height } = this.props; - this.editor.setValue(value || ''); - if (width || height) { - // set size - this.editor.setSize(width, height); - } - } - blur = instance => { - if (this.props.onBlur) { - this.props.onBlur(instance.doc.getValue()); - } - }; - - keydown = (_, change) => { - if (change.shiftKey === true && change.keyCode === 13) { - if (this.props.onShiftEnter) { - this.props.onShiftEnter(); - } - change.preventDefault(); - } - }; - - codemirrorValueChange = (doc, change) => { - doc.eachLine(line => { - if(line.text.startsWith('//') || line.text.startsWith('#')) { - doc.addLineClass(line, 'wrap', 'notes'); - } else if (line.wrapClass === 'notes') { - doc.removeLineClass(line, 'wrap', 'notes'); - } - }); - if (change.origin !== 'setValue') { - if (this.props.onChange) { - this.props.onChange(doc.getValue()); - } - } - if (change.origin === '+input') { - CodeMirror.commands.autocomplete(this.editor, null, { - completeSingle: false, - }); - } - if ( - this.props.onChangeLine && - (change.origin === '+delete' || change.origin === '+input') - ) { - this.props.onChangeLine(); - } - }; - - async UNSAFE_componentWillReceiveProps(nextProps) { - const { options, value } = nextProps; - await this.setOptions(options); - if (value !== this.editor.getValue()) { - this.editor.setValue(value || ''); - } - } - - async setOptions(options) { - if (typeof options === 'object') { - const mode = CodeMirror.findModeByName(options.mode); - if (mode && mode.mode) { - await import(/* @vite-ignore */`codemirror/mode/${mode.mode}/${mode.mode}.js`); - } - if (mode) { - options.mode = mode.mime; - } - Object.keys(options).forEach(name => { - if (options[name] && JSON.stringify(options[name])) { - this.editor.setOption(name, options[name]); - } - }); - } - } - - componentWillUnmount() { - if (this.editor) { - this.editor.toTextArea(); - } - } - - render() { - return ( -