Unverified Commit 5bd9efcc authored by Licho's avatar Licho Committed by GitHub

Refactor: some code (#2383)

* refactor: front web Signed-off-by: 's avatarlicho <lecho.sun@gmail.com> * feat: default flink sql type ane others refactor * refactor: equalsIgnoreCase * Spotless Apply --------- Signed-off-by: 's avatarlicho <lecho.sun@gmail.com> Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent 38e8932a
......@@ -58,7 +58,7 @@ public class CreateTemporalTableFunctionOperation extends AbstractOperation impl
.from(temporalTable.getTableName())
.createTemporalTableFunction(timeColumn, targetColumn);
if (temporalTable.getFunctionType().toUpperCase().equals("TEMPORARY SYSTEM")) {
if (temporalTable.getFunctionType().equalsIgnoreCase("TEMPORARY SYSTEM")) {
customTableEnvironmentImpl.createTemporarySystemFunction(temporalTable.getFunctionName(), ttf);
} else {
customTableEnvironmentImpl.createTemporaryFunction(temporalTable.getFunctionName(), ttf);
......
import React, {useState} from "react";
import {Button} from "antd";
import {ButtonProps} from "antd/es/button/button";
import { Button } from 'antd';
import { ButtonProps } from 'antd/es/button/button';
import React, { useState } from 'react';
export const LoadingBtn: React.FC<ButtonProps> = (props) => {
const [loading, setLoading] = useState(false);
const handleClick = async (event: React.MouseEvent<HTMLElement, MouseEvent>) => {
if (props.onClick) {
setLoading(true)
await props.onClick(event)
setLoading(false)
setLoading(true);
await props.onClick(event);
setLoading(false);
}
}
};
return (
<Button
{...props}
loading={loading}
onClick={(event) =>handleClick(event)}
></Button>
);
return <Button {...props} loading={loading} onClick={(event) => handleClick(event)}></Button>;
};
......@@ -69,37 +69,44 @@ export const buildDag = (job: Jobs.JobPlan) => {
export const updateDag = (job: Jobs.JobVertices[], graph?: Graph) => {
if (!job || !graph) return;
if (job && graph) {
job.forEach((vertice) => {
const node = graph.getCellById(vertice.id);
if (node) {
node.setData({ ...node.getData(), ...vertice });
}
});
job.forEach((vertices) => {
const node = graph.getCellById(vertices.id);
if (node) {
node.setData({ ...node.getData(), ...vertices });
}
});
graph.getEdges().forEach((edge) => {
const nodeData = edge.getSourceNode()?.getData();
if (nodeData.status == JOB_STATUS.RUNNING) {
edge.attr({ line: { stroke: '#3471F9' } });
edge.attr('line/strokeDasharray', 5);
edge.attr('line/strokeWidth', 2);
edge.attr('line/style/animation', 'running-line 30s infinite linear');
} else {
edge.attr('line/strokeDasharray', 0);
edge.attr('line/style/animation', '');
edge.attr('line/strokeWidth', 1);
if (nodeData.status == JOB_STATUS.FINISHED) {
edge.attr('line/stroke', '#52c41a');
} else if (nodeData.status == JOB_STATUS.CANCELED) {
edge.attr('line/stroke', '#ffe7ba');
} else if (nodeData.status == JOB_STATUS.FAILED) {
edge.attr('line/stroke', '#ff4d4f');
} else {
edge.attr('line/stroke', '#bfbfbf');
}
graph.getEdges().forEach((edge) => {
const nodeData = edge.getSourceNode()?.getData();
let stroke = '#bfbfbf';
let strokeDasharray = 0;
let strokeWidth = 1;
let animation = '';
switch (nodeData.status) {
case JOB_STATUS.RUNNING: {
stroke = '#3471F9';
strokeDasharray = 5;
strokeWidth = 2;
animation = 'running-line 30s infinite linear';
break;
}
});
}
case JOB_STATUS.FINISHED:
stroke = '#52c41a';
break;
case JOB_STATUS.CANCELED:
stroke = '#ffe7ba';
break;
case JOB_STATUS.FAILED:
stroke = '#ff4d4f';
break;
}
edge.attr({ line: { strokeDasharray: strokeDasharray } });
edge.attr({ line: { strokeWidth: strokeWidth } });
edge.attr({ line: { animation: animation } });
edge.attr({ line: { stroke: stroke } });
});
};
export const regConnect = (sourcePoint: any, targetPoint: any) => {
......
......@@ -46,6 +46,87 @@ export type DagProps = {
};
const { Paragraph } = Typography;
const RenderCheckpoint = (id: string, checkPoints: any) => {
const [selectPath, setSelectPath] = useState<string>('');
const key = id + selectPath;
const [itemChildren, setItemChildren] = useState({ [key]: [] as TabsProps['items'] });
const checkpointArray = ((checkPoints.history ?? []) as any[])
.filter((x) => x.status === 'COMPLETED')
.map((x) => {
return { checkpointType: x.checkpoint_type, path: x.external_path, id: x.id };
});
useEffect(() => {
if (!(selectPath && id)) {
return;
}
if (itemChildren[key]) {
return;
}
getData(API_CONSTANTS.READ_CHECKPOINT, { path: selectPath, operatorId: id }).then((res) => {
const genData = Object.keys(res.datas).map((x) => {
const datum = res.datas[x];
return {
key: x,
label: x,
children: (
<Tabs
items={Object.keys(datum).map((y) => {
return {
key: y,
label: y,
children: (
<Table
dataSource={datum[y].datas}
columns={(datum[y].headers as string[]).map((z) => {
return {
title: z,
dataIndex: z,
key: z,
render: (text) => (
<Paragraph copyable ellipsis={{ rows: 3 }}>
{text}
</Paragraph>
)
};
})}
/>
)
};
})}
tabBarStyle={{ marginBlock: 0 }}
tabBarGutter={10}
/>
)
};
});
setItemChildren({ ...itemChildren, [key]: genData });
});
}, [selectPath, id]);
return (
<>
<Select
defaultValue={selectPath}
style={{ width: '100%' }}
placeholder='Select a person'
optionFilterProp='children'
options={checkpointArray.map((x) => {
return { label: x.id, value: x.path };
})}
onChange={(path) => {
setSelectPath(path);
}}
/>
<Tabs items={itemChildren[key]} tabBarStyle={{ marginBlock: 0 }} tabBarGutter={10} />
</>
);
};
const FlinkDag = (props: DagProps) => {
const container = useRef(null);
......@@ -69,19 +150,21 @@ const FlinkDag = (props: DagProps) => {
const initListen = (graph: Graph) => {
graph.on('node:selected', ({ cell }) => {
if (!onlyPlan) {
setOpen(true);
setZoom((oldValue) => {
originPosition = { zoom: oldValue };
return 1;
});
graph.zoomTo(1);
setCurrentSelect(cell);
graph.positionPoint(Rectangle.create(cell.getBBox()).getLeftMiddle(), '10%', '50%');
if (onlyPlan) {
return;
}
setOpen(true);
setZoom((oldValue) => {
originPosition = { zoom: oldValue };
return 1;
});
graph.zoomTo(1);
setCurrentSelect(cell);
graph.positionPoint(Rectangle.create(cell.getBBox()).getLeftMiddle(), '10%', '50%');
});
graph.on('node:unselected', ({ cell }) => {
graph.on('node:unselected', () => {
setZoom(originPosition.zoom);
handleClose();
});
......@@ -150,82 +233,6 @@ const FlinkDag = (props: DagProps) => {
graph?.zoomTo(zoom);
}, [zoom]);
const renderCheckpoint = (id: string) => {
const [selectPath, setSelectPath] = useState<string>('');
const key = id + selectPath;
const [itemChildren, setItemChildren] = useState({ [key]: [] as TabsProps['items'] });
const checkpointArray = ((checkPoints.history ?? []) as any[])
.filter((x) => x.status === 'COMPLETED')
.map((x) => {
return { checkpointType: x.checkpoint_type, path: x.external_path, id: x.id };
});
useEffect(() => {
if (selectPath && id) {
if (!itemChildren[key]) {
getData(API_CONSTANTS.READ_CHECKPOINT, { path: selectPath, operatorId: id }).then(
(res) => {
const genData = Object.keys(res.datas).map((x) => {
const datum = res.datas[x];
return {
key: x,
label: x,
children: (
<Tabs
items={Object.keys(datum).map((y) => {
return {
key: y,
label: y,
children: (
<Table
dataSource={datum[y].datas}
columns={(datum[y].headers as string[]).map((z) => {
return {
title: z,
dataIndex: z,
key: z,
render: (text) => (
<Paragraph copyable ellipsis={{ rows: 3 }}>
{text}
</Paragraph>
)
};
})}
/>
)
};
})}
tabBarStyle={{ marginBlock: 0 }}
tabBarGutter={10}
/>
)
};
});
setItemChildren({ ...itemChildren, [key]: genData });
}
);
}
}
}, [selectPath, id]);
return (
<>
<Select
defaultValue={selectPath}
style={{ width: '100%' }}
placeholder='Select a person'
optionFilterProp='children'
options={checkpointArray.map((x) => {
return { label: x.id, value: x.path };
})}
onChange={(path) => {
setSelectPath(path);
}}
/>
<Tabs items={itemChildren[key]} tabBarStyle={{ marginBlock: 0 }} tabBarGutter={10} />
</>
);
};
return (
<span>
<div
......@@ -274,7 +281,7 @@ const FlinkDag = (props: DagProps) => {
{
key: '2',
label: 'CheckPointRead',
children: renderCheckpoint(currentSelect?.id)
children: RenderCheckpoint(currentSelect?.id, checkPoints)
}
]}
tabBarGutter={10}
......
......@@ -23,17 +23,14 @@ import { HomeOutlined } from '@ant-design/icons';
/**
* @description: 生成面包屑
* @type {({title: JSX.Element} | {title: string})[]}
*/
export const buildBreadcrumbItems = (breadcrumb: string) => {
const items = [{ title: <HomeOutlined /> }];
// 如果有 activeBreadcrumbTitle, 则切割 activeBreadcrumbTitle, 生成面包屑数组, 并映射
const activeBreadcrumbTitleList = Array.from(breadcrumb.split('/')).map((title) => ({
title: <>{title}</>
}));
items.push(...activeBreadcrumbTitleList);
return items;
return [{ title: <HomeOutlined /> }, ...activeBreadcrumbTitleList];
};
export const projectCommonShow = (type?: TabsPageType) => {
......@@ -41,15 +38,9 @@ export const projectCommonShow = (type?: TabsPageType) => {
};
export const isOnline = (data: TaskDataType | undefined) => {
if (data) {
return JOB_LIFE_CYCLE.ONLINE == data.step;
}
return false;
return data ? JOB_LIFE_CYCLE.ONLINE == data.step : false;
};
export const isRunning = (data: TaskDataType | undefined) => {
if (data) {
return JOB_STATUS.RUNNING == data.status;
}
return false;
return data ? JOB_STATUS.RUNNING == data.status : false;
};
......@@ -56,7 +56,7 @@ import {
FundOutlined,
MergeCellsOutlined,
MoreOutlined,
PauseOutlined, PlayCircleTwoTone,
PauseOutlined,
RotateRightOutlined,
SaveOutlined,
ScheduleOutlined,
......@@ -261,15 +261,15 @@ const HeaderContainer = (props: any) => {
},
{
// 执行按钮
icon: <CaretRightFilled/>,
icon: <CaretRightFilled />,
title: l('pages.datastudio.editor.exec'),
click: handlerSubmit,
hotKey: (e: KeyboardEvent) => e.shiftKey && e.key === 'F10',
hotKeyDesc: 'Shift+F10',
isShow: currentTab?.type == TabsPageType.project && !isRunning(currentData),
props: {
style: {background: "#52c41a"},
type: 'primary',
style: { background: '#52c41a' },
type: 'primary'
}
},
{
......
......@@ -70,7 +70,7 @@ const JobModal: React.FC<JobModalProps> = (props) => {
};
useEffect(() => {
isUDF(jobType) && queryUdfTemplate();
if (isUDF(jobType)) queryUdfTemplate();
}, [jobType, form]);
/**
......@@ -102,7 +102,7 @@ const JobModal: React.FC<JobModalProps> = (props) => {
onSubmit({ ...values, ...formData } as Catalogue);
};
const renderForm = () => {
const RenderForm = () => {
return (
<>
<ProFormSelect
......@@ -110,6 +110,7 @@ const JobModal: React.FC<JobModalProps> = (props) => {
label={l('catalog.type')}
tooltip={l('catalog.type.tip')}
options={JOB_TYPE}
initialValue={JOB_TYPE[0]['options'][0]['value']}
disabled={!!values.id}
placeholder={l('catalog.type.placeholder')}
rules={[{ required: true, message: l('catalog.type.placeholder') }]}
......@@ -163,26 +164,24 @@ const JobModal: React.FC<JobModalProps> = (props) => {
};
return (
<>
<ModalForm<Catalogue>
title={title}
form={form}
width={'30%'}
initialValues={{ ...values }}
open={modalVisible}
layout={'horizontal'}
autoFocusFirstInput
onValuesChange={onValuesChange}
modalProps={{
destroyOnClose: true,
maskClosable: false,
onCancel: handleCancel
}}
onFinish={async (values) => submitForm(values)}
>
{renderForm()}
</ModalForm>
</>
<ModalForm<Catalogue>
title={title}
form={form}
width={'30%'}
initialValues={{ ...values }}
open={modalVisible}
layout={'horizontal'}
autoFocusFirstInput
onValuesChange={onValuesChange}
modalProps={{
destroyOnClose: true,
maskClosable: false,
onCancel: handleCancel
}}
onFinish={async (values) => submitForm(values)}
>
{RenderForm()}
</ModalForm>
);
};
......
......@@ -131,7 +131,7 @@ export const buildProjectTree = (
})
: [];
export const isUDF = (jobType: string) => {
export const isUDF = (jobType: string): boolean => {
return jobType === 'Scala' || jobType === 'Python' || jobType === 'Java';
};
......
......@@ -2,7 +2,6 @@ import { getCurrentData } from '@/pages/DataStudio/function';
import { StateType, STUDIO_MODEL } from '@/pages/DataStudio/model';
import { connect } from '@@/exports';
import { Editor } from '@monaco-editor/react';
import { never } from '@umijs/utils/compiled/zod';
import { editor } from 'monaco-editor';
import React from 'react';
......@@ -69,7 +68,10 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => {
return;
}
typeof v === 'string' ? (current.statement = v) : never;
if (typeof v === 'string') {
current.statement = v;
}
dispatch({
type: STUDIO_MODEL.saveTabs,
payload: { ...props.tabs }
......
......@@ -142,15 +142,14 @@ export function getCurrentTab(
activeKey: string
): DataStudioTabsItemType | MetadataTabsItemType | undefined {
const item = panes.find((item) => item.key === activeKey);
if (item?.type === 'project') {
return item as DataStudioTabsItemType;
switch (item?.type) {
case 'project':
return item as DataStudioTabsItemType;
case 'metadata':
return item as MetadataTabsItemType;
default:
return undefined;
}
if (item?.type === 'metadata') {
return item as MetadataTabsItemType;
}
return undefined;
}
export const getCurrentData = (
......@@ -158,19 +157,15 @@ export const getCurrentData = (
activeKey: string
): TaskDataType | undefined => {
const item = getCurrentTab(panes, activeKey);
if (isDataStudioTabsItemType(item)) {
return item.params.taskData;
}
return undefined;
return isDataStudioTabsItemType(item) ? item.params.taskData : undefined;
};
export const getFooterValue = (panes: any, activeKey: string): Partial<FooterType> => {
const currentTab = getCurrentTab(panes, activeKey);
if (isDataStudioTabsItemType(currentTab)) {
return {
codePosition: [1, 1],
codeType: currentTab.params.taskData.dialect
};
}
return {};
return isDataStudioTabsItemType(currentTab)
? {
codePosition: [1, 1],
codeType: currentTab.params.taskData.dialect
}
: {};
};
......@@ -30,7 +30,7 @@ const MetricsConfigTab = (props: any) => {
const jobId = jobDetail.jobDataDto.job?.jid;
const { data } = useRequest({
url: API_CONSTANTS.GET_JOB_MERTICE_ITEMS,
url: API_CONSTANTS.GET_JOB_METRICS_ITEMS,
params: { address: jobManagerUrl, jobId: jobId, verticeId: vertice.id }
});
......
......@@ -224,7 +224,7 @@ export enum API_CONSTANTS {
GET_JOBMANAGER_THREAD_DUMP = 'api/jobInstance/getJobManagerThreadDump',
GET_TASKMANAGER_LIST = 'api/jobInstance/getTaskManagerList',
GET_TASKMANAGER_LOG = 'api/jobInstance/getTaskManagerLog',
GET_JOB_MERTICE_ITEMS = 'api/jobInstance/getJobMetricsItems',
GET_JOB_METRICS_ITEMS = 'api/jobInstance/getJobMetricsItems',
CANCEL_JOB = '/api/studio/cancel',
// /api/studio/getLineage
STUDIO_GET_LINEAGE = '/api/studio/getLineage',
......
......@@ -18,8 +18,9 @@
*/
import ProTable, {ActionType, ProColumns} from "@ant-design/pro-table";
import {TaskVersion} from "@/pages/DevOps/data";
import type {ActionType, ProColumns} from "@ant-design/pro-table";
import ProTable from "@ant-design/pro-table";
import type {TaskVersion} from "@/pages/DevOps/data";
import {useRef, useState,} from "react";
import {queryData} from "@/components/Common/crud";
import {getIcon} from "@/components/Studio/icon";
......@@ -83,11 +84,9 @@ const VersionList = (props: any) => {
render: (dom, entity) => {
return <>
{getIcon(entity.dialect)}
{
<Tag color="blue">
{entity.dialect}
</Tag>
}
</>;
},
},
......@@ -95,13 +94,11 @@ const VersionList = (props: any) => {
title: l('pages.devops.jobinfo.version.type'),
align: 'center',
render: (dom, entity) => {
return <>
{
return (
<Tag color="blue">
{entity.type}
</Tag>
}
</>;
</Tag>);
},
},
{
......@@ -117,7 +114,6 @@ const VersionList = (props: any) => {
hideInSearch: true,
render: (dom, entity) => {
return <>
{<>
<a onClick={() => {
setRow(entity)
setModalVisible(true);
......@@ -126,11 +122,7 @@ const VersionList = (props: any) => {
<FullscreenOutlined title={l('pages.devops.jobinfo.version.sql.showdetail')}/>
</Tag> {l('pages.devops.jobinfo.version.sql.showdetail')}
</a>
</>
}
</>
;
</>;
},
},
{
......
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