Unverified Commit 7092ea3f authored by yqwoe's avatar yqwoe Committed by GitHub

fix: shortcut key problem; editor theme switching problem; editor full screen;…

fix: shortcut key problem; editor theme switching problem; editor full screen; database field length; (#2436) * feat: use-service hooks * fix: 快捷键问题;编辑器主题切换问题;编辑 器全屏;数据库字段长度; * fix:提交 .mvn * fix:提交 .idea * fix:提交 .gitignore * fix:提交 maven-wrapper.jar * fix:提交 .gitignore
parent 4256a3bd
......@@ -26,7 +26,7 @@ logs.zip
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.idea/*
!.idea/icon.png
!.idea/icon.svg
!.idea/vcs.xml
build
target/*
......
......@@ -1642,7 +1642,7 @@ CREATE TABLE `dinky_metrics` (
`position` int(11) DEFAULT null,
`show_type` varchar(255) DEFAULT null,
`show_size` varchar(255) DEFAULT null,
`title` varchar(255) DEFAULT null,
`title` CLOB DEFAULT null,
`layout_name` varchar(255) DEFAULT null,
`create_time` datetime DEFAULT null,
`update_time` datetime DEFAULT null
......
......@@ -70,6 +70,7 @@
"redux-persist": "^6.0.0",
"remark-gfm": "^4.0.0",
"screenfull": "^6.0.2",
"sql-formatter": "^13.0.1",
"styled-components": "^6.0.8",
"use-sse": "^2.0.1"
},
......
......@@ -31,6 +31,7 @@ import { persistReducer, persistStore } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import { Navigate } from 'umi';
import { default as defaultSettings, default as Settings } from '../config/defaultSettings';
import { FullScreenProvider } from './hooks/useEditor';
import { errorConfig } from './requestErrorConfig';
import { getDataByParamsReturnResult } from './services/BusinessCrud';
import { API } from './services/data';
......@@ -114,6 +115,39 @@ export async function getInitialState(): Promise<{
// ProLayout 支持的api https://procomponents.ant.design/components/layout
export const layout: RunTimeLayoutConfig = ({ initialState }) => {
console.log(initialState);
const fullscreen = initialState?.fullscreen;
const defaultSettings = {
onPageChange: () => {
const { location } = history;
// 如果没有登录,重定向到 login
if (!initialState?.currentUser && location.pathname !== loginPath) {
history.push(loginPath);
}
},
// 自定义 403 页面
unAccessible: <UnAccessible />,
// 增加一个 loading 的状态
childrenRender: (children) => {
return initialState?.loading ? (
<PageLoading />
) : (
<AccessContextProvider currentUser={initialState?.currentUser}>
<FullScreenProvider>{children}</FullScreenProvider>
</AccessContextProvider>
);
}
};
if (fullscreen) {
return {
...initialState?.settings,
siderWidth: 0,
...defaultSettings,
layout: 'side'
};
}
return {
headerTitleRender: () => {
// 重新对 title 的设置进行设置
......@@ -135,25 +169,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
theme === THEME.light || undefined ? 'rgba(0, 0, 0, 0.15)' : 'rgba(255, 255, 255, 0.15)'
},*/
isChildrenLayout: true,
onPageChange: () => {
const { location } = history;
// 如果没有登录,重定向到 login
if (!initialState?.currentUser && location.pathname !== loginPath) {
history.push(loginPath);
}
},
// 自定义 403 页面
unAccessible: <UnAccessible />,
// 增加一个 loading 的状态
childrenRender: (children) => {
return initialState?.loading ? (
<PageLoading />
) : (
<AccessContextProvider currentUser={initialState?.currentUser}>
{children}
</AccessContextProvider>
);
},
...defaultSettings,
...initialState?.settings
};
};
......
......@@ -16,7 +16,7 @@
*
*/
import { TabsItemType } from '@/pages/DataStudio/model';
import { TabsItemType } from '@/pages/DataStudio/types';
import { Button } from 'antd';
import React from 'react';
......
......@@ -141,7 +141,7 @@ const CodeEdit = (props: CodeEditFormProps) => {
className={'editor-develop'}
onMount={editorDidMount}
onChange={onChange}
theme={theme ? theme : convertCodeEditTheme()}
theme={convertCodeEditTheme()}
/>
{showFloatButton && <EditorFloatBtn {...restEditBtnProps} />}
</div>
......
......@@ -242,7 +242,7 @@ const CodeShow = (props: CodeShowFormProps) => {
}
}}
onMount={editorDidMount}
theme={theme ? theme : convertCodeEditTheme()}
theme={convertCodeEditTheme()}
/>
{/* float button */}
......
......@@ -399,6 +399,12 @@ h5 {
scrollbar-width: thin;
}
.editor-full-screen{
.ant-tabs-tabpane{
height: 100vh;
}
}
.data-studio-tabs {
.ant-tabs-nav {
.ant-tabs-nav-wrap {
......
import {
createContext,
Dispatch,
FC,
memo,
SetStateAction,
useContext,
useEffect,
useState
} from 'react';
import { flushSync } from 'react-dom';
import { useModel } from 'umi';
export interface FullScreenContextProps {
fullscreen: boolean;
setFullscreen: Dispatch<SetStateAction<boolean>>;
}
export const FullScreenContext = createContext<FullScreenContextProps>(
{} as FullScreenContextProps
);
export const FullScreenProvider: FC = memo(({ children }) => {
const [fullscreen, setFullscreen] = useState<boolean>(false);
const { initialState, setInitialState } = useModel('@@initialState');
useEffect(() => {
flushSync(() => {
setInitialState((s) => ({
...s,
fullscreen
}));
});
}, [fullscreen]);
return (
<FullScreenContext.Provider value={{ fullscreen, setFullscreen }}>
{children}
</FullScreenContext.Provider>
);
});
export const useEditor = () => useContext(FullScreenContext);
......@@ -20,7 +20,7 @@
import useThemeValue from '@/hooks/useThemeValue';
import JobRunningModal from '@/pages/DataStudio/FooterContainer/JobRunningModal';
import { getCurrentTab } from '@/pages/DataStudio/function';
import { StateType, TabsPageType, VIEW } from '@/pages/DataStudio/model';
import { StateType,TabsPageType,VIEW} from '@/pages/DataStudio/model';
import { getSseData } from '@/services/api';
import { l } from '@/utils/intl';
import { connect } from '@@/exports';
......
......@@ -196,8 +196,8 @@ const HeaderContainer = (props: any) => {
const routes: ButtonRoute[] = [
// 保存按钮 icon
{
hotKey: (e: KeyboardEvent) => e.ctrlKey && e.key === 's',
hotKeyDesc: 'Ctrl+S',
hotKey: (e: KeyboardEvent) => e.ctrlKey && e.key === 's' || e.metaKey && e.key === 's',
hotKeyDesc: 'Ctrl/Command +S',
isShow: projectCommonShow(currentTab?.type),
icon: <SaveOutlined />,
title: l('button.save'),
......@@ -216,6 +216,8 @@ const HeaderContainer = (props: any) => {
{
// 检查 sql按钮
icon: <ScheduleOutlined />,
hotKey: (e: KeyboardEvent) => e.altKey && e.code === 'Digit2' || e.altKey && e.key === '@',
hotKeyDesc: 'Alt+2/@',
title: l('pages.datastudio.editor.check'),
click: () => showExplain(),
isShow: projectCommonShow(currentTab?.type)
......
......@@ -28,12 +28,16 @@ import {
} from '@/pages/DataStudio/model';
import { JOB_LIFE_CYCLE } from '@/pages/DevOps/constants';
import { API_CONSTANTS } from '@/services/endpoints';
import { convertCodeEditTheme } from '@/utils/function';
import { l } from '@/utils/intl';
import { connect, useRequest } from '@@/exports';
import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
import { Editor } from '@monaco-editor/react';
import { Spin } from 'antd';
import { editor } from 'monaco-editor';
import { Button, Spin } from 'antd';
import { editor, KeyCode, KeyMod } from 'monaco-editor';
import React, { useState } from 'react';
import { format } from 'sql-formatter';
import { useEditor } from '@/hooks/useEditor';
export type EditorProps = {
taskId: number;
......@@ -48,6 +52,8 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [diff, setDiff] = useState<any>([]);
const { fullscreen, setFullscreen } = useEditor();
const [editorIns, setEditorIns] = useState<editor.IStandaloneCodeEditor>(null);
const currentTab = getCurrentTab(panes, activeKey) as DataStudioTabsItemType;
const currentData = currentTab.params.taskData;
......@@ -89,62 +95,105 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => {
};
return (
<>
<Spin spinning={loading} delay={600}></Spin>
<DiffModal diffs={diff} open={isModalOpen} fileName={currentData?.name} onUse={upDateTask} />
<Editor
width={'100%'}
height={'100%'}
value={currentTab?.params?.taskData?.statement}
language={'sql'}
options={{
readOnlyMessage: { value: l('pages.datastudio.editor.onlyread') },
readOnly: currentData?.step == JOB_LIFE_CYCLE.ONLINE,
scrollBeyondLastLine: false,
wordWrap: 'on',
autoDetectHighContrast: true,
scrollbar: {
// Subtle shadows to the left & top. Defaults to true.
useShadows: false,
// Defaults to 'auto'
vertical: 'visible',
// Defaults to 'auto'
horizontal: 'visible',
verticalScrollbarSize: 8,
horizontalScrollbarSize: 8,
arrowSize: 30
}
}}
className={'editor-develop'}
onMount={(editor: editor.IStandaloneCodeEditor) => {
editor.layout();
editor.focus();
<Spin spinning={loading} delay={600}>
<div style={{ width: '100%', height: fullscreen ? 'calc(100vh - 50px)' : '33vh' }}>
<DiffModal
diffs={diff}
open={isModalOpen}
fileName={currentData?.name}
onUse={upDateTask}
/>
<Editor
value={currentTab?.params?.taskData?.statement}
language={'sql'}
options={{
readOnlyMessage: { value: l('pages.datastudio.editor.onlyread') },
readOnly: currentData?.step == JOB_LIFE_CYCLE.ONLINE,
scrollBeyondLastLine: false,
wordWrap: 'on',
autoDetectHighContrast: true,
scrollbar: {
// Subtle shadows to the left & top. Defaults to true.
useShadows: false,
// Defaults to 'auto'
vertical: 'visible',
// Defaults to 'auto'
horizontal: 'visible',
verticalScrollbarSize: 8,
horizontalScrollbarSize: 8,
arrowSize: 30
},
automaticLayout: true
}}
className={'editor-develop'}
onMount={(editor: editor.IStandaloneCodeEditor) => {
editor.layout();
editor.focus();
editor.onDidChangeCursorPosition((e) => {
props.footContainer.codePosition = [e.position.lineNumber, e.position.column];
dispatch({
type: STUDIO_MODEL.saveFooterValue,
payload: { ...props.footContainer }
editor.onDidChangeCursorPosition((e) => {
props.footContainer.codePosition = [e.position.lineNumber, e.position.column];
dispatch({
type: STUDIO_MODEL.saveFooterValue,
payload: { ...props.footContainer }
});
});
});
}}
onChange={(v) => {
if (!currentData || !currentTab) {
return;
}
if (typeof v === 'string') {
currentData.statement = v;
}
currentTab.isModified = true;
dispatch({
type: STUDIO_MODEL.saveTabs,
payload: { ...props.tabs }
});
}}
theme={'vs-dark'}
/>
</>
editor.addCommand(KeyMod.Alt | KeyCode.Digit3, () => {
editor?.trigger('anyString', 'editor.action.formatDocument');
editor.setValue(format(editor.getValue()));
});
setEditorIns(editor);
}}
onChange={(v) => {
if (!currentData || !currentTab) {
return;
}
if (typeof v === 'string') {
currentData.statement = v;
}
currentTab.isModified = true;
dispatch({
type: STUDIO_MODEL.saveTabs,
payload: { ...props.tabs }
});
}}
theme={convertCodeEditTheme()}
></Editor>
<div
style={{
position: 'absolute',
top: 0,
right: 150
}}
>
{fullscreen ? (
<Button
type='text'
style={{
color: '#fff'
}}
icon={<FullscreenExitOutlined />}
onClick={() => {
editorIns.layout();
setFullscreen(false);
}}
/>
) : (
<Button
type='text'
style={{
color: '#fff'
}}
icon={<FullscreenOutlined />}
onClick={() => {
editorIns.layout();
setFullscreen(true);
}}
/>
)}
</div>
</div>
</Spin>
);
};
......
......@@ -22,7 +22,7 @@ import { l } from '@/utils/intl';
export const KEY_BOARD_MIDDLE = [
{
key: 'ctrls',
label: 'Ctrl + S',
label: 'Ctrl / Command + S',
description: l('shortcut.key.save')
},
{
......@@ -35,16 +35,16 @@ export const KEY_BOARD_MIDDLE = [
label: 'Alt + 3',
description: l('shortcut.key.beautify')
},
{
key: 'f2',
label: 'F2',
description: l('shortcut.key.fullscreen')
},
{
key: 'esc',
label: 'Esc',
description: l('shortcut.key.fullscreenClose')
}
// {
// key: 'f2',
// label: 'F2',
// description: l('shortcut.key.fullscreen')
// },
// {
// key: 'esc',
// label: 'Esc',
// description: l('shortcut.key.fullscreenClose')
// }
];
export const KEY_BOARD_RIGHT_SLIDER = [
......
......@@ -16,6 +16,7 @@
*/
import ContentScroll from '@/components/Scroll/ContentScroll';
import { useEditor } from '@/hooks/useEditor';
import useThemeValue from '@/hooks/useThemeValue';
import { STUDIO_TAG_RIGHT_CONTEXT_MENU } from '@/pages/DataStudio/constants';
import {
......@@ -50,6 +51,9 @@ const MiddleContainer = (props: any) => {
} = props;
const themeValue = useThemeValue();
const {fullscreen} = useEditor();
const [contextMenuPosition, setContextMenuPosition] = useState({});
const [contextMenuVisible, setContextMenuVisible] = useState(false);
const [includeTab, setIncludeTab] = useState({});
......@@ -248,7 +252,7 @@ const MiddleContainer = (props: any) => {
</Space>
),
children: (
<ContentScroll height={activeKey === item.key ? props.centerContentHeight - 35 : 0}>
<ContentScroll height={activeKey === item.key ? fullscreen ? document.body.clientHeight : props.centerContentHeight - 35 : 0}>
{renderContent()}
</ContentScroll>
)
......
......@@ -16,6 +16,7 @@
*/
import { AuthorizedObject, useAccess } from '@/hooks/useAccess';
import { FullScreenProvider, useEditor } from '@/hooks/useEditor';
import useThemeValue from '@/hooks/useThemeValue';
import BottomContainer from '@/pages/DataStudio/BottomContainer';
import FooterContainer from '@/pages/DataStudio/FooterContainer';
......@@ -68,6 +69,8 @@ const DataStudio = (props: any) => {
const persist = app._store.persist;
const bottomHeight = bottomContainer.selectKey === '' ? 0 : bottomContainer.height;
const { fullscreen } = useEditor();
const getClientSize = () => ({
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
......@@ -197,49 +200,56 @@ const DataStudio = (props: any) => {
);
return (
<PageContainer title={false} breadcrumb={{ style: { display: 'none' } }}>
<PersistGate loading={null} persistor={persist}>
<div style={{ marginInline: -10, marginTop: -6, width: size.width }}>
<SecondHeaderContainer size={size} activeBreadcrumbTitle={activeBreadcrumbTitle} />
<Layout
hasSider
style={{
minHeight: size.contentHeight,
maxHeight: size.contentHeight,
paddingInline: 0
}}
>
<Sider collapsed collapsedWidth={40}>
<div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
{LeftTopMenu}
{LeftBottomMenu}
</div>
</Sider>
<Content style={{ display: 'flex', flexDirection: 'column', minWidth: 0 }}>
<div style={{ display: 'flex' }}>
<LeftContainer size={size} />
<Content
style={{
width:
size.width - 2 * VIEW.sideWidth - leftContainer.width - rightContainer.width
}}
>
<MiddleContainer />
fullscreen ? (
<MiddleContainer />
) : (
<PageContainer title={false} breadcrumb={{ style: { display: 'none' } }}>
<PersistGate loading={null} persistor={persist}>
<div style={{ marginInline: -10, marginTop: -6, width: size.width }}>
<SecondHeaderContainer size={size} activeBreadcrumbTitle={activeBreadcrumbTitle} />
<Layout
hasSider
style={{
minHeight: size.contentHeight,
maxHeight: size.contentHeight,
paddingInline: 0
}}
>
<Sider collapsed collapsedWidth={40}>
<div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
{LeftTopMenu}
{LeftBottomMenu}
</div>
</Sider>
<Content style={{ display: 'flex', flexDirection: 'column', minWidth: 0 }}>
<div style={{ display: 'flex' }}>
<LeftContainer size={size} />
<Content
style={{
width:
size.width -
2 * VIEW.sideWidth -
leftContainer.width -
rightContainer.width
}}
>
<MiddleContainer />
</Content>
<RightContainer size={size} bottomHeight={bottomHeight} />
</div>
{<BottomContainer size={size} />}
</Content>
<RightContainer size={size} bottomHeight={bottomHeight} />
</div>
{<BottomContainer size={size} />}
</Content>
<Sider collapsed collapsedWidth={40}>
{RightTopMenu}
</Sider>
</Layout>
{<FooterContainer token={token} />}
</div>
</PersistGate>
</PageContainer>
<Sider collapsed collapsedWidth={40}>
{RightTopMenu}
</Sider>
</Layout>
{<FooterContainer token={token} />}
</div>
</PersistGate>
</PageContainer>
)
);
};
......
......@@ -32,6 +32,7 @@ import HistoryVersion from '@/pages/DataStudio/RightContainer/HistoryVersion';
import JobConfig from '@/pages/DataStudio/RightContainer/JobConfig';
import JobInfo from '@/pages/DataStudio/RightContainer/JobInfo';
import SavePoints from '@/pages/DataStudio/RightContainer/SavePoints';
import { convertCodeEditTheme } from '@/utils/function';
import { l } from '@/utils/intl';
import {
ApartmentOutlined,
......@@ -210,6 +211,7 @@ export const LeftBottomMoreTabs: { [c: string]: TabProp[] } = {
}
}}
language={'text'}
theme={convertCodeEditTheme()}
/>
)
},
......
......@@ -124,40 +124,41 @@ export function getLocalTheme(): string {
* @constructor
*/
export function convertCodeEditTheme() {
/**
* user can define a new theme by calling the defineTheme method on the editor.
*/
editor.defineTheme(CODE_EDIT_THEME.VS_CUSTOME, {
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).
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' }
],
// colors is an object of color identifiers and their color values.
colors: {
'editor.background': '#5d5b5b', // 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
}
});
/**
* user can define a new theme by calling the defineTheme method on the editor.
*/
editor.defineTheme(CODE_EDIT_THEME.VS_CUSTOME, {
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).
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' }
],
// 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
}
});
const theme = getLocalTheme();
switch (theme) {
......
......@@ -1047,7 +1047,7 @@ CREATE TABLE `dinky_metrics` (
`position` int(11) DEFAULT NULL COMMENT 'position',
`show_type` varchar(255) DEFAULT NULL COMMENT 'show type',
`show_size` varchar(255) DEFAULT NULL COMMENT 'show size',
`title` varchar(255) DEFAULT NULL COMMENT 'title',
`title` longtext DEFAULT NULL COMMENT 'title',
`layout_name` varchar(255) DEFAULT NULL COMMENT 'layout name',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'update time',
......
......@@ -1975,7 +1975,7 @@ CREATE TABLE "public"."dinky_metrics" (
"position" int4,
"show_type" varchar(255) COLLATE "pg_catalog"."default",
"show_size" varchar(255) COLLATE "pg_catalog"."default",
"title" varchar(255) COLLATE "pg_catalog"."default",
"title" text COLLATE "pg_catalog"."default",
"layout_name" varchar(255) COLLATE "pg_catalog"."default",
"create_time" timestamp(6) NOT null,
"update_time" timestamp(6) NOT null,
......@@ -2441,4 +2441,4 @@ INSERT INTO public.dinky_alert_template VALUES (1, 'Default', '
[Go toTask Web](http://${taskUrl})
', 1, null, null);
COMMIT;
\ No newline at end of file
COMMIT;
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