-
Notifications
You must be signed in to change notification settings - Fork 199
refactor: migrate the "Animation" story to TypeScript #635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Rationale: - Ease the maintenance - Detect the errors earlier
WalkthroughThe pull request focuses on enhancing type safety and improving error handling in the Changes
Possibly related PRs
Suggested labels
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/html/stories/Animation.stories.ts (1)
35-35: Consider using a more specific type for the template props.Using
Record<string, string>is too generic and might hide potential type errors. Consider creating a specific interface for the props.interface TemplateProps extends Record<string, string> { label: string; } const Template = ({ label, ...args }: TemplateProps)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/html/stories/Animation.stories.ts(3 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/html/stories/Animation.stories.ts
[error] 82-82: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.
(lint/suspicious/noAssignInExpressions)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: build
- GitHub Check: build (windows-2022)
- GitHub Check: build (macos-14)
- GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (4)
packages/html/stories/Animation.stories.ts (4)
18-18: LGTM! Clean type import declaration.The type-only import for
CellStylefollows TypeScript best practices.
Line range hint
42-51: LGTM! Well-typed style object.The
CellStyletype annotation provides good type safety for the vertex styling properties.
77-79: LGTM! Proper boolean values for edge properties.Converting numeric values to proper boolean types improves type safety and readability.
87-91: Consider refactoring repetitive DOM operations.The code could be simplified to reduce repetition and improve null safety.
const path0 = state?.shape?.node.getElementsByTagName('path')[0]; const path1 = state?.shape?.node.getElementsByTagName('path')[1]; if (path0) { path0.removeAttribute('visibility'); path0.setAttribute('stroke-width', '6'); path0.setAttribute('stroke', 'lightGray'); } path1?.setAttribute('class', 'flow');Also, consider adding a comment explaining why the non-null assertion (
!) is safe to use one1.✅ Verification successful
Refactoring suggestion is valid and safe to implement
The suggested refactoring will improve code readability while maintaining the same functionality. The non-null assertion on
e1is safe as the edge is created and configured immediately before use.🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash # Find the context around this code rg -B 10 -A 5 "state\?\.shape\?\.node\.getElementsByTagName\('path'\)" packages/html/stories/Animation.stories.ts # Look for similar patterns of DOM operations on SVG paths rg "getElementsByTagName\('path'\)" --type ts # Find usage of graph.view.getState rg "graph\.view\.getState" --type tsLength of output: 5969
| }, | ||
| }); | ||
| e1.geometry.points = [new Point(230, 50)]; | ||
| e1.geometry && (e1.geometry.points = [new Point(230, 50)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid assignment within expression.
The assignment within the condition makes the code harder to read and maintain.
-e1.geometry && (e1.geometry.points = [new Point(230, 50)]);
+if (e1.geometry) {
+ e1.geometry.points = [new Point(230, 50)];
+}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| e1.geometry && (e1.geometry.points = [new Point(230, 50)]); | |
| if (e1.geometry) { | |
| e1.geometry.points = [new Point(230, 50)]; | |
| } |
🧰 Tools
🪛 Biome (1.9.4)
[error] 82-82: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.
(lint/suspicious/noAssignInExpressions)
Rationale:
Summary by CodeRabbit
CellStyle