Unverified Commit 227b6e9f authored by Licho's avatar Licho Committed by GitHub

fix: Lineage render problem (#2408)

* fix: Lineage render problem * Spotless Apply --------- Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent 4fb43039
import { Badge, Tooltip, Typography } from 'antd'; import { Badge, Tooltip, Typography } from 'antd';
import LineageDagExt from '@/components/LineageGraph/lineage-dag-ext';
import { import {
LineageDetailInfo, LineageDetailInfo,
LineageRelations, LineageRelations,
...@@ -18,11 +19,8 @@ import { ...@@ -18,11 +19,8 @@ import {
} from '@ant-design/icons'; } from '@ant-design/icons';
import _ from 'lodash'; import _ from 'lodash';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import LineageDag from 'react-lineage-dag';
import 'react-lineage-dag/dist/index.css'; import 'react-lineage-dag/dist/index.css';
const { Text } = Typography;
interface LineageState { interface LineageState {
lineageData: LineageDetailInfo; lineageData: LineageDetailInfo;
canvas: any; canvas: any;
...@@ -42,6 +40,20 @@ interface LineageState { ...@@ -42,6 +40,20 @@ interface LineageState {
collapseUpstream: boolean; collapseUpstream: boolean;
} }
type JobLineageProps = {
lineageData: LineageDetailInfo;
refreshCallBack: () => void;
};
type ITable = {
id: string;
name: string;
isCollapse: boolean;
fields: LineageTableColumn[];
};
const { Text } = Typography;
const InitLineageState: LineageState = { const InitLineageState: LineageState = {
lineageData: { lineageData: {
tables: [], tables: [],
...@@ -64,34 +76,10 @@ const InitLineageState: LineageState = { ...@@ -64,34 +76,10 @@ const InitLineageState: LineageState = {
collapseUpstream: false collapseUpstream: false
}; };
type JobLineageProps = {
lineageData: LineageDetailInfo;
refreshCallBack: () => void;
};
type ITable = {
id: string;
name: string;
isCollapse: boolean;
fields: LineageTableColumn[];
};
const LineageGraph: React.FC<JobLineageProps> = (props) => { const LineageGraph: React.FC<JobLineageProps> = (props) => {
const { lineageData, refreshCallBack } = props; const { lineageData, refreshCallBack } = props;
const [lineageState, setLineageState] = React.useState<LineageState>(InitLineageState); const [lineageState, setLineageState] = React.useState<LineageState>(InitLineageState);
useEffect(() => {
if (lineageData) {
setLineageState((prevState) => ({
...prevState,
lineageData: lineageData,
tables: buildLineageTables(lineageData.tables),
relations: buildLineageRelations(lineageData.relations)
}));
}
}, [lineageData, lineageState.refresh]);
const buildLineageColumns = (data: LineageDetailInfo) => { const buildLineageColumns = (data: LineageDetailInfo) => {
return [ return [
{ {
...@@ -99,13 +87,11 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => { ...@@ -99,13 +87,11 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => {
width: '100', width: '100',
render: (text: any, record: any, index: number) => { render: (text: any, record: any, index: number) => {
return ( return (
<> <Badge
<Badge count={index + 1}
count={index + 1} size={'small'}
size={'small'} color={index < 10 ? 'red' : index < 20 ? 'blue' : index < 30 ? 'gold' : 'cyan'}
color={index < 10 ? 'red' : index < 20 ? 'blue' : index < 30 ? 'gold' : 'cyan'} />
/>
</>
); );
} }
}, },
...@@ -143,26 +129,19 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => { ...@@ -143,26 +129,19 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => {
})); }));
}; };
function findTableById(id: string) {
const { tables } = lineageState;
return tables.find((item) => {
return String(item.id) === String(id);
});
}
const handleExpandField = (nodeData: any, tables: ITable[]) => { const handleExpandField = (nodeData: any, tables: ITable[]) => {
const { isCollapse, id } = nodeData; const { isCollapse, id } = nodeData;
console.log(id, findTableById(id), tables); lineageState.tables
const iTable = findTableById(id); .filter((item) => item.id === id)
if (iTable) { .forEach((item) => (item.isCollapse = isCollapse));
iTable.isCollapse = isCollapse;
}
// todo: 待实现 展开字段 // todo: 待实现 展开字段
setLineageState((prevState) => ({ ...prevState, expandField: !prevState.expandField })); setLineageState((prevState) => ({ ...prevState, expandField: !prevState.expandField }));
SuccessNotification( SuccessNotification(
lineageState.expandField ? l('lineage.expandField') : l('lineage.expandField') lineageState.expandField ? l('lineage.expandField') : l('lineage.expandField')
); );
}; };
const buildActionMenu = (data: ITable[]) => { const buildActionMenu = (data: ITable[]) => {
return [ return [
{ {
...@@ -273,7 +252,7 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => { ...@@ -273,7 +252,7 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => {
]; ];
}; };
const renderTitle = (title: string) => { const RenderTitle = (title: string) => {
return ( return (
<Text <Text
title={title} title={title}
...@@ -291,62 +270,70 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => { ...@@ -291,62 +270,70 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => {
); );
}; };
useEffect(() => {
if (lineageData) {
setLineageState((prevState) => ({
...prevState,
lineageData: lineageData,
tables: buildLineageTables(lineageData.tables),
relations: buildLineageRelations(lineageData.relations)
}));
}
}, [lineageData, lineageState.refresh]);
return ( return (
<> <LineageDagExt
<LineageDag tables={buildLineageTables(lineageState.lineageData.tables)}
delayDraw={2000} relations={buildLineageRelations(lineageState.lineageData.relations)}
tables={buildLineageTables(lineageState.lineageData.tables)} columns={buildLineageColumns(lineageState.lineageData)}
relations={buildLineageRelations(lineageState.lineageData.relations)} operator={buildActionMenu(lineageState.tables)}
columns={buildLineageColumns(lineageState.lineageData)} centerId={lineageState.centerId}
operator={buildActionMenu(lineageState.tables)} onLoaded={(canvas: any) => setLineageState((prevState) => ({ ...prevState, canvas }))}
centerId={lineageState.centerId} onChange={(data: any) =>
onLoaded={(canvas: any) => setLineageState((prevState) => ({ ...prevState, canvas }))} setLineageState((prevState) => ({ ...prevState, centerId: data.id }))
onChange={(data: any) => }
setLineageState((prevState) => ({ ...prevState, centerId: data.id })) config={{
} titleRender: (title: string) => RenderTitle(title),
config={{ minimap: { enable: lineageState.showMinimap },
titleRender: (title: string) => renderTitle(title), enableHoverChain: true,
minimap: { enable: lineageState.showMinimap }, showActionIcon: true,
enableHoverChain: true, gridMode: {
showActionIcon: true, isAdsorb: true,
gridMode: { theme: {
isAdsorb: true, shapeType: 'line',
theme: { gap: 20,
shapeType: 'line', lineWidth: 1,
gap: 20, lineColor: '#e8e8e8',
lineWidth: 1, circleRadiu: 5,
lineColor: '#e8e8e8', circleColor: '#e8e8e8'
circleRadiu: 5,
circleColor: '#e8e8e8'
}
} }
// theme: { }
// isMouseMoveStopPropagation: true, // theme: {
// autoFixCanvas: { // isMouseMoveStopPropagation: true,
// enable: true, // autoFixCanvas: {
// autoMovePadding: [40, 40, 40, 40], // enable: true,
// }, // autoMovePadding: [40, 40, 40, 40],
// edge: { // },
// type: 'endpoint', // edge: {
// shapeType: 'AdvancedBezier', // type: 'endpoint',
// hasRadius: true, // shapeType: 'AdvancedBezier',
// isExpandWidth: true, // hasRadius: true,
// label: '111', // isExpandWidth: true,
// defaultAnimate: true, // label: '111',
// arrowPosition: 1, // defaultAnimate: true,
// arrowOffset: -5 // arrowPosition: 1,
// }, // arrowOffset: -5
// } // },
}} // }
butterfly={{ }}
zoomable: true, butterfly={{
draggable: true, zoomable: true,
movable: true, draggable: true,
linkable: true movable: true,
}} linkable: true
actionMenu={renderExtActionButton()} }}
/> actionMenu={renderExtActionButton()}
</> />
); );
}; };
......
import LineageDag from 'react-lineage-dag';
import * as _ from 'lodash';
import * as ReactDOM from 'react-dom';
import { transformEdges, transformInitData } from 'react-lineage-dag/src/adaptor';
import LineageCanvas from 'react-lineage-dag/src/canvas/canvas';
export default class LineageDagExt extends LineageDag {
componentDidMount() {
let root = ReactDOM.findDOMNode(this) as HTMLElement;
let enableHoverChain = _.get(this.props, 'config.enableHoverChain', true);
let titleRender = _.get(this.props, 'config.titleRender');
let canvasObj = {
root: root,
disLinkable: false,
linkable: false,
draggable: false,
zoomable: true,
moveable: true,
theme: {
edge: {
type: 'endpoint',
// shapeType: 'AdvancedBezier',
arrow: true,
isExpandWidth: true,
arrowPosition: 1,
arrowOffset: -5
},
endpoint: {
limitNum: undefined,
expandArea: {
left: 0,
right: 0,
top: 0,
botton: 0
}
}
},
data: {
enableHoverChain: enableHoverChain
}
};
this.canvas = new LineageCanvas(canvasObj);
let result = transformInitData({
tables: this.props.tables,
relations: this.props.relations,
columns: this.props.columns,
operator: this.props.operator,
_titleRender: titleRender,
_enableHoverChain: enableHoverChain,
_emptyContent: this.props.emptyContent,
_emptyWidth: this.props.emptyWidth
});
this.originEdges = result.edges;
result = transformEdges(result.nodes, _.cloneDeep(result.edges));
this.canvasData = {
nodes: result.nodes,
edges: result.edges
};
let minimap = _.get(this, 'props.config.minimap', {});
const minimapCfg = _.assign({}, minimap.config, {
events: ['system.node.click', 'system.canvas.click']
});
if (minimap && minimap.enable) {
this.canvas.setMinimap(true, minimapCfg);
}
if (_.get(this, 'props.config.gridMode')) {
this.canvas.setGridMode(true, _.assign({}, _.get(this, 'props.config.gridMode', {})));
}
if (result.nodes.length !== 0) {
this.canvas.focusCenterWithAnimate();
this._isFirstFocus = true;
}
this.props.onLoaded && this.props.onLoaded(this.canvas);
this.canvas.on('system.node.click', (data) => {
let node = data.node;
this.canvas.focus(node.id);
});
this.canvas.on('system.canvas.click', () => {
this.canvas.unfocus();
});
}
}
...@@ -54,19 +54,17 @@ const Lineage: React.FC<connect> = (props) => { ...@@ -54,19 +54,17 @@ const Lineage: React.FC<connect> = (props) => {
}, [activeKey]); }, [activeKey]);
return ( return (
<> <Card hoverable bodyStyle={{ height: bottomHeight - 50 }} style={{ height: bottomHeight }}>
<Card hoverable bodyStyle={{ height: bottomHeight - 50 }} style={{ height: bottomHeight }}> {lineageData && (lineageData.tables.length !== 0 || lineageData.relations.length !== 0) ? (
{lineageData && (lineageData.tables.length !== 0 || lineageData.relations.length !== 0) ? ( <LineageGraph lineageData={lineageData} refreshCallBack={queryLineageData} />
<LineageGraph lineageData={lineageData} refreshCallBack={queryLineageData} /> ) : (
) : ( <Result
<Result style={{ height: bottomHeight - 120 }}
style={{ height: bottomHeight - 120 }} status='warning'
status='warning' title={l('lineage.getError')}
title={l('lineage.getError')} />
/> )}
)} </Card>
</Card>
</>
); );
}; };
......
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