Skip to content

Commit 6dd91c8

Browse files
Fixed an issue where the ERD tool fails to open a saved file containing parent-child relationship within the same table. #8389
Fixed an issue in ERD where link notation end-points were not rendering occasionally. --------- Co-authored-by: Aditya Toshniwal <[email protected]>
1 parent 83ade5d commit 6dd91c8

File tree

1 file changed

+40
-48
lines changed

1 file changed

+40
-48
lines changed

web/pgadmin/tools/erd/static/js/erd_tool/links/OneToManyLink.jsx

+40-48
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class OneToManyLinkModel extends RightAngleLinkModel {
8181
data: this.getData(),
8282
};
8383
}
84-
84+
8585
setPointType(nodesDict) {
8686
let data = this.getData();
8787
let target = nodesDict[data['local_table_uid']].getData();
@@ -97,6 +97,18 @@ export class OneToManyLinkModel extends RightAngleLinkModel {
9797
getPointType() {
9898
return this._linkPointType;
9999
}
100+
101+
setFirstAndLastPathsDirection() {
102+
let points = this.getPoints();
103+
if (points.length > 2){
104+
super.setFirstAndLastPathsDirection();
105+
} else {
106+
let dx = Math.abs(points[1].getX() - points[0].getX());
107+
let dy = Math.abs(points[1].getY() - points[0].getY());
108+
this._firstPathXdirection = dx > dy;
109+
this._lastPathXdirection = dx > dy;
110+
}
111+
}
100112
}
101113

102114
const svgLinkSelected = keyframes`
@@ -147,49 +159,33 @@ ChenNotation.propTypes = {
147159
type: PropTypes.string,
148160
};
149161

150-
function CustomLinkEndWidget(props) {
151-
const { point, rotation, tx, ty, type } = props;
152-
162+
function NotationForType({itype, width, rotation}) {
153163
const settings = useContext(ERDCanvasSettings);
154164

155-
const svgForType = (itype) => {
156-
if(settings.cardinality_notation == 'chen') {
157-
return <ChenNotation rotation={rotation} type={itype} />;
158-
}
159-
if(itype == 'many') {
160-
return (
161-
<>
162-
<circle className={['OneToMany-svgLink','OneToMany-svgLinkCircle'].join(' ')} cx="0" cy="16" r={props.width*2.5} strokeWidth={props.width} />
163-
<polyline className='OneToMany-svgLink' points="-8,0 0,15 0,0 0,30 0,15 8,0" fill="none" strokeWidth={props.width} />
164-
</>
165-
);
166-
} else if (itype == 'one') {
167-
return (
168-
<polyline className='OneToMany-svgLink' points="-8,15 0,15 0,0 0,30 0,15 8,15" fill="none" strokeWidth={props.width} />
169-
);
170-
}
171-
};
172-
173-
return (
174-
<g transform={'translate(' + point.getPosition().x + ', ' + point.getPosition().y + ')'}>
175-
<g transform={'translate('+tx+','+ty+')'}>
176-
<g transform={'rotate(' + rotation + ')' }>
177-
{svgForType(type)}
178-
</g>
179-
</g>
180-
</g>
181-
);
165+
if(settings.cardinality_notation == 'chen') {
166+
return <ChenNotation rotation={rotation} type={itype} />;
167+
}
168+
if(itype == 'many') {
169+
return (
170+
<>
171+
<circle className={['OneToMany-svgLink','OneToMany-svgLinkCircle'].join(' ')} cx="0" cy="16" r={width*2.5} strokeWidth={width} />
172+
<polyline className='OneToMany-svgLink' points="-8,0 0,15 0,0 0,30 0,15 8,0" fill="none" strokeWidth={width} />
173+
</>
174+
);
175+
} else if (itype == 'one') {
176+
return (
177+
<polyline className='OneToMany-svgLink' points="-8,15 0,15 0,0 0,30 0,15 8,15" fill="none" strokeWidth={width} />
178+
);
179+
}
182180
}
183181

184-
CustomLinkEndWidget.propTypes = {
185-
point: PropTypes.instanceOf(PointModel).isRequired,
182+
NotationForType.propTypes = {
183+
itype: PropTypes.oneOf(['many', 'one']).isRequired,
186184
rotation: PropTypes.number.isRequired,
187-
tx: PropTypes.number.isRequired,
188-
ty: PropTypes.number.isRequired,
189-
type: PropTypes.oneOf(['many', 'one']).isRequired,
190185
width: PropTypes.number,
191186
};
192187

188+
193189
export class OneToManyLinkWidget extends RightAngleLinkWidget {
194190
constructor(props) {
195191
super(props);
@@ -255,17 +251,13 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
255251

256252
generateCustomEndWidget({type, point, rotation, tx, ty}) {
257253
return (
258-
<CustomLinkEndWidget
259-
key={point.getID()}
260-
point={point}
261-
rotation={rotation}
262-
tx={tx}
263-
ty={ty}
264-
type={type}
265-
colorSelected={this.props.link.getOptions().selectedColor}
266-
color={this.props.link.getOptions().color}
267-
width={this.props.width}
268-
/>
254+
<g key={point.getID()} transform={'translate(' + point.getPosition().x + ', ' + point.getPosition().y + ')'}>
255+
<g transform={'translate('+tx+','+ty+')'}>
256+
<g transform={'rotate(' + rotation + ')' }>
257+
<NotationForType itype={type} width={this.props.width} rotation={rotation} />
258+
</g>
259+
</g>
260+
</g>
269261
);
270262
}
271263

@@ -318,6 +310,7 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
318310
}
319311

320312
// If there is existing link which has two points add one
313+
// and the link is horizontal
321314
if (points.length === 2 && !this.state.canDrag && onePoint.point.getX() != manyPoint.point.getX()) {
322315
this.props.link.addPoint(
323316
new PointModel({
@@ -357,7 +350,6 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
357350
}
358351
paths.push(this.generateCustomEndWidget(manyPoint));
359352

360-
this.refPaths = [];
361353
return <StyledG data-default-link-test={this.props.link.getOptions().testName}>{paths}</StyledG>;
362354
}
363355
}

0 commit comments

Comments
 (0)