Unverified Commit e0017561 authored by Licho's avatar Licho Committed by GitHub

Fix lineage again (#2411)

* fix: Lineage render problem * Spotless Apply * feat: use origin lineage-dag-ext.tsx * feat: use ext lineage-dag-ext.tsx * Spotless Apply --------- Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent 80529cf8
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,
...@@ -20,6 +19,9 @@ import { ...@@ -20,6 +19,9 @@ import {
import _ from 'lodash'; import _ from 'lodash';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import 'react-lineage-dag/dist/index.css'; import 'react-lineage-dag/dist/index.css';
// import LineageDag from "react-lineage-dag";
import LineageDagExt from '@/components/LineageGraph/lineage-dag-ext';
// import LineageDagExt from "@/components/LineageGraph/lineage-dag-ext";
interface LineageState { interface LineageState {
lineageData: LineageDetailInfo; lineageData: LineageDetailInfo;
...@@ -76,11 +78,7 @@ const InitLineageState: LineageState = { ...@@ -76,11 +78,7 @@ const InitLineageState: LineageState = {
collapseUpstream: false collapseUpstream: false
}; };
const LineageGraph: React.FC<JobLineageProps> = (props) => { const buildLineageColumns = (data: LineageDetailInfo) => {
const { lineageData, refreshCallBack } = props;
const [lineageState, setLineageState] = React.useState<LineageState>(InitLineageState);
const buildLineageColumns = (data: LineageDetailInfo) => {
return [ return [
{ {
key: 'id', key: 'id',
...@@ -108,18 +106,18 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => { ...@@ -108,18 +106,18 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => {
} }
} }
]; ];
}; };
const buildLineageTables = (tables: LineageTable[]) => { const buildLineageTables = (tables: LineageTable[]) => {
return tables.map((table: LineageTable) => ({ return tables.map((table: LineageTable) => ({
id: table?.id, id: table?.id,
name: table?.name, name: table?.name,
isCollapse: false, isCollapse: false,
fields: table?.columns fields: table?.columns
})); }));
}; };
const buildLineageRelations = (relations: LineageRelations[]) => { const buildLineageRelations = (relations: LineageRelations[]) => {
return relations.map((relation: LineageRelations) => ({ return relations.map((relation: LineageRelations) => ({
id: relation?.id, id: relation?.id,
srcTableId: relation?.srcTableId, srcTableId: relation?.srcTableId,
...@@ -127,7 +125,27 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => { ...@@ -127,7 +125,27 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => {
srcTableColName: relation?.srcTableColName, srcTableColName: relation?.srcTableColName,
tgtTableColName: relation?.tgtTableColName tgtTableColName: relation?.tgtTableColName
})); }));
}; };
const LineageGraph: React.FC<JobLineageProps> = (props) => {
const { lineageData, refreshCallBack } = props;
const [lineageState, setLineageState] = React.useState<LineageState>({
...InitLineageState,
lineageData: lineageData,
tables: buildLineageTables(lineageData.tables),
relations: buildLineageRelations(lineageData.relations)
});
useEffect(() => {
if (lineageData) {
setLineageState((prevState) => ({
...prevState,
lineageData: lineageData,
tables: buildLineageTables(lineageData.tables),
relations: buildLineageRelations(lineageData.relations)
}));
}
}, [lineageData, lineageState.refresh]);
const handleExpandField = (nodeData: any, tables: ITable[]) => { const handleExpandField = (nodeData: any, tables: ITable[]) => {
const { isCollapse, id } = nodeData; const { isCollapse, id } = nodeData;
...@@ -260,7 +278,7 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => { ...@@ -260,7 +278,7 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => {
ellipsis ellipsis
type={'secondary'} type={'secondary'}
onClick={() => { onClick={() => {
lineageState.canvas.nodes.forEach((item: { redrawTitle: () => void }) => { lineageState.canvas.nodes?.forEach((item: { redrawTitle: () => void }) => {
item.redrawTitle(); item.redrawTitle();
}); });
}} }}
...@@ -270,17 +288,6 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => { ...@@ -270,17 +288,6 @@ 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 <LineageDagExt
tables={buildLineageTables(lineageState.lineageData.tables)} tables={buildLineageTables(lineageState.lineageData.tables)}
...@@ -308,23 +315,6 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => { ...@@ -308,23 +315,6 @@ const LineageGraph: React.FC<JobLineageProps> = (props) => {
circleColor: '#e8e8e8' circleColor: '#e8e8e8'
} }
} }
// theme: {
// isMouseMoveStopPropagation: true,
// autoFixCanvas: {
// enable: true,
// autoMovePadding: [40, 40, 40, 40],
// },
// edge: {
// type: 'endpoint',
// shapeType: 'AdvancedBezier',
// hasRadius: true,
// isExpandWidth: true,
// label: '111',
// defaultAnimate: true,
// arrowPosition: 1,
// arrowOffset: -5
// },
// }
}} }}
butterfly={{ butterfly={{
zoomable: true, zoomable: true,
......
...@@ -22,7 +22,7 @@ export default class LineageDagExt extends LineageDag { ...@@ -22,7 +22,7 @@ export default class LineageDagExt extends LineageDag {
theme: { theme: {
edge: { edge: {
type: 'endpoint', type: 'endpoint',
// shapeType: 'AdvancedBezier', shapeType: 'AdvancedBezier',
arrow: true, arrow: true,
isExpandWidth: true, isExpandWidth: true,
arrowPosition: 1, arrowPosition: 1,
...@@ -59,11 +59,38 @@ export default class LineageDagExt extends LineageDag { ...@@ -59,11 +59,38 @@ export default class LineageDagExt extends LineageDag {
this.originEdges = result.edges; this.originEdges = result.edges;
result = transformEdges(result.nodes, _.cloneDeep(result.edges)); result = transformEdges(result.nodes, _.cloneDeep(result.edges));
result.edges = result.edges.map((item) => {
return {
...item,
shapeType: 'AdvancedBezier'
};
});
this.canvasData = { this.canvasData = {
nodes: result.nodes, nodes: result.nodes,
edges: result.edges edges: result.edges
}; };
setTimeout(() => {
let tmpEdges = result.edges;
result.edges = [];
// this.canvas.wrapper.style.visibility = 'hidden';
this.canvas.draw(result, () => {
this.canvas.relayout(
{
edges: tmpEdges.map((item) => {
return {
source: item.sourceNode,
target: item.targetNode
};
})
},
true
);
// this.canvas.wrapper.style.visibility = 'visible';
debugger;
this.canvas.addEdges(tmpEdges, true);
let minimap = _.get(this, 'props.config.minimap', {}); let minimap = _.get(this, 'props.config.minimap', {});
const minimapCfg = _.assign({}, minimap.config, { const minimapCfg = _.assign({}, minimap.config, {
...@@ -83,7 +110,9 @@ export default class LineageDagExt extends LineageDag { ...@@ -83,7 +110,9 @@ export default class LineageDagExt extends LineageDag {
this._isFirstFocus = true; this._isFirstFocus = true;
} }
this.forceUpdate();
this.props.onLoaded && this.props.onLoaded(this.canvas); this.props.onLoaded && this.props.onLoaded(this.canvas);
});
this.canvas.on('system.node.click', (data) => { this.canvas.on('system.node.click', (data) => {
let node = data.node; let node = data.node;
this.canvas.focus(node.id); this.canvas.focus(node.id);
...@@ -91,5 +120,6 @@ export default class LineageDagExt extends LineageDag { ...@@ -91,5 +120,6 @@ export default class LineageDagExt extends LineageDag {
this.canvas.on('system.canvas.click', () => { this.canvas.on('system.canvas.click', () => {
this.canvas.unfocus(); this.canvas.unfocus();
}); });
}, _.get(this.props, 'config.delayDraw', 0));
} }
} }
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