Skip to content

chore: Add code-split for widget refactoring in UI module #40226

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

Merged

Conversation

subrata71
Copy link
Contributor

@subrata71 subrata71 commented Apr 11, 2025

Description

EE Counterpart: https://github.com/appsmithorg/appsmith-ee/pull/7143

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/14404193022
Commit: 5585f90
Cypress dashboard.
Tags: @tag.All
Spec:


Fri, 11 Apr 2025 14:44:36 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced context-aware layout management that enhances page design updates and dynamic refactoring.
    • Added improved handling for layout and widget updates, offering a smoother editing experience.
  • Refactor

    • Streamlined layout update processes with adaptive behavior based on context.
    • Optimized service interactions for more robust and modular page and widget processing.

Copy link
Contributor

coderabbitai bot commented Apr 11, 2025

Walkthrough

Several refactorings have been made across layout and refactoring services. A new LayoutContainer interface was introduced and integrated into existing DTOs. The update layout methods now accept a new CreatorContextType parameter and use a context-based resolver instead of directly depending on the application service. New classes and interfaces for context-aware layout refactoring have been added along with modifications in widget and on-load executable services. Test classes have also been updated to reflect these dependency and method signature changes.

Changes

File(s) Change Summary
.../domains/ce/LayoutContainer.java
.../dtos/PageDTO.java
Added new LayoutContainer interface with getLayouts(), setLayouts(List<Layout>), getId() methods; updated PageDTO to implement the interface.
.../layouts/UpdateLayoutServiceCE.java
.../layouts/UpdateLayoutServiceCEImpl.java
.../layouts/UpdateLayoutServiceImpl.java
Updated updateLayout method signature to include CreatorContextType; changed dependency from ApplicationService to ContextLayoutRefactorResolver; modified access modifier of updateLayoutDsl (private → protected).
.../newpages/refactors/PageLayoutRefactoringServiceImpl.java
.../refactors/ContextLayoutRefactoringService.java
Introduced a new page layout refactoring service and interface with multiple methods for managing layout contexts and evaluation versions.
.../refactors/resolver/ContextLayoutRefactorResolver.java
.../refactors/resolver/ContextLayoutRefactorResolverCE.java
Added new resolver classes that provide a helper method to retrieve the context layout refactoring service.
.../onload/internal/OnLoadExecutablesUtilCEImpl.java Updated multiple method signatures to include a new creatorType (or contextType) parameter and route service calls through getExecutableOnLoadService(creatorType).
.../refactors/applications/RefactoringServiceCEImpl.java
.../refactors/applications/RefactoringServiceImpl.java
Refactored the refactorName logic to use context-based methods; updated constructor dependencies to include ContextLayoutRefactorResolver and removed obsolete parameters.
.../widgets/refactors/WidgetRefactoringServiceCEImpl.java
.../widgets/refactors/WidgetRefactoringServiceImpl.java
Modified widget refactoring services by replacing removed dependencies with ContextLayoutRefactorResolver; updated constructor parameters accordingly.
.../refactors/ce/RefactoringServiceCEImplTest.java Updated tests to inject ContextLayoutRefactorResolver and modified invocations of updateLayout to match the new method signature with an extra parameter.

Sequence Diagram(s)

sequenceDiagram
  participant C as Client
  participant U as UpdateLayoutServiceImpl
  participant R as ContextLayoutRefactorResolver
  participant D as LayoutUpdateHelper

  C->>U: updateLayout(pageId, applicationId, layoutId, layout, contextType)
  activate U
  U->>R: getContextLayoutRefactorHelper(contextType)
  activate R
  R-->>U: returns ContextLayoutRefactoringService
  alt Page/Module Context
    U->>D: updateLayoutDsl(...)
  else Default Processing
    U->>U: process layout update normally
  end
  U-->>C: LayoutDTO response
  deactivate U
Loading
sequenceDiagram
  participant Cl as Caller
  participant O as OnLoadExecutablesUtilCEImpl
  participant S as ExecutableOnLoadService

  Cl->>O: findAllOnLoadExecutables(..., creatorType)
  activate O
  O->>O: getExecutableOnLoadService(creatorType)
  O->>S: Forward request with creatorType
  S-->>O: Executable list response
  O-->>Cl: Return updated executables
  deactivate O
Loading

Poem

In the code where layouts reside,
New interfaces and methods now guide.
Context flows and refactoring so bright,
Resolvers assist, making updates light.
Tests and services in joyful sync 😄,
A code symphony on the brink.
Happy refactoring—smooth as ink!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

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

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.

@subrata71 subrata71 added the ok-to-test Required label for CI label Apr 11, 2025
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Apr 11, 2025
Copy link
Contributor

@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 (18)
app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCE.java (1)

17-19: Consider providing JavaDoc for the new overloaded method.
This method overload is helpful for context-aware layouts. Adding documentation about how CreatorContextType affects the update process would benefit maintainability.

app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceCEImpl.java (6)

4-4: Streamline Unused Imports.
Double-check if BaseDomain import is essential here. If it’s only referenced in the generic signature, that’s fine; otherwise, consider removing.


30-30: Check for additional context types.
The static import for isModuleContext complements the existing isPageContext. Confirm whether new context types may emerge, and handle them gracefully.


48-49: Consider fallback handling.
Returning empty for non-page non-module contexts is safe, but ensure no other context type is missed or incorrectly handled.


58-59: Efficient pattern usage.
Storing updatedBindingPaths and oldNamePattern is sensible. Confirm that no concurrency requires thread-safe data structures here.


120-123: Flux-based approach for entity names.
Returning a flux from a context-based mono ensures correct handling of multiple names if needed. Watch out for blocking calls or large name sets.


124-133: Casting context objects.
Casting to LayoutContainer is safe if guaranteed by design. Consider an instanceof check with fallback to prevent unforeseen cast exceptions.

app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/ce/RefactoringServiceCEImplTest.java (1)

94-95: Resolver test coverage.
Having a spy on contextLayoutRefactorResolver is useful for verifying correct context-based refactoring calls. Ensure coverage extends to edge contexts.

app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/ContextLayoutRefactoringService.java (2)

22-46: Update and retrieval methods.
Methods updateContext and getContextDTOMono comprehensively handle context updates and retrieval in both published and unpublished modes.


67-83: Layout extraction and updates.
getLayouts and updateLayoutByContextId methods offer a straightforward approach. Confirm concurrency handling if multiple updates happen at once.

app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java (1)

251-252: TODO comment added.

Don’t forget to replace the overloaded updateLayout usage as noted.

Shall I open a new ticket to address this TODO?

app/server/appsmith-server/src/main/java/com/appsmith/server/newpages/refactors/PageLayoutRefactoringServiceImpl.java (5)

37-39: Check for null context
In getContextDTOMono(String contextId, boolean viewMode), you call findPageById directly. If contextId is empty or null, findPageById might return an error immediately. Ensure upstream callers always supply a valid contextId, or add an early null check.


41-44: Consider early validation
getContextDTOMono(RefactoringMetaDTO refactoringMetaDTO) simply returns pageDTOMono from refactoringMetaDTO. If pageDTOMono is null or out of date (e.g., never set), it could lead to an unexpected empty result. Consider adding an assertion or fallback for better error messages.


46-59: Validate page.getApplicationId()
Within getEvaluationVersionMono(...), if page.getApplicationId() is null or invalid, applicationService.findById may fail. You might include a null guard or a more descriptive error for diagnosing issues quickly.


77-83: Potential null return
getLayouts(...) can return null if updatedPage is absent. Returning an empty List instead of null often simplifies calling code by removing the need for null checks.

- return null;
+ return Collections.emptyList();

86-90: Plan future implementation
updateLayoutByContextId is not implemented yet. Prepare a TODO or implement to avoid accidental usage. If this is intentional, clarify in the documentation.

Do you want help creating a stubbed-out implementation or opening a tracking issue?

app/server/appsmith-server/src/main/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImpl.java (2)

424-424: Check null layout
findAndUpdateLayout(...) directly delegates to findAndUpdateLayout(creatorId, layoutId, layout). If layout can be null, the delegating method might fail. Consider a pre-check or graceful handling.


1480-1481: Unused parameter
getExecutableOnLoadService(CreatorContextType contextType) unconditionally returns pageExecutableOnLoadService. If you plan to support multiple services, implement the logic to select them here. Otherwise, consider removing the unused parameter.

-protected ExecutableOnLoadService<?> getExecutableOnLoadService(CreatorContextType contextType) {
+protected ExecutableOnLoadService<?> getExecutableOnLoadService() {
    return pageExecutableOnLoadService;
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7cdee43 and 5585f90.

📒 Files selected for processing (15)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/LayoutContainer.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/PageDTO.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java (5 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/newpages/refactors/PageLayoutRefactoringServiceImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImpl.java (13 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/ContextLayoutRefactoringService.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCEImpl.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/resolver/ContextLayoutRefactorResolver.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/resolver/ContextLayoutRefactorResolverCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceCEImpl.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceImpl.java (1 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/ce/RefactoringServiceCEImplTest.java (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/resolver/ContextLayoutRefactorResolver.java (4)
app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceImpl.java (1)
  • Service (14-37)
app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceImpl.java (1)
  • Service (16-42)
app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/resolver/ContextLayoutRefactorResolverCE.java (1)
  • Service (9-21)
app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceImpl.java (1)
  • Service (9-18)
app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceCEImpl.java (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCEImpl.java (1)
  • Slf4j (40-299)
app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java (1)
  • Slf4j (65-668)
app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceImpl.java (5)
app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCEImpl.java (1)
  • Slf4j (40-299)
app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceImpl.java (1)
  • Service (14-37)
app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/resolver/ContextLayoutRefactorResolver.java (1)
  • Service (8-13)
app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/resolver/ContextLayoutRefactorResolverCE.java (1)
  • Service (9-21)
app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceImpl.java (1)
  • Service (9-18)
app/server/appsmith-server/src/main/java/com/appsmith/server/newpages/refactors/PageLayoutRefactoringServiceImpl.java (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCEImpl.java (1)
  • Slf4j (40-299)
app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java (1)
  • Slf4j (65-668)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: server-unit-tests / server-unit-tests
  • GitHub Check: server-spotless / spotless-check
🔇 Additional comments (53)
app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/PageDTO.java (1)

8-8: Appropriate interface implementation

The PageDTO class now correctly implements the LayoutContainer interface. This implementation makes the relationship between PageDTO and layouts explicit, enabling better type safety in the refactoring services.

Also applies to: 30-30

app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/resolver/ContextLayoutRefactorResolver.java (1)

1-13: Clean class implementation

This implementation extends ContextLayoutRefactorResolverCE, following the standard pattern for service implementation. The constructor correctly passes the pageLayoutRefactorService to the superclass.

app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/LayoutContainer.java (1)

1-13: Well-designed interface

The LayoutContainer interface is cohesive and follows the Interface Segregation Principle, containing only methods related to layout management. This abstraction will enable more flexible refactoring operations across different layout-containing entities.

app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/resolver/ContextLayoutRefactorResolverCE.java (2)

1-17: Clean resolver base class

The ContextLayoutRefactorResolverCE class is well-structured with appropriate dependency injection. It follows the Spring service pattern correctly.


18-20:

✅ Verification successful

Prepared for future context types

The method parameter contextType is currently unused since it always returns pageLayoutRefactorService regardless of the context type. This suggests the method is designed for future extensibility when more context types might be supported.


🏁 Script executed:

#!/bin/bash
# Check if there are other implementations of ContextLayoutRefactoringService besides the one for PageDTO
echo "Checking for potential future implementations of ContextLayoutRefactoringService..."
rg -B 1 -A 1 "class .* implements ContextLayoutRefactoringService" --type java

Length of output: 776


Future-Proofing Verified

  • The contextType parameter in getContextLayoutRefactorHelper remains unused, consistent with the current implementation.
  • The repository search confirms that PageLayoutRefactoringServiceImpl is the only implementation of ContextLayoutRefactoringService, aligning with the design for future extensibility.
  • No immediate changes are necessary as the method is correctly prepared for adding support for additional context types later.
app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceImpl.java (1)

14-16: Constructor refactoring looks good.
Removing unused services and introducing ContextLayoutRefactorResolver aligns with the context-based approach. Make sure there are no dangling references to the old services.

app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCEImpl.java (7)

17-19: Imports align with context-based refactoring.
These imports for ContextLayoutRefactoringService and ContextLayoutRefactorResolver appear correct and consistent with the new workflow.


53-53: Added dependency for context layout solver.
Declaring ContextLayoutRefactorResolver ensures a clean, centralized approach for context-aware layout handling.


73-73: Naming clarity.
Renaming to contextId is a good step toward distinguishing page-bound logic from generic context-based logic.


83-85: Dynamic evaluation version retrieval.
Injecting the correct evaluation version via contextLayoutRefactorResolver centralizes context logic, improving maintainability.


91-94: Refactored layout retrieval.
Fetching layouts through ContextLayoutRefactoringService fosters consistency and modular design.


99-99: Check for potential null artifactId.
Handle cases where no artifact exists, particularly if the refactoring context is incomplete or missing references.


101-106: Context-based layout update logic.
Passing contextId and CreatorContextType ensures the update flow remains adaptive to different contexts. No issues spotted in error handling, but confirm that all callers handle potential failures.

app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceCEImpl.java (10)

8-8: Validate LayoutContainer usage.
Ensure that all references and downcasts to LayoutContainer are safe and thoroughly tested, especially for contexts that might not produce a layout container.


14-14: Context-based refactoring utility.
The new ContextLayoutRefactoringService dependency appears to correctly modularize context-based layout refactoring. This separation enhances maintainability.


16-16: Resolver integration.
Using ContextLayoutRefactorResolver to conditionally fetch the correct helper promotes better extensibility for additional context types in the future.


35-38: Dependency injection.
The newly added resolver and utilities make the service more flexible. Verify that all are properly mocked or injected in tests.


45-45: Method override.
Refactoring references appears consistent with the EntityRefactoringServiceCE interface. Good alignment with the contract.


53-53: Context type assignment.
Ensure that this local CreatorContextType contextType is used consistently within the method to avoid confusion or overshadowing.


61-63: Improved modular approach.
Retrieving the correct refactoring helper for the given context promotes clean, decoupled logic.


65-68: Asynchronous context retrieval.
Fetching the context DTO with reactive semantics is aligned with upstream code style. Validate the presence of fallback values if context is unexpected.


135-136: Empty results for missing rules.
Returning an empty flux allows the calling code to handle no-results scenarios gracefully. This is a good pattern for reactive flows.


139-140: Proper error signaling.
Raising a specific error if no layout matches is clear and explicit, which aids debugging.

app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/ce/RefactoringServiceCEImplTest.java (4)

23-23: SpyBean usage.
Spying on ContextLayoutRefactorResolver helps verify interactions. Good approach for ensuring logic is triggered as expected.


114-115: Constructor consistency.
Adding contextLayoutRefactorResolver aligns the test with the new service injection. Ensure any other test coverage is updated accordingly.


173-173: Updated method signature.
The updateLayout call signature changed to accept extra parameters. Confirm all test references match these new arguments.


311-311: Method invocation with five params.
All references to updateLayout have been updated to reflect the new signature. Double-check that inputs for the new parameter are correct.

app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/ContextLayoutRefactoringService.java (3)

1-19: Well-defined interface structure.
This interface cleanly defines a contract for context-based layout refactoring, enhancing maintainability by segregating responsibilities.


48-65: Evaluation version retrieval.
Providing two separate methods to retrieve evaluation versions is clear. Ensure consistency with how the artifact ID is used in the rest of the codebase.


84-107: Metadata-based context ID and artifact retrieval.
Encapsulating ID extraction logic in the service is neat and ensures a single source of truth. The in-memory updates to metadata are also well structured.

app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceImpl.java (3)

6-6: New import introduced.

The addition of the ContextLayoutRefactorResolver import aligns with the wider context-based refactoring approach.


24-25: New constructor parameters added.

Injecting observationHelper and contextLayoutRefactorResolver is consistent with the refactoring strategy.


34-35: Passing new dependencies to superclass.

Forwarding the new parameters in the super call is properly handled and maintains the updated signature.

app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java (6)

23-23: Imported ContextLayoutRefactorResolver.

Importing the resolver indicates the service will handle context-based refactoring.


62-62: Imported isPageContext().

This helper method import suggests you’re branching logic based on context type.


78-78: Added field for contextLayoutRefactorResolver.

Declaring contextLayoutRefactorResolver as a final field ensures consistent usage throughout the service.


121-121: Visibility changed for updateLayoutDsl().

Using protected broadens its accessibility for potential subclass overrides.


264-272: New overloaded updateLayout with CreatorContextType.

Introducing an explicit context parameter promotes context-based branching for page vs. non-page scenarios.


255-258:

❓ Verification inconclusive

Passing null to the context refactor helper.

Verify that providing null as the CreatorContextType won’t cause unexpected fallback or logic issues.


🏁 Script executed:

#!/bin/bash
# Searching for calls to getContextLayoutRefactorHelper(null) to ensure there's a fallback
rg "getContextLayoutRefactorHelper\(null\)"

Length of output: 199


Verify that passing null to getContextLayoutRefactorHelper is safe

The grep search confirmed that the only instance of passing a null argument to getContextLayoutRefactorHelper is in the UpdateLayoutServiceCEImpl.java file (lines 255-258). Please double-check that the implementation of getContextLayoutRefactorHelper gracefully handles a null CreatorContextType without triggering unexpected fallback behavior or logic issues. It would also be beneficial to add or review unit tests to ensure that this behavior remains stable in the future.

app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceImpl.java (3)

9-9: Imported ContextLayoutRefactorResolver.

This aligns with the overall shift toward context-aware layout refactoring.


28-29: Constructor parameters updated.

Injecting widgetEntityRefactoringService and contextLayoutRefactorResolver paves the way for comprehensive refactoring flows.


39-40: Super call updated to accept new parameters.

Ensures the parent constructor receives the additional services for context-based refactoring without breaking existing flows.

app/server/appsmith-server/src/main/java/com/appsmith/server/newpages/refactors/PageLayoutRefactoringServiceImpl.java (3)

31-34: Ensure DTO Casting Safety
In updateContext(String contextId, LayoutContainer dto), you're casting dto to PageDTO before calling saveUnpublishedPage(). If a different LayoutContainer implementation is ever passed, this cast could fail at runtime. Consider validating the type and handling mismatches gracefully.

Can you confirm there are no external calls passing a non-PageDTO object to this method?


61-74: Graceful error handling
When findById(artifactId) returns an empty Mono, you raise an ACL error. Confirm this covers other potential causes, such as a missing or invalid artifact. If you expect different error scenarios, you could differentiate them for clarity.


105-108: Maintain symmetry between getters & setters
setUpdatedContext(...) updates updatedPage in refactoringMetaDTO. Verify that the rest of the codebase consistently uses this new updated context, and that no existing logic sets updatedPage in other ways, to prevent overwriting or confusion.

app/server/appsmith-server/src/main/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImpl.java (8)

170-171: No immediate concerns
Adding creatorType alongside evaluatedVersion ensures context-aware handling. This looks consistent with the rest of the parameter additions.


198-199: Consistent parameter usage
Similar to lines 170–171, adding creatorType here maintains consistency. Good job ensuring uniform handling across methods.


427-428: Type safety
updateUnpublishedExecutable(...) checks executable instanceof ActionDTO but not other potential subtypes. If new Executable types are introduced, consider broadening the condition or throwing a meaningful error.


431-431: Delegation is straightforward
Forwarding the call to getExecutableOnLoadService(contextType).updateUnpublishedExecutable(...) simplifies code. No issues noticed.


445-445: Context-based retrieval
getAllExecutablesByCreatorIdFlux(...) uses getExecutableOnLoadService(creatorType). Ensure the chosen service matches the creatorType. No further concerns here.


716-716: No issues with widget creation
Instantiating EntityDependencyNode with identical validEntityName and referenceString for widgets is acceptable if the code downstream does not differentiate them. Looks good.


750-760: Asynchronous chaining
Chaining multiple async calls inside addDirectlyReferencedExecutablesToGraph can be error-prone if one fails. Ensure each step is handled properly with error logs or fallback if needed. Otherwise, no immediate issues.


1018-1019: Creator context extension
Adding extra parameters ensures the code can resolve context-based logic more accurately. This expansion looks consistent.

Comment on lines +69 to +108
return contextDTOMono
.flatMap(contextDTO -> {
String contextId = contextDTO.getId();
Mono<Integer> evalVersionMono = contextLayoutRefactorHelper.getEvaluationVersionMono(
contextId, refactorEntityNameDTO, refactoringMetaDTO);

return pageDTOMono.then();
return evalVersionMono.flatMap(evalVersion -> {
List<Layout> layouts = contextDTO.getLayouts();
if (layouts == null) {
return Mono.just(contextDTO);
}
for (Layout layout : layouts) {
if (layoutId.equals(layout.getId()) && layout.getDsl() != null) {
// DSL has removed all the old names and replaced it with new name. If the change of
// name
// was one of the mongoEscaped widgets, then update the names in the set as well
Set<String> mongoEscapedWidgetNames = layout.getMongoEscapedWidgetNames();
if (mongoEscapedWidgetNames != null && mongoEscapedWidgetNames.contains(oldName)) {
mongoEscapedWidgetNames.remove(oldName);
mongoEscapedWidgetNames.add(newName);
}

final JsonNode dslNode = objectMapper.convertValue(layout.getDsl(), JsonNode.class);
return widgetRefactorUtil
.refactorNameInDsl(dslNode, oldName, newName, evalVersion, oldNamePattern)
.flatMap(dslBindingPaths -> {
updatedBindingPaths.addAll(dslBindingPaths);
layout.setDsl(objectMapper.convertValue(dslNode, JSONObject.class));
contextDTO.setLayouts(layouts);
contextLayoutRefactorHelper.setUpdatedContext(
refactoringMetaDTO, contextDTO);

return contextLayoutRefactorHelper.updateContext(contextId, contextDTO);
});
}
}
return Mono.just(contextDTO);
});
})
.then();
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Chained Mono operations.
This chain gracefully handles DSL name refactoring and updates the context. Make sure error cases are tested and that partial updates do not leave the context in an inconsistent state.

Copy link

Failed server tests

  • com.appsmith.server.helpers.UserUtilsTest#makeInstanceAdministrator_WhenUserAlreadyAdmin_MaintainsPermissionsSuccessfully
  • com.appsmith.server.services.ce.OrganizationServiceCETest#checkAndExecuteMigrationsForOrganizationFeatureFlags_withPendingMigration_getUpdatedOrganization

@subrata71 subrata71 requested a review from sondermanish April 11, 2025 14:43
@subrata71 subrata71 merged commit d4a0852 into release Apr 16, 2025
89 checks passed
@subrata71 subrata71 deleted the chore/code-split-for-widget-refactoring-in-ui-module branch April 16, 2025 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants