Skip to content

refactor(stories): migrate PortRefs to TypeScript - #1129

Merged
redfish4ktc merged 1 commit into
mainfrom
docs/portrefs-migrate-to-typescript
Aug 8, 2026
Merged

refactor(stories): migrate PortRefs to TypeScript#1129
redfish4ktc merged 1 commit into
mainfrom
docs/portrefs-migrate-to-typescript

Conversation

@redfish4ktc

@redfish4ktc redfish4ktc commented Aug 8, 2026

Copy link
Copy Markdown
Member

Overview

Migrates the PortRefs Storybook story from JavaScript to TypeScript, and removes the four global prototype mutations it relied on.

Those mutations were the main problem: Shape.prototype, TriangleShape.prototype, ConstraintHandler.prototype and EdgeHandler.prototype are shared by every story running in the same Storybook session, so the port definitions and the port image leaked out of this story into the others. They are replaced by per-instance constructs:

Before After
Shape.prototype.getPorts / TriangleShape.prototype.getPorts a PortRefsCellRenderer reading a ports key from the cell style
ConstraintHandler.prototype.pointImage a MyCustomConstraintHandler, injected through a custom ConnectionHandler and an explicit plugin list
EdgeHandler.prototype.isConnectableCell a CustomEdgeHandler, returned by the createEdgeHandler hook of the graph

Two defects found while porting are fixed as well:

  • the triangle out1 port sat at the middle of the flat top edge instead of the top right vertex that its north east constraint announces
  • the port id was bolted onto ConnectionConstraint through an as any cast, while the class already exposes a typed name field designed for exactly that

The story also gains a description above the graph explaining what it demonstrates, optional chaining instead of the nested null checks in the port lookups, and the object parameter form of insertVertex / insertEdge (see #856).

Notes

Covers #418 and #1035.

The behaviour of the story is unchanged. Validated manually in Storybook: connecting through ports, reconnecting an edge terminal, and the port image on hover.

This PR is deliberately limited to the story. It is extracted from a larger branch that moves the cell handler factories out of AbstractGraph into the SelectionCellsHandler plugin (#762). Once this is merged, the only remaining difference on this file in that branch is the edge handler wiring, which switches from the createEdgeHandler hook used here to the new plugin factory.

Summary by CodeRabbit

  • New Features
    • Added a Storybook example demonstrating connections that reference specific port IDs.
    • The example includes standard and triangle-shaped nodes with custom connection points and representative edges.
    • Demonstrates connections that remain associated with their intended ports, including customized connection behavior and styling.

Port the story to TypeScript and drop the four global prototype mutations it relied on, which leaked into every
other story sharing the same classes:

- Shape.prototype.getPorts and TriangleShape.prototype.getPorts become a PortRefsCellRenderer that reads a `ports`
  key from the cell style, so the port sets stay attached to the cells that declare them.
- ConstraintHandler.prototype.pointImage becomes a MyCustomConstraintHandler, injected through a custom
  ConnectionHandler and an explicit plugin list.
- EdgeHandler.prototype.isConnectableCell becomes a CustomEdgeHandler, returned by the graph createEdgeHandler hook.

Fix two defects found while porting: the triangle 'out1' port sat at the middle of the flat top edge instead of the
top right vertex its 'north east' constraint announces, and the port id was bolted onto ConnectionConstraint through
an `as any` cast while the class already has a typed `name` field for it.

Add a description above the graph explaining what the story demonstrates, use optional chaining instead of the
nested null checks in the port lookups, and insert the cells with the object parameter form.
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The PortRefs Storybook story was migrated from JavaScript to TypeScript. The new story preserves port metadata, custom connection handling, sample graph setup, and the exported Default story.

Changes

PortRefs Story Migration

Layer / File(s) Summary
Story metadata and port contracts
packages/html/stories/PortRefs.stories.ts, packages/html/stories/PortRefs.stories.js
The TypeScript story adds Storybook metadata, port configuration types, and custom renderers that expose port metadata. The JavaScript story is removed.
Port connection handling
packages/html/stories/PortRefs.stories.ts
The story configures graph plugins and connectability. It stores port IDs in edge styles and resolves connection constraints and coordinates from those IDs.
Sample graph and story export
packages/html/stories/PortRefs.stories.ts
The story creates sample vertices and edges with standard, ellipse, and triangle ports. It exports the bound Default story and retains notes for future orthogonal routing.
Estimated code review effort: 3 (Moderate) ~25 minutes

Possibly related PRs

Suggested labels: refactor

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the TypeScript migration of the PortRefs Storybook story.
Description check ✅ Passed The description explains the motivation, implementation, fixes, issue references, validation, and scope of the changes.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Aug 8, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/html/stories/PortRefs.stories.ts (1)

64-64: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a typed story-arguments contract.

Record<string, string> makes the shared rubberBand, width, and height args sound like strings even though they are booleans and numbers, and the story does not provide label. Give the template the actual story argument shape, or type createGraphContainer’s args contract if this type is shared.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 94249578-fc22-476c-8b7c-3fb55fe83026

📥 Commits

Reviewing files that changed from the base of the PR and between 5c8cf90 and 9f93592.

📒 Files selected for processing (2)
  • packages/html/stories/PortRefs.stories.js
  • packages/html/stories/PortRefs.stories.ts
💤 Files with no reviewable changes (1)
  • packages/html/stories/PortRefs.stories.js

@redfish4ktc redfish4ktc added the refactor Code refactoring label Aug 8, 2026
@redfish4ktc
redfish4ktc merged commit d19ad65 into main Aug 8, 2026
14 checks passed
@redfish4ktc
redfish4ktc deleted the docs/portrefs-migrate-to-typescript branch August 8, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant