-
Notifications
You must be signed in to change notification settings - Fork 199
feat!: introduce global config for the Manhattan connector #681
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
Introduce a dedicated `ManhattanConnectorConfig` global object and its companion reset function. BREAKING CHANGES: `ManhattanConnector` is now configured with the global `ManhattanConnectorConfig` object. The following properties that were previously on `EdgeStyle` have moved to `ManhattanConnectorConfig`: - `MANHATTAN_END_DIRECTIONS` to `endDirections` - `MANHATTAN_MAX_ALLOWED_DIRECTION_CHANGE` to `maxAllowedDirectionChange` - `MANHATTAN_MAXIMUM_LOOPS` to `maxLoops` - `MANHATTAN_START_DIRECTIONS` to `startDirections` - `MANHATTAN_STEP` to `step`
WalkthroughThe pull request reorganizes the internal API of the maxGraph library by restricting the visibility of utility functions, removing obsolete functions, and centralizing configuration management. It removes several public utility functions, relocates the version property, and introduces global configuration objects for the Manhattan and Orth connectors. Additionally, the changes enhance the shallow copy utility to handle arrays accurately, add tests for the reset functionality of the Manhattan connector configuration, and update related documentation and Storybook reset logic. Changes
Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
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: 4
🧹 Nitpick comments (3)
packages/core/src/view/style/config.ts (1)
131-132: Use type-safe initialization for the original config backup.Instead of using type assertion, consider initializing the object with the same shape as
ManhattanConnectorConfig.Apply this diff:
-const originalManhattanConnectorConfig = {} as typeof ManhattanConnectorConfig; -shallowCopy(ManhattanConnectorConfig, originalManhattanConnectorConfig); +const originalManhattanConnectorConfig: ManhattanConnectorConfigType = { + maxAllowedDirectionChange: ManhattanConnectorConfig.maxAllowedDirectionChange, + maxLoops: ManhattanConnectorConfig.maxLoops, + endDirections: [...ManhattanConnectorConfig.endDirections], + startDirections: [...ManhattanConnectorConfig.startDirections], + step: ManhattanConnectorConfig.step, +};packages/website/docs/usage/global-configuration.md (2)
24-25: Fix indentation in the unordered list.The indentation of the list items is inconsistent with the rest of the document. The markdownlint tool indicates that the indentation should be 2 spaces.
Apply this diff to fix the indentation:
- - `ManhattanConnectorConfig` (since 0.16.0): for `ManhattanConnector`. - - `OrthConnectorConfig` (since 0.16.0): for `OrthConnector`. + - `ManhattanConnectorConfig` (since 0.16.0): for `ManhattanConnector`. + - `OrthConnectorConfig` (since 0.16.0): for `OrthConnector`.🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
24-24: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
25-25: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
35-36: Fix indentation in the unordered list.The indentation of the list items is inconsistent with the rest of the document. The markdownlint tool indicates that the indentation should be 2 spaces.
Apply this diff to fix the indentation:
- - `resetManhattanConnectorConfig` (since 0.16.0) - - `resetOrthConnectorConfig` (since 0.16.0) + - `resetManhattanConnectorConfig` (since 0.16.0) + - `resetOrthConnectorConfig` (since 0.16.0)🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
35-35: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
36-36: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
CHANGELOG.md(1 hunks)packages/core/__tests__/view/style/config.test.ts(2 hunks)packages/core/src/util/cloneUtils.ts(2 hunks)packages/core/src/view/style/EdgeStyle.ts(9 hunks)packages/core/src/view/style/config.ts(2 hunks)packages/html/.storybook/preview.ts(2 hunks)packages/website/docs/usage/global-configuration.md(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/core/src/util/cloneUtils.ts (1)
Learnt from: tbouffard
PR: maxGraph/maxGraph#582
File: packages/core/src/util/config.ts:0-0
Timestamp: 2024-11-23T16:12:51.380Z
Learning: The `shallowCopy` function in `cloneUtils.ts` is intentionally designed to perform a shallow copy on objects that contain only primitive properties, and deep copying is not necessary.
🪛 markdownlint-cli2 (0.17.2)
packages/website/docs/usage/global-configuration.md
24-24: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
35-35: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
🪛 Biome (1.9.4)
packages/core/src/util/cloneUtils.ts
[error] 78-78: Use Array.isArray() instead of instanceof Array.
instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.
(lint/suspicious/useIsArray)
🪛 GitHub Actions: Generate website
packages/core/src/view/style/EdgeStyle.ts
[error] 1200-1200: Argument of type 'DirectionValue[]' is not assignable to parameter of type 'DIRECTION[]'. Type 'DirectionValue' is not assignable to type 'DIRECTION'. Type '"north"' is not assignable to type 'DIRECTION'.
[error] 1207-1207: Argument of type 'DirectionValue[]' is not assignable to parameter of type 'DIRECTION[]'. Type 'DirectionValue' is not assignable to type 'DIRECTION'. Type '"north"' is not assignable to type 'DIRECTION'.
🪛 GitHub Actions: Build
packages/core/src/view/style/EdgeStyle.ts
[error] 1200-1200: Argument of type 'DirectionValue[]' is not assignable to parameter of type 'DIRECTION[]'.
🪛 LanguageTool
CHANGELOG.md
[grammar] ~29-~29: This phrase is duplicated. You should probably use “to to” only once.
Context: ...Config: - MANHATTAN_END_DIRECTIONStoendDirections -MANHATTAN_MAX_ALLOWED_DIRECTION_CHANGEtomaxAllowedDirectionChange -MANHATTAN_MAXIMUM_LOOPStomaxLoops -MANHATTAN_START_DIRECTIONStostartDirections -MANHATTAN_STEP` ...
(PHRASE_REPETITION)
🔇 Additional comments (5)
packages/html/.storybook/preview.ts (1)
8-8: LGTM! Reset function integration is well-placed.The integration of
resetManhattanConnectorConfigfollows the established pattern and is appropriately placed in the reset sequence.Also applies to: 27-27
packages/core/__tests__/view/style/config.test.ts (1)
42-71: LGTM! Comprehensive test coverage for the reset functionality.The test suite thoroughly covers both simple values and array handling, ensuring the reset function works as expected.
packages/core/src/view/style/config.ts (1)
86-129: LGTM! Well-structured configuration type and object.The
ManhattanConnectorConfigTypeis well-documented and the configuration object provides sensible defaults.packages/core/src/view/style/EdgeStyle.ts (1)
43-43: LGTM!The import statement correctly imports both
ManhattanConnectorConfigandOrthConnectorConfigfrom the configuration module.CHANGELOG.md (1)
27-33: LGTM!The breaking changes are well documented, clearly listing all properties that have been moved from
EdgeStyletoManhattanConnectorConfig.🧰 Tools
🪛 LanguageTool
[grammar] ~29-~29: This phrase is duplicated. You should probably use “to to” only once.
Context: ...Config: -MANHATTAN_END_DIRECTIONStoendDirections-MANHATTAN_MAX_ALLOWED_DIRECTION_CHANGEtomaxAllowedDirectionChange-MANHATTAN_MAXIMUM_LOOPStomaxLoops-MANHATTAN_START_DIRECTIONStostartDirections-MANHATTAN_STEP` ...(PHRASE_REPETITION)
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
♻️ Duplicate comments (1)
packages/core/src/view/style/EdgeStyle.ts (1)
1158-1163:⚠️ Potential issueFix type errors in direction handling.
The
DirectionValue[]type is not assignable toDIRECTION[]. This needs to be fixed in multiple locations.Apply this diff to fix the type errors:
- ? ManhattanConnectorConfig.startDirections.every( + ? (ManhattanConnectorConfig.startDirections as DIRECTION[]).every( (d) => d != DIRECTION.NORTH && d != DIRECTION.SOUTH ) - : ManhattanConnectorConfig.endDirections.every( + : (ManhattanConnectorConfig.endDirections as DIRECTION[]).every( (d) => d != DIRECTION.NORTH && d != DIRECTION.SOUTH ); - ? ManhattanConnectorConfig.startDirections.every( + ? (ManhattanConnectorConfig.startDirections as DIRECTION[]).every( (d) => d != DIRECTION.WEST && d != DIRECTION.EAST ) - : ManhattanConnectorConfig.endDirections.every( + : (ManhattanConnectorConfig.endDirections as DIRECTION[]).every( (d) => d != DIRECTION.WEST && d != DIRECTION.EAST ); const startPoints = getRectPoints( start, - ManhattanConnectorConfig.startDirections, + ManhattanConnectorConfig.startDirections as DIRECTION[], opt ).filter((p) => obstacleMap.isPointAccessible(p)); const endPoints = getRectPoints( end, - ManhattanConnectorConfig.endDirections, + ManhattanConnectorConfig.endDirections as DIRECTION[], opt ).filter((p) => obstacleMap.isPointAccessible(p));Also applies to: 1175-1180, 1198-1208
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/core/src/view/style/EdgeStyle.ts(9 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: build (windows-2022)
- GitHub Check: build
- GitHub Check: build (macos-14)
- GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (1)
packages/core/src/view/style/EdgeStyle.ts (1)
35-35: LGTM! Import changes align with the PR objectives.The addition of
DirectionValuetype andManhattanConnectorConfigimports supports the introduction of the global configuration object.Also applies to: 43-43
Also make the code more robust and better use the maxGraph API.
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: 0
🧹 Nitpick comments (3)
packages/html/stories/Manhattan.stories.ts (3)
26-26: Remove file extension from import path.The import statement includes the
.tsfile extension, which is not a common practice in TypeScript and may cause issues with some bundlers.-import EventObject from '@maxgraph/core/lib/view/event/EventObject.ts'; +import EventObject from '@maxgraph/core/lib/view/event/EventObject';
38-38: Consider using a more specific type for the Template function parameters.Using
Record<string, string>is too generic. Consider creating an interface that explicitly defines the expected properties.-const Template = ({ label, ...args }: Record<string, string>) => { +interface TemplateProps { + label?: string; + [key: string]: string | undefined; +} +const Template = ({ label, ...args }: TemplateProps) => {
51-56: Improve type safety in event handling.The event handling code uses
anytype in several places. Consider creating proper interfaces for the change objects.- graph.model.addListener(InternalEvent.CHANGE, (_sender: any, evt: EventObject) => { +interface GeometryChange { + geometry: unknown; + previous: unknown; +} + graph.model.addListener(InternalEvent.CHANGE, (_sender: unknown, evt: EventObject) => { const changes = evt.getProperty('changes'); const hasMoveEdits = changes?.some( - (c: any) => typeof c.geometry !== 'undefined' && typeof c.previous !== 'undefined' + (c: GeometryChange) => typeof c.geometry !== 'undefined' && typeof c.previous !== 'undefined'
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/core/src/util/cloneUtils.ts(2 hunks)packages/html/stories/Manhattan.stories.ts(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/core/src/util/cloneUtils.ts
🔇 Additional comments (1)
packages/html/stories/Manhattan.stories.ts (1)
76-80: LGTM! Good improvements to variable declarations and naming.The changes to use
constand more descriptive vertex names improve code readability and maintainability.
|



Introduce a dedicated
ManhattanConnectorConfigglobal object and its companion reset function.Also migrate the Manhattan story to TypeScript for easier maintenance. Make its code more robust and make better use of the maxGraph API.
BREAKING CHANGES:
ManhattanConnectoris now configured with the globalManhattanConnectorConfigobject.The following properties that were previously on
EdgeStylehave moved toManhattanConnectorConfig:MANHATTAN_END_DIRECTIONStoendDirectionsMANHATTAN_MAX_ALLOWED_DIRECTION_CHANGEtomaxAllowedDirectionChangeMANHATTAN_MAXIMUM_LOOPStomaxLoopsMANHATTAN_START_DIRECTIONStostartDirectionsMANHATTAN_STEPtostepSummary by CodeRabbit
Summary by CodeRabbit
New Features
ManhattanConnectorConfigandresetManhattanConnectorConfigfor enhanced routing configuration.Refactor
shallowCopyfunction to improve array handling.Tests
resetManhattanConnectorConfigfunctionality to ensure proper behavior after modification.Documentation