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

feat:sort apps in a workspace in alphabetical order #36312

Conversation

MajaharZemoso
Copy link

@MajaharZemoso MajaharZemoso commented Sep 13, 2024

Issue

Describtion

  • added a new service which return applications of the user in alphabetical order
  • added this service call in controller.
  • added the test case for this changes.

Screenshots

image

Summary by CodeRabbit

  • New Features

    • Introduced a new method to retrieve applications within a workspace, sorted alphabetically by name.
    • Enhanced application retrieval options to improve organization and accessibility for users.
  • Bug Fixes

    • Updated application retrieval logic to ensure applications are displayed in alphabetical order instead of by recent usage.
  • Tests

    • Added tests to verify that applications are returned in alphabetical order within a workspace.

Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

The changes introduce a new method, findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder, to the ApplicationServiceCE interface and its implementation. This method retrieves applications based on a specified workspace ID and sorts them alphabetically. Additionally, the ApplicationControllerCE is updated to utilize this new sorting method instead of the previously used recently accessed order. Corresponding tests are added to ensure that the applications are returned in the correct alphabetical order.

Changes

Files Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCE.java
app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java
Added method findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder(String workspaceId) to retrieve applications in alphabetical order.
app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ApplicationControllerCE.java Modified findByWorkspaceIdAndRecentlyUsedOrder to call the new alphabetical order method.
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java Added test findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder_applicationPresentInWorkspace_orderedAlphabetically to verify alphabetical sorting.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Controller
    participant Service

    User->>Controller: Request applications by workspace ID
    Controller->>Service: findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder(workspaceId)
    Service->>Service: Validate workspace ID
    Service->>Service: Fetch applications
    Service->>Service: Sort applications alphabetically
    Service-->>Controller: Return sorted applications
    Controller-->>User: Display sorted applications
Loading

🌟 In a workspace bright and grand,
Applications take a stand.
Alphabetical order, neat and clear,
Users cheer, "Our apps are here!"
With tests to guard this newfound grace,
Organization finds its rightful place! 🎉


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cf51feb and bc941e1.

Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ApplicationRepositoryCE.java (1 hunks)
Additional comments not posted (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ApplicationRepositoryCE.java (1)

30-30: Excellent work on adding the new query method! 👍

The findByWorkspaceIdOrderByNameAsc method follows the Spring Data JPA naming convention and enhances the repository's querying capabilities. It allows retrieving applications for a given workspace, ordered alphabetically by name.

This addition integrates seamlessly with the existing codebase and could be beneficial for features that require listing applications in a user-friendly manner.

app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java (2)

60-60: Don't forget the previous review comment about sorting in the database query. 🤔

In the past review, it was suggested to perform the sorting operation during the database query instead of in application memory. This is because it's generally more efficient to let the database handle the sorting, especially for larger datasets.

Consider updating the code to sort the applications directly in the MongoDB query using the sort method. This will ensure better performance and scalability.


215-257: Excellent work on the new findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder function! 👍

This function provides a convenient way to retrieve applications for a given workspace, sorted alphabetically. The validation checks and filtering logic ensure that only valid and relevant applications are returned.

To verify that the applications are indeed sorted alphabetically, you can run the following script:

Replace <workspace_id> with a valid workspace ID. The script retrieves the applications for the specified workspace, extracts their names, and compares the order with the sorted names. If they match, it confirms that the applications are sorted alphabetically.


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 generate interesting stats about this repository and render them as a table.
    -- @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.

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 (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ApplicationControllerCE.java (1)

130-130: Great work implementing the alphabetical sorting! Just one small suggestion.

The change correctly updates the service method call to fetch applications in alphabetical order, which aligns perfectly with the PR objective.

However, since the sorting order is changed from recently used to alphabetical, consider renaming this controller method to accurately reflect its new behavior. For example:

- findByWorkspaceIdAndRecentlyUsedOrder
+ findByWorkspaceIdAndAlphabeticalOrder

This will improve code readability and maintainability by ensuring the method name matches its functionality.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f5b29b4 and cf51feb.

Files selected for processing (4)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ApplicationControllerCE.java (1 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java (1 hunks)
Additional comments not posted (4)
app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCE.java (1)

32-32: Great work on adding the new method! 👍

The findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder method is a valuable addition to the ApplicationServiceCE interface. It complements the existing findByWorkspaceIdAndBaseApplicationsInRecentlyUsedOrder method by providing an alternative sorting option based on the application names.

This enhancement improves the application's ability to manage and display applications in a user-friendly manner, allowing for better organization and accessibility within a workspace. The method signature is clear, follows the naming convention, and effectively communicates its purpose.

Keep up the excellent work in improving the user experience! 🌟

app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java (2)

60-60: Good job importing the Comparator class!

The Comparator class is necessary for sorting applications alphabetically by name in the new findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder method.


215-263: Excellent work implementing the new method to retrieve applications in alphabetical order!

The findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder method is well-structured and follows a similar pattern to the existing findByWorkspaceIdAndBaseApplicationsInRecentlyUsedOrder method. Here are the key points:

  1. Error handling for invalid workspaceId is implemented correctly by returning a Flux error.
  2. The filtering logic for Git-connected applications ensures that only applications that are not connected to Git or are connected but revert to the default branch are included in the results.
  3. The alphabetical sorting using Comparator.comparing with a case-insensitive comparator is implemented correctly.

Overall, the method implementation looks solid and should work as expected. Great job!

app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java (1)

4523-4566: Excellent work!

The new test method findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder_applicationPresentInWorkspace_orderedAlphabetically is well-written and thoroughly tests the functionality of fetching applications in alphabetical order. It creates dummy applications, invokes the service method, and verifies if the returned applications are ordered alphabetically by name.

The test follows good practices by:

  1. Creating a workspace and dummy applications for testing.
  2. Mocking the user data service to return empty recently used application IDs.
  3. Invoking the service method to fetch applications in alphabetical order.
  4. Asserting that the returned applications are ordered alphabetically by name.
  5. Cleaning up the created resources after the test.

Great job in adding this comprehensive test case! It enhances the test coverage and ensures the correctness of the alphabetical ordering functionality.

@MajaharZemoso
Copy link
Author

@appsmithorg/query-js-pod , Please add reviewer for this pr if you have enough bandwidth.
Thanks in advance.

@rishabhrathod01 rishabhrathod01 added IDE Product Issues related to the IDE Product IDE Pod Issues that new developers face while exploring the IDE labels Sep 13, 2024
return !GitUtils.isApplicationConnectedToGit(application)
|| GitUtils.isDefaultBranchedApplication(application);
})
.sort(Comparator.comparing(
Copy link
Member

Choose a reason for hiding this comment

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

Instead of sorting in application memory, we should perform this operation during the database query. In this scenario, we should query MongoDB to get the applications for the workspace in a sorted manner. This is because it's much faster to perform this operation in a database rather than in application memory. Also, moving such ops to the DB ensures long-term stability of this function.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the suggestion! I've updated the code to perform sorting at the MongoDB query level. Please let me know if further adjustments are needed.

@ankitakinger ankitakinger removed their request for review September 16, 2024 05:19
@vsvamsi1 vsvamsi1 requested review from subrata71 and removed request for vsvamsi1 September 17, 2024 09:38
@abhvsn
Copy link
Contributor

abhvsn commented Sep 18, 2024

@MajaharZemoso thanks for your interest but we have received another contribution for the same issue, and decided to go ahead with the other PR as the other one was raised earlier.
You can look for other good first issues. Sorry again we should have assigned this ticket to single owner before asking for the contribution to avoid this situation.

Copy link

github-actions bot commented Oct 2, 2024

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Oct 2, 2024
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants