Skip to content
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

chore: Modified default behaviour of consolidated API for missing url params and extra url params #37274

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

sondermanish
Copy link
Contributor

@sondermanish sondermanish commented Nov 7, 2024

Description

  • PR for handling Consolidated API when url params are incomplete or have extra params.

Fixes #36537, #37316

Automation

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

🔍 Cypress test results

Tip

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


Fri, 08 Nov 2024 08:27:02 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Improved logic for application and page retrieval based on branch names and application modes.
    • Enhanced error handling and logging for better user experience during page loads.
  • Bug Fixes

    • Resolved issues with application ID fetching when branch names are present.
  • Tests

    • Added new test cases to cover various scenarios related to page loading in Git-connected and non-Git applications, ensuring robust functionality across different contexts.

@sondermanish sondermanish self-assigned this Nov 7, 2024
Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes in this pull request primarily enhance the ConsolidatedAPIServiceCEImpl class, focusing on the getConsolidatedInfoForPageLoad method. Modifications include the introduction of Git-related functionality and improved logic for handling application and page retrieval based on branch names. Additionally, new test cases have been added to the ConsolidatedAPIServiceImplTest class to ensure comprehensive coverage of various scenarios, particularly around branch handling in Git-connected and non-Git applications.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java - Added imports for GitArtifactMetadata and Tuple2.
- Restructured getConsolidatedInfoForPageLoad to improve application and page retrieval logic based on branch names.
- Enhanced error handling and logging.
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceImplTest.java - Added new test methods: testPageLoadResponseForViewMode_whenBranchNameIsPresentInNonGitApp and testPageLoadResponseForEditModeWhenDefaultBranchIsDifferentFromDefault.
- Updated existing tests to include new scenarios and imports.

Possibly related PRs

  • fix: fixed page data DB call getting called twice #36247: The changes in this PR directly modify the getConsolidatedInfoForPageLoad method in the ConsolidatedAPIServiceCEImpl class, which is also the focus of the main PR. Both PRs enhance the logic and control flow of this method.
  • fix: consolidated api test file split to ce #36318: This PR involves changes to the ConsolidatedAPIServiceImplTest class, which tests the getConsolidatedInfoForPageLoad method, aligning with the enhancements made in the main PR regarding test coverage and functionality.

Suggested labels

Bug, Task, Query & JS Pod, Integrations Product, Integrations Pod General, Git Platform Pod

Suggested reviewers

  • nidhi-nair
  • subrata71

🎉 In the land of code, where logic flows,
A service was changed, as everyone knows.
With branches and pages, it now stands tall,
Robust and ready, to handle it all!
New tests were written, to cover the ground,
In the realm of Git, new features abound! 🌟


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?

❤️ 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 resolve resolve all the CodeRabbit review comments.
  • @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.

@sondermanish sondermanish added Git Product Issues related to version control product ok-to-test Required label for CI labels Nov 7, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 7, 2024
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: 0

🧹 Outside diff range and nitpick comments (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java (1)

281-283: Address the TODO regarding branch name residue

Please resolve the TODO comment about verifying if the branch name could be residue from an old Git connection.

Would you like assistance in addressing this TODO item?

app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceImplTest.java (2)

883-1069: Consider refactoring duplicated setup code

The test method testPageLoadResponseForViewMode_whenBranchNameIsPresentInNonGitApp contains setup code that is similar to other test methods in this class. Extracting common code into helper methods or using @BeforeEach could improve maintainability and reduce code duplication.


1072-1419: Refactor to eliminate repetitive code in test

The test method testPageLoadResponseForEditModeWhenDefaultBranchIsDifferentFromDefault duplicates setup logic found in other tests. Consider refactoring shared code into common setup methods to enhance readability and maintainability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d00c15d and 2de6e5e.

📒 Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java (6 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceImplTest.java (4 hunks)
🧰 Additional context used
📓 Learnings (1)
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceImplTest.java (2)
Learnt from: sumitsum
PR: appsmithorg/appsmith#29875
File: app/server/appsmith-server/src/main/java/com/appsmith/server/services/ConsolidatedAPIServiceImpl.java:0-0
Timestamp: 2023-12-27T21:27:19.887Z
Learning: Test cases for the `getConsolidatedInfoForPageLoad` method have already been added, and the refactoring of the method into smaller methods is planned for later and is being tracked in a separate GitHub issue.
Learnt from: sumitsum
PR: appsmithorg/appsmith#29875
File: app/server/appsmith-server/src/main/java/com/appsmith/server/services/ConsolidatedAPIServiceImpl.java:0-0
Timestamp: 2024-10-08T15:32:34.114Z
Learning: Test cases for the `getConsolidatedInfoForPageLoad` method have already been added, and the refactoring of the method into smaller methods is planned for later and is being tracked in a separate GitHub issue.
🔇 Additional comments (5)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java (5)

11-11: Importing GitArtifactMetadata

The addition of GitArtifactMetadata import is appropriate for handling Git-related functionality.


46-46: Importing Tuple2

Including Tuple2 is necessary for encapsulating Application and NewPage objects.


224-257: Refactored application and page retrieval logic

The use of Tuple2<Application, NewPage> improves code clarity and streamlines data handling.


390-392: Optimized page retrieval with DSL migration

Fetching and migrating the DSL in getPageAndMigrateDslByBranchAndBasePageId enhances efficiency.


404-406: Verify action fetching with correct branch handling

Ensure that actions are fetched correctly when the branch name may differ from the base in Git-connected applications.

Run the following script to confirm actions are associated with the correct branch:

✅ Verification successful

Let me gather more information about the branch handling logic.


Branch handling for action fetching is correctly implemented

The code correctly handles branch-specific action fetching through multiple safeguards:

  • Validates branch name presence and Git connection status
  • Falls back to default branch when needed via defaultBranchName
  • Uses cached branched page ID to fetch actions for the correct branch context
  • Handles error cases for non-Git applications attempting to use branches
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that actions are fetched for the correct branch in view mode.

# Test: Search for actions linked to the specified branch. Expect: Actions should belong to the correct branch.
rg -A 5 $'getActionsForViewModeByPageId'

Length of output: 4946


Script:

#!/bin/bash
# Search for branch-related logic in action fetching
rg -A 10 "branchedPageId|defaultBranchName|branchName" app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java

# Check implementation of action service for branch handling
ast-grep --pattern 'class NewActionServiceCEImpl {
  $$$
  getActionsForViewModeByPageId($$$) {
    $$$
  }
  $$$
}'

Length of output: 5980

@sondermanish sondermanish added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Nov 8, 2024
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: 2

🧹 Outside diff range and nitpick comments (4)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java (3)

224-324: Consider breaking down the complex application and page retrieval logic into smaller methods.

The application and page retrieval logic is quite complex and handles multiple scenarios. Consider extracting the logic into smaller, more focused methods to improve readability and maintainability.

+ private Mono<Tuple2<Application, NewPage>> fetchApplicationAndPage(
+     String cachedBaseApplicationId,
+     String branchName,
+     String basePageId,
+     ApplicationMode mode
+ ) {
+     Mono<Application> applicationMono = fetchApplication(cachedBaseApplicationId, branchName, mode);
+     Mono<NewPage> branchedPageMono = fetchBranchedPage(branchName, basePageId, mode);
+     return applicationMono.zipWith(branchedPageMono);
+ }

281-282: Address the TODO comment regarding branch name verification.

The TODO comment suggests a potential issue with residual branch names from old Git connections. This should be addressed to prevent potential bugs.

Would you like me to help create a GitHub issue to track this technical debt?


404-406: Consider adding debug logging for branch name resolution.

For Git-connected applications where the desired branch name differs from the base, adding debug logging would help in troubleshooting issues.

+ log.debug(
+   "Resolving branch name for Git-connected application. Desired: {}, Base: {}",
+   branchName,
+   application.getGitArtifactMetadata().getDefaultBranchName()
+ );
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceImplTest.java (1)

1071-1415: LGTM! Thorough test for edit mode with different default branch.

The test comprehensively covers the scenario where the default branch differs from the expected default, including Git metadata handling.

Consider extracting common setup code (user, profile, feature flags, etc.) into a shared setup method to reduce duplication across test methods.

+private void setupCommonMocks() {
+    User sampleUser = new User();
+    when(mockSessionUserService.getCurrentUser()).thenReturn(Mono.just(sampleUser));
+
+    UserProfileDTO sampleUserProfileDTO = new UserProfileDTO();
+    sampleUserProfileDTO.setName("sampleUserProfileDTO");
+    when(mockUserService.buildUserProfileDTO(any())).thenReturn(Mono.just(sampleUserProfileDTO));
+    
+    // ... other common setup code
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2de6e5e and f6124cb.

📒 Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java (6 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceImplTest.java (7 hunks)
🧰 Additional context used
📓 Learnings (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java (2)
Learnt from: sumitsum
PR: appsmithorg/appsmith#29875
File: app/server/appsmith-server/src/main/java/com/appsmith/server/services/ConsolidatedAPIServiceImpl.java:0-0
Timestamp: 2023-12-27T21:27:19.887Z
Learning: Test cases for the `getConsolidatedInfoForPageLoad` method have already been added, and the refactoring of the method into smaller methods is planned for later and is being tracked in a separate GitHub issue.
Learnt from: sumitsum
PR: appsmithorg/appsmith#29875
File: app/server/appsmith-server/src/main/java/com/appsmith/server/services/ConsolidatedAPIServiceImpl.java:0-0
Timestamp: 2024-10-08T15:32:34.114Z
Learning: Test cases for the `getConsolidatedInfoForPageLoad` method have already been added, and the refactoring of the method into smaller methods is planned for later and is being tracked in a separate GitHub issue.
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceImplTest.java (2)
Learnt from: sumitsum
PR: appsmithorg/appsmith#29875
File: app/server/appsmith-server/src/main/java/com/appsmith/server/services/ConsolidatedAPIServiceImpl.java:0-0
Timestamp: 2023-12-27T21:27:19.887Z
Learning: Test cases for the `getConsolidatedInfoForPageLoad` method have already been added, and the refactoring of the method into smaller methods is planned for later and is being tracked in a separate GitHub issue.
Learnt from: sumitsum
PR: appsmithorg/appsmith#29875
File: app/server/appsmith-server/src/main/java/com/appsmith/server/services/ConsolidatedAPIServiceImpl.java:0-0
Timestamp: 2024-10-08T15:32:34.114Z
Learning: Test cases for the `getConsolidatedInfoForPageLoad` method have already been added, and the refactoring of the method into smaller methods is planned for later and is being tracked in a separate GitHub issue.
🔇 Additional comments (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java (1)

259-301: Add unit tests for non-Git connected application scenarios.

The logic for handling branch names in non-Git connected applications is complex and requires thorough testing.

#!/bin/bash
# Check if there are existing tests for non-Git connected applications
rg -A 5 "testPageLoadResponseForViewMode_whenBranchNameIsPresentInNonGitApp" 
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceImplTest.java (2)

11-13: LGTM!

The new imports are required for the Git-related test cases.


882-1069: LGTM! Comprehensive test coverage for view mode.

The test thoroughly validates the consolidated API response when a branch name is provided in a non-Git application context.

Comment on lines +390 to +392
fetches.add(branchedPageMonoCached
.flatMap(branchedPage -> applicationPageService.getPageAndMigrateDslByBranchedPageId(
branchedPage.getId(), isViewMode, true))
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Both old and new method names are present - needs cleanup

The old method getPageAndMigrateDslByBranchAndBasePageId is still present in:

  • ApplicationPageServiceCE.java interface
  • ApplicationPageServiceCEImpl.java implementation
  • Test files

While the new method getPageAndMigrateDslByBranchedPageId is being used in:

  • PageControllerCE.java
  • ConsolidatedAPIServiceCEImpl.java
  • Test files

Please remove the old method and update all its references to use the new method name.

🔗 Analysis chain

Verify the impact of the method name change.

The method name has changed from getPageAndMigrateDslByBranchAndBasePageId to getPageAndMigrateDslByBranchedPageId. Ensure all callers are updated.


The results show that the old method is still being used in test files and is defined in the CE (Community Edition) interface and implementation. Let's verify the new method to understand the complete picture before making a conclusion.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usages of the old method name
rg "getPageAndMigrateDslByBranchAndBasePageId"

Length of output: 1461


Script:

#!/bin/bash
# Let's check the interface and implementation of the new method name
ast-grep --pattern 'getPageAndMigrateDslByBranchedPageId'

# Also check for any references to the new method name
rg "getPageAndMigrateDslByBranchedPageId"

Length of output: 4556

@@ -262,7 +263,7 @@ public void testPageLoadResponseForViewMode() {
samplePageDTO.setName("samplePageDTO");
doReturn(Mono.just(samplePageDTO))
.when(spyApplicationPageService)
.getPageAndMigrateDslByBranchAndBasePageId(anyString(), anyString(), anyBoolean(), anyBoolean());
.getPageAndMigrateDslByBranchedPageId(anyString(), anyBoolean(), anyBoolean());
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Method name inconsistency found - needs update across codebase

The old method name getPageAndMigrateDslByBranchAndBasePageId is still in use in several files while the new name getPageAndMigrateDslByBranchedPageId is also present, indicating an incomplete refactoring:

  • ApplicationPageServiceCE.java: Both old and new method signatures exist
  • ApplicationPageServiceCEImpl.java: Both implementations present
  • NewPageServiceTest.java: Still using old method name
  • ApplicationPageServiceTest.java: Multiple occurrences of old method name
🔗 Analysis chain

Verify method name consistency across codebase.

The method name has been updated from getPageAndMigrateDslByBranchAndBasePageId to getPageAndMigrateDslByBranchedPageId.

Also applies to: 436-436, 458-458

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining occurrences of the old method name
# Test: Search for old method name. Expect: No occurrences.
rg "getPageAndMigrateDslByBranchAndBasePageId"

# Test: Verify all occurrences use the new method name
rg "getPageAndMigrateDslByBranchedPageId"

Length of output: 3615

Copy link
Contributor

@subrata71 subrata71 left a comment

Choose a reason for hiding this comment

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

LGTM.
Nit: The readability could be improved though by breaking down the logic into smaller methods.

@sondermanish sondermanish merged commit 806c710 into release Nov 8, 2024
52 of 53 checks passed
@sondermanish sondermanish deleted the chore/consolidated-default branch November 8, 2024 11:30
@github-actions github-actions bot added App Navigation Issues related to the topbar navigation and configuring it Bug Something isn't working Customer Success Issues that the success team cares about Git Platform Issues related to the git & the app platform Medium Issues that frustrate users due to poor UX Production UI Building Product Issues related to the UI Building experience and removed Bug Something isn't working labels Nov 11, 2024
@github-actions github-actions bot added Bug Something isn't working and removed Bug Something isn't working labels Nov 11, 2024
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
… params and extra url params (appsmithorg#37274)

## Description
- PR for handling Consolidated API when url params are incomplete or
have extra params.

> [!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.Git"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11738054403>
> Commit: f6124cb
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11738054403&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Fri, 08 Nov 2024 08:27:02 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Improved logic for application and page retrieval based on branch
names and application modes.
- Enhanced error handling and logging for better user experience during
page loads.

- **Bug Fixes**
- Resolved issues with application ID fetching when branch names are
present.

- **Tests**
- Added new test cases to cover various scenarios related to page
loading in Git-connected and non-Git applications, ensuring robust
functionality across different contexts.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App Navigation Issues related to the topbar navigation and configuring it Customer Success Issues that the success team cares about Git Platform Issues related to the git & the app platform Git Product Issues related to version control product Medium Issues that frustrate users due to poor UX ok-to-test Required label for CI Production skip-changelog Adding this label to a PR prevents it from being listed in the changelog UI Building Product Issues related to the UI Building experience
Projects
None yet
2 participants