Skip to content

refactor!: expose all exported functions in namespaces#740

Merged
tbouffard merged 4 commits intomainfrom
refactor/exported_functions_in_namespace
Mar 31, 2025
Merged

refactor!: expose all exported functions in namespaces#740
tbouffard merged 4 commits intomainfrom
refactor/exported_functions_in_namespace

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Mar 30, 2025

Introduce guiUtils and requestUtils to hold functions that previously lived alone.
By convention, only the global configuration functions live outside a namespace.

BREAKING CHANGES: some functions are now accessible via a namespace:

  • get, getAll, load, post, submit via requestUtils
  • error, popup via guiUtils

Summary by CodeRabbit

  • New Features
    • Introduced new utility functions for making HTTP requests and displaying pop-up messages.
  • Refactor
    • Enhanced modularity by reorganizing utility functions into dedicated namespaces for better access and management.
  • Documentation
    • Updated release notes to reflect the new organization of user-facing functionalities and improved clarity on available methods.
  • Bug Fixes
    • Adjusted import paths to ensure proper functionality after the reorganization of utility functions.

Introduce `guiUtils` and `requestUtils` to hold functions that previously lived alone.
By convention, only the global configuration functions live outside a namespace.

BREAKING CHANGES: some functions are now accessible via a namespace:
  - `get`, `getAll`, `load`, `submit` via `requestUtils`
  - `error`, `popup` via `guiUtils`
@tbouffard tbouffard added the refactor Code refactoring label Mar 30, 2025
@coderabbitai
Copy link

coderabbitai bot commented Mar 30, 2025

Walkthrough

The changes restructure the codebase by organizing utility functions into two new namespaces: requestUtils and guiUtils. Functions handling HTTP requests (e.g., get, getAll, load, submit) and GUI pop-ups (e.g., error, popup) have been migrated to these modules. Consequently, multiple files now update their import/export paths to reference the new modules, while legacy functions in files like MaxXmlRequest.ts and MaxWindow.ts have been removed or refactored. Documentation and example code have also been updated to reflect these changes.

Changes

File(s) Change Summary
CHANGELOG.md Added section detailing accessible functions via requestUtils (get, getAll, load, submit) and guiUtils (error, popup); previous breaking changes remain unchanged.
packages/core/src/editor/Editor.ts, packages/core/src/i18n/Translations.ts, packages/core/src/serialization/ObjectCodec.ts Updated import paths to use ../util/requestUtils and ../gui/guiUtils instead of legacy modules.
packages/core/src/gui/MaxLog.ts, packages/html/stories/HelloPort.stories.ts, packages/html/stories/JsonData.stories.ts, packages/html/stories/UserObject.stories.ts Modified imports so that popup functionality is accessed via guiUtils instead of from MaxWindow.
packages/core/src/gui/MaxWindow.ts Removed exported functions popup and error and updated the class export to default, removing unused imports.
packages/core/src/gui/guiUtils.ts New file added with implementations of popup and error functions for managing GUI pop-up windows and error displays.
packages/core/src/util/MaxXmlRequest.ts Removed exported functions (load, get, getAll, post, submit), updated comments and examples, and modified the class export.
packages/core/src/util/requestUtils.ts New file added containing utility functions for HTTP requests (load, get, getAll, post, submit) utilizing the MaxXmlRequest class.
packages/core/src/index.ts Replaced direct exports with namespace exports (guiUtils and requestUtils) for better organization.
packages/html/stories/FileIO.stories.ts, packages/html/stories/Stencils.stories.ts, packages/html/stories/SwimLanes.stories.ts Updated import statements and function calls to use the new utility namespaces, reflecting the module reorganization.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant guiUtils
    participant MaxWindow
    Caller->>guiUtils: call popup(content, isInternalWindow)
    alt isInternalWindow true
        guiUtils->>MaxWindow: Create and display internal window with content
        MaxWindow-->>guiUtils: Confirm window is displayed
    else
        guiUtils->>Browser: Attempt to open new browser window
        Browser-->>guiUtils: Return window handle or error
    end
Loading
sequenceDiagram
    participant Caller
    participant requestUtils
    participant MaxXmlRequest
    Caller->>requestUtils: call load(url)
    requestUtils->>MaxXmlRequest: Create a request with URL
    MaxXmlRequest-->>requestUtils: Return request instance
    requestUtils-->>Caller: Provide instance for further processing
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 (5)
packages/core/src/util/MaxXmlRequest.ts (1)

24-26: Documentation references to removed functions are outdated.

The documentation still references functions that have been moved to requestUtils namespace (get, getAll, post, and load). While these references are now likely maintained in the new module, keeping them here could mislead developers.

Consider updating the documentation to reference these functions through the new namespace:

- See also {@link get}, {@link getAll}, {@link post} and {@link load}.
+ See also {@link requestUtils.get}, {@link requestUtils.getAll}, {@link requestUtils.post} and {@link requestUtils.load}.
packages/core/src/gui/guiUtils.ts (1)

33-87: Successfully relocated popup function.

The popup function has been properly moved from MaxWindow.ts to the new guiUtils namespace. The function maintains its original behavior while now being part of a more logical grouping of GUI-related utilities.

However, there's an inconsistency in the error message format between the branches of the conditional.

-wnd.document.writeln(`<pre>${htmlEntities(content)}</pre`);
+wnd.document.writeln(`<pre>${htmlEntities(content)}</pre>`);
packages/core/src/util/requestUtils.ts (3)

81-86: Consider using specific function types.

The static analysis tool correctly identifies the use of generic Function types as a potential issue. Using more specific function types would improve type safety.

Consider replacing generic Function types with more specific function signatures:

-  onload: Function | null = null,
-  onerror: Function | null = null,
+  onload: ((req: MaxXmlRequest) => void) | null = null,
+  onerror: ((req: MaxXmlRequest) => void) | null = null,
-  ontimeout: Function | null = null,
+  ontimeout: ((req: MaxXmlRequest) => void) | null = null,

And similarly for the other functions in this file.

🧰 Tools
🪛 Biome (1.9.4)

[error] 81-81: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 82-82: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 85-85: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


117-158: Comprehensive implementation of getAll function.

The getAll function properly handles multiple asynchronous requests and manages the response aggregation appropriately.

Consider a small improvement to use strict equality operators for consistency:

-          if (remain == 0) {
+          if (remain === 0) {
-    if (errors == 0 && onerror != null) {
+    if (errors === 0 && onerror != null) {
-  if (remain == 0) {
+  if (remain === 0) {

180-187: Properly implemented post function.

The post function correctly implements asynchronous POST requests, maintaining a fluent interface by returning the request object.

Similar to the get function, consider using more specific function types for improved type safety:

-  onload: Function,
-  onerror: Function | null = null
+  onload: (req: MaxXmlRequest) => void,
+  onerror: ((req: MaxXmlRequest) => void) | null = null
🧰 Tools
🪛 Biome (1.9.4)

[error] 183-183: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 184-184: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a9f70a and 95e9ba2.

📒 Files selected for processing (16)
  • CHANGELOG.md (1 hunks)
  • packages/core/src/editor/Editor.ts (3 hunks)
  • packages/core/src/gui/MaxLog.ts (1 hunks)
  • packages/core/src/gui/MaxWindow.ts (2 hunks)
  • packages/core/src/gui/guiUtils.ts (1 hunks)
  • packages/core/src/i18n/Translations.ts (1 hunks)
  • packages/core/src/index.ts (1 hunks)
  • packages/core/src/serialization/ObjectCodec.ts (1 hunks)
  • packages/core/src/util/MaxXmlRequest.ts (1 hunks)
  • packages/core/src/util/requestUtils.ts (1 hunks)
  • packages/html/stories/FileIO.stories.ts (3 hunks)
  • packages/html/stories/HelloPort.stories.ts (2 hunks)
  • packages/html/stories/JsonData.stories.ts (2 hunks)
  • packages/html/stories/Stencils.stories.ts (2 hunks)
  • packages/html/stories/SwimLanes.stories.ts (1 hunks)
  • packages/html/stories/UserObject.stories.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/core/src/util/requestUtils.ts (1)
packages/core/src/util/MaxXmlRequest.ts (2)
  • MaxXmlRequest (86-378)
  • setRequestHeaders (311-315)
🪛 Biome (1.9.4)
packages/core/src/util/requestUtils.ts

[error] 81-81: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 82-82: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 85-85: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 183-183: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 184-184: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (windows-2022)
🔇 Additional comments (30)
packages/core/src/util/MaxXmlRequest.ts (3)

22-22: Documentation updated to clarify MaxXmlRequest's role.

The description now clearly states that MaxXmlRequest is an XML HTTP request wrapper, which better reflects its purpose.


38-41: Example code updated to use modern JavaScript syntax.

Good use of modern JavaScript conventions with const instead of var and using window.alert for better clarity.


86-86: Class export declaration moved to the beginning.

The class is now properly declared with export default at its definition rather than at the end of the file, which is a better practice.

packages/core/src/i18n/Translations.ts (1)

22-22: Import statement updated to use new namespace structure.

The get and load functions are now imported from requestUtils instead of MaxXmlRequest, aligning with the PR objective of moving utility functions into appropriate namespaces.

packages/core/src/serialization/ObjectCodec.ts (1)

25-25: Import statement updated to use new namespace structure.

The load function is now imported from requestUtils instead of MaxXmlRequest, aligning with the PR objective of moving utility functions into appropriate namespaces.

packages/core/src/gui/MaxLog.ts (1)

23-23: Import statements updated to use new namespace structure.

The popup function is now imported from guiUtils instead of MaxWindow, aligning with the PR objective of moving utility functions into appropriate namespaces.

Also applies to: 28-28

packages/html/stories/UserObject.stories.ts (2)

32-32: Import updated to use the new namespace structure.

The import has been updated to use the new guiUtils namespace instead of directly importing the popup function, which aligns with the PR's goal of reorganizing utility functions into namespaces.


186-186: Function call updated to use the new namespace.

The popup function call has been properly updated to use the guiUtils.popup namespace access pattern, maintaining the same functionality while following the new code organization structure.

packages/html/stories/SwimLanes.stories.ts (1)

65-65: Updated commented-out code to match new namespace structure.

Even though this is commented-out code, it's good practice to keep it aligned with current code patterns. The reference has been updated from utils to requestUtils, which matches the namespace refactoring described in the PR objectives.

packages/html/stories/Stencils.stories.ts (2)

31-31: Import updated to use the new namespace.

The import statement now correctly references the requestUtils namespace instead of directly importing the load function, which aligns with the PR's goal of better organizing utility functions.


172-172: Function call updated to use the namespace access pattern.

The load function call has been properly updated to use the requestUtils.load namespace pattern, maintaining the same functionality while following the new code organization structure.

CHANGELOG.md (1)

16-18: Well-documented breaking changes in the CHANGELOG.

The breaking changes section has been clearly updated to document that functions have been moved to namespaces. This provides users with the information needed to adapt their code to the new structure:

  • HTTP request utilities (get, getAll, load, submit) are now under the requestUtils namespace
  • GUI-related utilities (error, popup) are now under the guiUtils namespace

This documentation is essential for users upgrading to the new version.

packages/html/stories/FileIO.stories.ts (3)

28-28: Updated import to use the new requestUtils namespace.

The import has been updated to use the new requestUtils namespace instead of the standalone load function.


149-149: Function call updated to use requestUtils namespace.

The load function is now being accessed through the requestUtils namespace.


195-195: Function call updated to use requestUtils namespace.

The load function is now being accessed through the requestUtils namespace, consistent with the previous update.

packages/core/src/editor/Editor.ts (3)

31-31: Updated import statement for MaxWindow.

The import for MaxWindow has been modified to no longer import the error function, as it's now imported from a different module.


48-48: Updated import statement for request utilities.

The import for load, post, and submit functions has been updated to use the new requestUtils namespace.


61-61: Added import for error function from guiUtils.

The error function is now imported from the guiUtils namespace, consistent with the refactoring goal.

packages/html/stories/JsonData.stories.ts (2)

25-25: Updated import to use guiUtils namespace.

The import has been updated to use the new guiUtils namespace instead of the standalone popup function.


109-109: Function call updated to use guiUtils namespace.

The popup function is now being accessed through the guiUtils namespace.

packages/html/stories/HelloPort.stories.ts (2)

25-25: Updated import to use guiUtils namespace.

The import has been updated to use the new guiUtils namespace instead of the standalone popup function.


125-125: Function call updated to use guiUtils namespace.

The popup function is now being accessed through the guiUtils namespace, consistent with the PR's goal of organizing utility functions into namespaces.

packages/core/src/index.ts (2)

182-182: New namespace export for GUI utilities.

The new guiUtils namespace properly groups related GUI utility functions, making them more discoverable and organized.


190-190: New namespace export for request utilities.

The new requestUtils namespace appropriately organizes HTTP request-related functions, aligning with the PR objectives to group exported functions into namespaces.

packages/core/src/gui/MaxWindow.ts (1)

178-178: Export class as default correctly.

The change to export MaxWindow as a default export is appropriate and consistent with the modular approach being adopted in this PR. This maintains the class's accessibility while allowing the utility functions to be moved to their dedicated namespace.

packages/core/src/gui/guiUtils.ts (2)

19-26: Appropriate imports for utility functions.

The imports are correctly organized and include all necessary dependencies for the relocated functions. This ensures that the utility functions maintain their functionality in the new location.


99-157: Successfully relocated error function.

The error function has been properly moved from MaxWindow.ts to the new guiUtils namespace. The function maintains its original behavior for displaying error messages in a window.

packages/core/src/util/requestUtils.ts (3)

19-20: Import MaxXmlRequest for request utilities.

The import is properly set up to allow the utility functions to create and manipulate MaxXmlRequest instances.


40-44: Well-documented load function.

The load function is well-documented with appropriate examples and correctly implements synchronous URL loading.


198-200: Correctly implemented submit function.

The submit function properly uses the simulate method of MaxXmlRequest to submit parameters via a form.

Comment on lines +79 to +106
export const get = (
url: string,
onload: Function | null = null,
onerror: Function | null = null,
binary = false,
timeout: number | null = null,
ontimeout: Function | null = null,
headers: { [key: string]: string } | null = null
) => {
const req = new MaxXmlRequest(url, null, 'GET');
const { setRequestHeaders } = req;

if (headers) {
req.setRequestHeaders = (request, params) => {
setRequestHeaders.apply(this, [request, params]);
for (const key in headers) {
request.setRequestHeader(key, headers[key]);
}
};
}

if (binary != null) {
req.setBinary(binary);
}

req.send(onload, onerror, timeout, ontimeout);
return req;
};
Copy link

@coderabbitai coderabbitai bot Mar 30, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improved get function with header support.

The get function implementation enhances the original functionality with proper header handling. The function correctly overrides the setRequestHeaders method to include custom headers while maintaining the original behavior.

However, I noticed a potential issue with the this context in the headers handling code:

-    setRequestHeaders.apply(this, [request, params]);
+    setRequestHeaders.apply(req, [request, params]);

The current implementation uses this which is incorrect in this context. It should use req to ensure the method is called with the correct context.

📝 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.

Suggested change
export const get = (
url: string,
onload: Function | null = null,
onerror: Function | null = null,
binary = false,
timeout: number | null = null,
ontimeout: Function | null = null,
headers: { [key: string]: string } | null = null
) => {
const req = new MaxXmlRequest(url, null, 'GET');
const { setRequestHeaders } = req;
if (headers) {
req.setRequestHeaders = (request, params) => {
setRequestHeaders.apply(this, [request, params]);
for (const key in headers) {
request.setRequestHeader(key, headers[key]);
}
};
}
if (binary != null) {
req.setBinary(binary);
}
req.send(onload, onerror, timeout, ontimeout);
return req;
};
export const get = (
url: string,
onload: Function | null = null,
onerror: Function | null = null,
binary = false,
timeout: number | null = null,
ontimeout: Function | null = null,
headers: { [key: string]: string } | null = null
) => {
const req = new MaxXmlRequest(url, null, 'GET');
const { setRequestHeaders } = req;
if (headers) {
req.setRequestHeaders = (request, params) => {
- setRequestHeaders.apply(this, [request, params]);
+ setRequestHeaders.apply(req, [request, params]);
for (const key in headers) {
request.setRequestHeader(key, headers[key]);
}
};
}
if (binary != null) {
req.setBinary(binary);
}
req.send(onload, onerror, timeout, ontimeout);
return req;
};
🧰 Tools
🪛 Biome (1.9.4)

[error] 81-81: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 82-82: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 85-85: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

Copy link
Member Author

Choose a reason for hiding this comment

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

This remarks seems valid.
However, here we are only moving existing code and we don't want to change any implementation which would be out of topic.
The suggestion may be taken into account in the future.

Copy link

Choose a reason for hiding this comment

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

@tbouffard I understand your approach. Focusing on code reorganization first while maintaining the exact implementation is a sound strategy. It keeps the PR's scope clear and makes changes easier to review. Thanks for explaining the context.


✏️ Learnings added
Learnt from: tbouffard
PR: maxGraph/maxGraph#740
File: packages/core/src/util/requestUtils.ts:79-106
Timestamp: 2025-03-31T08:32:16.906Z
Learning: PR #740 is focused on reorganizing code into namespaces (guiUtils and requestUtils) without changing any implementations. Implementation improvements should be suggested for future PRs.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link

@coderabbitai coderabbitai bot left a 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 (1)
CHANGELOG.md (1)

16-18: Clarify Namespace Refactoring in Breaking Changes

The new changelog section clearly states that several utility functions are now accessible through the requestUtils and guiUtils namespaces. This documentation aligns with the PR objectives by informing users of the breaking change and the new access paths. Consider adding the version number or date when these changes were introduced for further clarity, which would help users track when to update their code references.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95e9ba2 and ff72c9b.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • packages/core/src/util/MaxXmlRequest.ts (1 hunks)
🔇 Additional comments (12)
packages/core/src/util/MaxXmlRequest.ts (12)

22-22: Improved class description clarity.

The updated description more clearly describes the purpose of this class as an XML HTTP request wrapper.


32-36: Documentation formatting improvements.

The HTML example is now properly formatted as a code block, which improves readability.


38-41: Modernized example code.

The example code has been updated to use const instead of var and window.alert instead of mxUtils.alert, which aligns with modern JavaScript practices.


43-45: Modernized error handler example.

Similar to the previous example, this code has been updated to use modern JavaScript conventions.


49-50: Improved documentation section header formatting.

The "Sending requests" section header is now properly formatted, which improves readability.


54-58: Modernized synchronous request example.

The example has been updated to use const instead of var and window.alert, following modern JavaScript practices.


63-68: Updated encoder example with modern syntax.

The example has been modernized to use const instead of var and template literals, which aligns with current JavaScript best practices.


79-81: Improved Java example for XML processing.

The Java example now correctly shows how to handle XML entities when processing the response, replacing newlines with the appropriate XML entity.


83-84: Clarified comment about linefeed replacement.

The comment now clearly explains when linefeed replacements should be applied in Java processing scenarios.


85-85: Changed export declaration style.

The class MaxXmlRequest is now exported using the export default class syntax at the class declaration instead of at the end of the file, which is a more modern and consistent approach.


1-377:

Details

✅ Verification successful

Verify all uses of removed functions have been updated.

Based on the PR objectives and AI summary, functions like load, get, getAll, post, and submit have been moved to the new requestUtils namespace. Let's verify that all imports in dependent files have been updated to reference these functions from the new namespace.


🏁 Script executed:

#!/bin/bash
# Search for any remaining direct imports from MaxXmlRequest that might need to be updated
echo "Checking for imports from MaxXmlRequest..."
rg -A 3 "import.*from ['\"]\.\./util/MaxXmlRequest['\"]" --glob "*.ts" --glob "*.tsx"

# Check for any uses of the old functions that might not have been updated
echo "Checking for potentially missed function usages..."
rg "\b(get|getAll|load|submit|post)\(" --glob "*.ts" --glob "*.tsx" | grep -v "requestUtils" | grep -v "MaxXmlRequest.ts"

Length of output: 10727


All network request function updates verified

The verification confirms that the removed functions from MaxXmlRequest (i.e., load, get, getAll, post, and submit) have been correctly migrated. In particular:

  • In packages/core/src/i18n/Translations.ts, the old direct import from MaxXmlRequest is now a type import, and the functional imports (get, load) are correctly sourced from the new requestUtils namespace.
  • The search did not uncover any remaining call sites referencing the removed functions in a problematic way—most instances of methods like get() and load() in other files belong to unrelated, context-specific utilities or local implementations.

No further changes appear necessary.

🧰 Tools
🪛 Biome (1.9.4)

[error] 121-121: Expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found ':'.

Expected an identifier, a string literal, a number literal, a private field name, or a computed name here.

(parse)


[error] 253-253: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 254-254: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 256-256: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


24-26:

Details

✅ Verification successful

Verify that the referenced utility functions exist in requestUtils.

The documentation still references get, getAll, post, and load functions which were removed from this file. Since this PR moves these functions to a new requestUtils namespace, ensure they're properly implemented there.


🏁 Script executed:

#!/bin/bash
# Check if the removed functions exist in the requestUtils.ts file
echo "Checking for requestUtils.ts file..."
fd -t f "requestUtils.ts" --exec grep -E "export function (get|getAll|post|load|submit)" {} \;

Length of output: 180


Please run the above script to verify if the utility functions (get, getAll, post, load) are exported from the requestUtils.ts file using alternative export syntaxes (e.g., as arrow functions or const assignments). If this script still produces no output, then manual verification is required to confirm that these functions are implemented as part of the new requestUtils namespace.


🏁 Script executed:

#!/bin/bash
echo "Searching for exported functions (using various export syntaxes) for get, getAll, post, load in requestUtils.ts..."
fd -t f "requestUtils.ts" --exec grep -E "export\s+(function|const|let)\s+(get|getAll|post|load)\b" {} \;

Length of output: 468


Verified: The utility functions are now correctly implemented in the requestUtils.ts file.

  • The functions get, getAll, post, and load are all properly exported as shown by the grep output.
  • Please ensure that the documentation references (e.g., the @link annotations) in MaxXmlRequest.ts are updated if necessary to point to their new location in the requestUtils namespace.

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a 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 (2)
packages/core/src/gui/guiUtils.ts (2)

33-86: Refine the popup function handling & consider merging the duplicated window logic.

Overall, the logic for displaying content in an internal or external window is clean. However, both code paths (lines 69–75 vs. 76–85) contain nearly identical steps for opening a window and inserting content. In a future refactor, consolidating the repeated logic could simplify maintenance. Additionally, some styling details (e.g., fixed widths and heights, scrollbar usage) may benefit from a more responsive or configurable approach.


99-157: Use CSS instead of the non-standard valign HTML attribute & consider small naming adjustments.

The error display function is well-structured, with proper image and optional close button logic. However, note that 'valign' is not a standard HTML5 attribute (line 110). Replacing it with a CSS approach (e.g., vertical-align: bottom;) preserves cross-browser compatibility. Also, you might consider renaming warn to something more descriptive like errorWindow for clarity. Implementation updates can be safely tackled in a later PR, as the function is otherwise correct.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff72c9b and 4e87ab0.

📒 Files selected for processing (1)
  • packages/core/src/gui/guiUtils.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: tbouffard
PR: maxGraph/maxGraph#740
File: packages/core/src/util/requestUtils.ts:79-106
Timestamp: 2025-03-31T08:32:17.055Z
Learning: PR #740 is focused on reorganizing code into namespaces (guiUtils and requestUtils) without changing any implementations. Implementation improvements should be suggested for future PRs.

@tbouffard tbouffard merged commit 5f20e56 into main Mar 31, 2025
2 checks passed
@tbouffard tbouffard deleted the refactor/exported_functions_in_namespace branch March 31, 2025 08:39
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