Skip to content

Commit 5079421

Browse files
adityatoshniwalpravesh-sharma
authored andcommitted
Fixed an issue in ERD where link notation end-points were not rendering occassionaly.
1 parent 2c4ccd0 commit 5079421

File tree

1 file changed

+33
-48
lines changed

1 file changed

+33
-48
lines changed

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

Lines changed: 33 additions & 48 deletions
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();
@@ -102,6 +102,11 @@ export class OneToManyLinkModel extends RightAngleLinkModel {
102102
let points = this.getPoints();
103103
if (points.length > 2){
104104
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;
105110
}
106111
}
107112
}
@@ -154,49 +159,33 @@ ChenNotation.propTypes = {
154159
type: PropTypes.string,
155160
};
156161

157-
function CustomLinkEndWidget(props) {
158-
const { point, rotation, tx, ty, type } = props;
159-
162+
function NotationForType({itype, width, rotation}) {
160163
const settings = useContext(ERDCanvasSettings);
161164

162-
const svgForType = (itype) => {
163-
if(settings.cardinality_notation == 'chen') {
164-
return <ChenNotation rotation={rotation} type={itype} />;
165-
}
166-
if(itype == 'many') {
167-
return (
168-
<>
169-
<circle className={['OneToMany-svgLink','OneToMany-svgLinkCircle'].join(' ')} cx="0" cy="16" r={props.width*2.5} strokeWidth={props.width} />
170-
<polyline className='OneToMany-svgLink' points="-8,0 0,15 0,0 0,30 0,15 8,0" fill="none" strokeWidth={props.width} />
171-
</>
172-
);
173-
} else if (itype == 'one') {
174-
return (
175-
<polyline className='OneToMany-svgLink' points="-8,15 0,15 0,0 0,30 0,15 8,15" fill="none" strokeWidth={props.width} />
176-
);
177-
}
178-
};
179-
180-
return (
181-
<g transform={'translate(' + point.getPosition().x + ', ' + point.getPosition().y + ')'}>
182-
<g transform={'translate('+tx+','+ty+')'}>
183-
<g transform={'rotate(' + rotation + ')' }>
184-
{svgForType(type)}
185-
</g>
186-
</g>
187-
</g>
188-
);
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+
}
189180
}
190181

191-
CustomLinkEndWidget.propTypes = {
192-
point: PropTypes.instanceOf(PointModel).isRequired,
182+
NotationForType.propTypes = {
183+
itype: PropTypes.oneOf(['many', 'one']).isRequired,
193184
rotation: PropTypes.number.isRequired,
194-
tx: PropTypes.number.isRequired,
195-
ty: PropTypes.number.isRequired,
196-
type: PropTypes.oneOf(['many', 'one']).isRequired,
197185
width: PropTypes.number,
198186
};
199187

188+
200189
export class OneToManyLinkWidget extends RightAngleLinkWidget {
201190
constructor(props) {
202191
super(props);
@@ -262,17 +251,13 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
262251

263252
generateCustomEndWidget({type, point, rotation, tx, ty}) {
264253
return (
265-
<CustomLinkEndWidget
266-
key={point.getID()}
267-
point={point}
268-
rotation={rotation}
269-
tx={tx}
270-
ty={ty}
271-
type={type}
272-
colorSelected={this.props.link.getOptions().selectedColor}
273-
color={this.props.link.getOptions().color}
274-
width={this.props.width}
275-
/>
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>
276261
);
277262
}
278263

@@ -325,6 +310,7 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
325310
}
326311

327312
// If there is existing link which has two points add one
313+
// and the link is horizontal
328314
if (points.length === 2 && !this.state.canDrag && onePoint.point.getX() != manyPoint.point.getX()) {
329315
this.props.link.addPoint(
330316
new PointModel({
@@ -364,7 +350,6 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
364350
}
365351
paths.push(this.generateCustomEndWidget(manyPoint));
366352

367-
this.refPaths = [];
368353
return <StyledG data-default-link-test={this.props.link.getOptions().testName}>{paths}</StyledG>;
369354
}
370355
}

0 commit comments

Comments
 (0)