Skip to content

Commit

Permalink
Optimize datastudio (DataLinkDC#2387)
Browse files Browse the repository at this point in the history
* save job when submit

* disable edit when task online

* optimize job edit

* optimize job diff modal

* merge dev
  • Loading branch information
gaoyan1998 authored Oct 14, 2023
1 parent 5bd9efc commit 3cbe7ed
Show file tree
Hide file tree
Showing 14 changed files with 419 additions and 180 deletions.
20 changes: 20 additions & 0 deletions dinky-web/src/locales/en-US/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ export default {
'pages.datastudio.editor.stop.job': 'Stop job',
'pages.datastudio.editor.stop.jobConfirm': 'Are you sure to stop the job [{jobName}]? ',
'pages.datastudio.editor.submitting': 'The new task [{jobName}] is executing',
'pages.datastudio.editor.onlyread':
'Task has been published, modification is prohibited, please go offline first',
'pages.datastudio.editor.notsave': 'Current changes are not saved! ',
'pages.datastudio.editor.notsave.note':
'Continue will discard the changes, are you sure to continue?',
'pages.datastudio.to.jobDetail': 'Operation Center',
'pages.datastudio.explain.validate': 'Validating...',
'pages.datastudio.explain.validate.allright': 'All Right',
Expand All @@ -323,6 +328,21 @@ export default {
'pages.datastudio.footer.codeType': 'Code Type',
'pages.datastudio.footer.lineSeparator': 'Line Separator',
'pages.datastudio.footer.memDetails': 'Maximum heap size',

'pages.datastudio.sql.sqlChanged': 'Code recovery',
'pages.datastudio.sql.sqlChangedPrompt':
'The code you modified is not saved, it is inconsistent with the server, we cached the last modification for you, please select the version',
'pages.datastudio.sql.sqldiff.title': 'Code comparison',
'pages.datastudio.sql.paramdiff.title': 'Configuration comparison',
'pages.datastudio.sql.nochange': 'No change in job content',
'pages.datastudio.sql.useCache': 'Use cached version',
'pages.datastudio.sql.useServer': 'Use server version',
'pages.datastudio.sql.cacheVersion': 'Local cache code',
'pages.datastudio.sql.serverVersion': 'server-side code',
'pages.datastudio.sql.configItem': 'Configuration Item',
'pages.datastudio.sql.cacheConfigItem': 'Local cache configuration',
'pages.datastudio.sql.serverConfigItem': 'server-side configuration',

'pages.datastudio.help.sqlChanged': 'Sql context or configure changed',
'pages.datastudio.help.sqlChangedPrompt':
'the remote context is not the same as the current page , will the data be flushed?',
Expand Down
20 changes: 18 additions & 2 deletions dinky-web/src/locales/zh-CN/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ export default {
'pages.datastudio.editor.stop.job': '停止作业',
'pages.datastudio.editor.stop.jobConfirm': '确定停止作业【{jobName}】吗?',
'pages.datastudio.editor.submitting': '新任务【{jobName}】正在执行',
'pages.datastudio.editor.onlyread': '任务已发布,禁止修改,请先下线任务',
'pages.datastudio.editor.notsave': '当前修改内容未保存!',
'pages.datastudio.editor.notsave.note': '继续将抛弃所修改内容,确定继续吗?',
'pages.datastudio.to.jobDetail': '运维',
'pages.datastudio.explain.validate': '正在校验中...',
'pages.datastudio.explain.validate.allright': '全部正确',
Expand All @@ -316,8 +319,21 @@ export default {
'pages.datastudio.footer.codeType': '代码类型:',
'pages.datastudio.footer.lineSeparator': '行分隔符:',
'pages.datastudio.footer.memDetails': '最大堆大小:{max}\n已使用: {used}M',
'pages.datastudio.help.sqlChanged': 'Sql内容或配置变更',
'pages.datastudio.help.sqlChangedPrompt': '检测到当前页与远端不一致,是否刷新更新数据?',

'pages.datastudio.sql.sqlChanged': '代码恢复',
'pages.datastudio.sql.sqlChangedPrompt':
'您修改的代码未保存,与服务端不一致,我们为您缓存了上次修改,请选择版本',
'pages.datastudio.sql.sqldiff.title': '代码对比',
'pages.datastudio.sql.paramdiff.title': '配置对比',
'pages.datastudio.sql.nochange': '作业内容无变化',
'pages.datastudio.sql.useCache': '使用缓存版本',
'pages.datastudio.sql.useServer': '使用服务器版本',
'pages.datastudio.sql.cacheVersion': '本地缓存代码',
'pages.datastudio.sql.serverVersion': '服务端代码',
'pages.datastudio.sql.configItem': '配置项',
'pages.datastudio.sql.cacheConfigItem': '本地缓存配置',
'pages.datastudio.sql.serverConfigItem': '服务端配置',

'pages.datastudio.label.execConfig': '执行配置',
'pages.datastudio.label.execConfig.autostop': '自动停止',
'pages.datastudio.label.execConfig.autostop.tip':
Expand Down
47 changes: 27 additions & 20 deletions dinky-web/src/pages/DataStudio/HeaderContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
DataStudioTabsItemType,
MetadataTabsItemType,
StateType,
TabsPageSubType,
TabsPageType,
TaskDataType,
VIEW
Expand Down Expand Up @@ -126,8 +127,10 @@ const HeaderContainer = (props: any) => {
}, [dsConfig]);

const handleSave = async () => {
await handlePutDataJson('/api/task', currentData);
const saved = await handlePutDataJson('/api/task', currentData);
saveTabs({ ...props.tabs });
if (currentTab) currentTab.isModified = false;
return saved;
};

const handlerStop = () => {
Expand All @@ -151,23 +154,24 @@ const HeaderContainer = (props: any) => {

const handlerSubmit = async () => {
if (!currentData) return;
const saved = currentData.step == JOB_LIFE_CYCLE.ONLINE ? true : await handleSave();
if (saved) {
const res = await executeSql(
l('pages.datastudio.editor.submitting', '', { jobName: currentData.name }),
currentData.id
);
if (!res) return;

const res = await executeSql(
l('pages.datastudio.editor.submitting', '', { jobName: currentData.name }),
currentData.id
);
if (!res) return;

updateJobRunningMsg({
taskId: currentData.id,
jobName: currentData.name,
jobState: res.datas.status,
runningLog: res.msg
});

messageApi.success(l('pages.datastudio.editor.exec.success'));
currentData.status = JOB_STATUS.RUNNING;
saveTabs({ ...props.tabs });
updateJobRunningMsg({
taskId: currentData.id,
jobName: currentData.name,
jobState: res.datas.status,
runningLog: res.msg
});
messageApi.success(l('pages.datastudio.editor.exec.success'));
currentData.status = JOB_STATUS.RUNNING;
saveTabs({ ...props.tabs });
}
};

const handleChangeJobLife = async () => {
Expand All @@ -176,8 +180,11 @@ const HeaderContainer = (props: any) => {
await offLinelTask(currentData.id);
currentData.step = JOB_LIFE_CYCLE.DEVELOP;
} else {
await onLineTask(currentData.id);
currentData.step = JOB_LIFE_CYCLE.ONLINE;
const saved = await handleSave();
if (saved) {
await onLineTask(currentData.id);
currentData.step = JOB_LIFE_CYCLE.ONLINE;
}
}
saveTabs({ ...props.tabs });
};
Expand Down Expand Up @@ -253,7 +260,7 @@ const HeaderContainer = (props: any) => {
isShow:
currentTab?.type == TabsPageType.project &&
currentData?.jobInstanceId &&
currentTab.subType == 'flinksql',
currentTab.subType == TabsPageSubType.flinkSql,
props: {
href: `/#/devops/job-detail?id=${currentData?.jobInstanceId}`,
target: '_blank'
Expand Down
34 changes: 15 additions & 19 deletions dinky-web/src/pages/DataStudio/LeftContainer/Project/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import FolderModal from '@/pages/DataStudio/LeftContainer/Project/FolderModal';
import JobModal from '@/pages/DataStudio/LeftContainer/Project/JobModal';
import JobTree from '@/pages/DataStudio/LeftContainer/Project/JobTree';
import { getTaskDetails } from '@/pages/DataStudio/LeftContainer/Project/service';
import { StateType, STUDIO_MODEL, STUDIO_MODEL_ASYNC } from '@/pages/DataStudio/model';
import {
handleAddOrUpdate,
Expand Down Expand Up @@ -108,24 +107,21 @@ const Project: React.FC = (props: connect) => {
return;
}

getTaskDetails(taskId).then((res) => {
path.pop();
dispatch({
type: STUDIO_MODEL.addTab,
payload: {
icon: type,
id: parentId + name,
treeKey: key,
breadcrumbLabel: path.join('/'),
label: name,
params: {
taskId: taskId,
taskData: { ...res, useResult: true, maxRowNum: 100 }
},
type: 'project',
subType: type.toLowerCase()
}
});
path.pop();
dispatch({
type: STUDIO_MODEL.addTab,
payload: {
icon: type,
id: parentId + name,
treeKey: key,
breadcrumbLabel: path.join('/'),
label: name,
params: {
taskId: taskId
},
type: 'project',
subType: type
}
});
};

Expand Down
127 changes: 127 additions & 0 deletions dinky-web/src/pages/DataStudio/MiddleContainer/Editor/DiffModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import {
DIFF_EDITOR_PARAMS,
PARAM_DIFF_TABLE_COL
} from '@/pages/DataStudio/MiddleContainer/Editor/constants';
import { l } from '@/utils/intl';
import { DiffEditor } from '@monaco-editor/react';
import { Col, Modal, Row, Space, Table, Tabs, Typography } from 'antd';
import React from 'react';
import styles from './index.less';

const { Text, Link } = Typography;

export type DiffModalProps = {
diffs: any[];
open: boolean;
fileName?: string;
onUse: (server: boolean) => void;
};

const DiffModal: React.FC<DiffModalProps> = (props) => {
const { diffs, open, fileName, onUse } = props;
// Find the diff object with key 'statement'
const statementDiff = diffs.find((diff) => diff.key === 'statement');
// Filter out the diff objects with key other than 'statement'
const paramDiff = diffs.filter((diff) => diff.key != 'statement');

// Render the statement diff section
const renderStatementDiff = () => {
return (
<>
{statementDiff ? (
<div className={styles.diff_content}>
<Row style={{ marginBottom: '5px' }}>
<Col span={12}>
<Text type={'secondary'}>{l('pages.datastudio.sql.serverVersion')}</Text>
</Col>
<Col span={12}>
<Text type={'secondary'}>{l('pages.datastudio.sql.cacheVersion')}</Text>
</Col>
</Row>
<DiffEditor
{...DIFF_EDITOR_PARAMS}
original={statementDiff?.server}
modified={statementDiff?.cache}
/>
</div>
) : (
<Text className={styles.no_diff_content} type={'success'}>
{l('pages.datastudio.sql.nochange')}
</Text>
)}
</>
);
};

// Render the parameter diff section
const renderParamDiff = () => {
return (
<div className={styles.diff_content}>
{paramDiff.length > 0 ? (
<Table size={'small'} dataSource={paramDiff} columns={PARAM_DIFF_TABLE_COL} />
) : (
<Text className={styles.no_diff_content} type={'success'}>
{l('pages.datastudio.sql.nochange')}
</Text>
)}
</div>
);
};

return (
<Modal
title={
<div className={styles.header}>
{l('pages.datastudio.sql.sqlChanged')}-{fileName}
</div>
}
open={open}
footer={null}
width={'60%'}
>
<div style={{ margin: '10px 0' }}>
<Text>{l('pages.datastudio.sql.sqlChangedPrompt')}</Text>
</div>
<Tabs
tabBarExtraContent={
<Space>
<Link onClick={() => onUse(false)}>{l('pages.datastudio.sql.useCache')}</Link>
<Link onClick={() => onUse(true)}>{l('pages.datastudio.sql.useServer')}</Link>
</Space>
}
items={[
{
key: '1',
label: l('pages.datastudio.sql.sqldiff.title'),
children: renderStatementDiff()
},
{
key: '2',
label: l('pages.datastudio.sql.paramdiff.title'),
children: renderParamDiff()
}
]}
/>
</Modal>
);
};
export default DiffModal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { l } from '@/utils/intl';

export const PARAM_DIFF_TABLE_COL = [
{ title: l('pages.datastudio.sql.configItem'), key: 'key', dataIndex: 'key' },
{ title: l('pages.datastudio.sql.cacheConfigItem'), key: 'cache', dataIndex: 'cache' },
{ title: l('pages.datastudio.sql.serverConfigItem'), key: 'server', dataIndex: 'server' }
];

export const DIFF_EDITOR_PARAMS = {
width: '100%',
height: '90%',
options: {
readOnly: true,
selectOnLineNumbers: true,
lineDecorationsWidth: 20,
mouseWheelZoom: true,
automaticLayout: true
},
language: 'sql',
theme: 'vs-dark'
};

export const TASK_VAR_FILTER = [
'updateTime',
'createTime',
'jobInstanceId',
'useResult',
'maxRowNum',
'useChangeLog',
'useAutoCancel',
'status',
'step',
'jobConfig'
];
Loading

0 comments on commit 3cbe7ed

Please sign in to comment.