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: Removed setting of published theme while application import #38806

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

sondermanish
Copy link
Contributor

@sondermanish sondermanish commented Jan 22, 2025

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

Fixes #38767

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, @tag.ImportExport"

🔍 Cypress test results

Tip

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


Wed, 22 Jan 2025 18:43:17 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • Theme Management

    • Simplified theme import and publishing logic
    • Removed handling of published mode themes during import process
    • Updated theme management to handle scenarios with null theme IDs
  • Bug Fixes

    • Improved null handling for application and theme-related lists
    • Ensured proper initialization of page and theme lists to prevent potential exceptions
  • Testing

    • Updated test assertions to reflect new theme management approach
    • Adjusted expectations for published mode theme ID during application imports

@sondermanish sondermanish requested a review from a team as a code owner January 22, 2025 16:43
@sondermanish sondermanish self-assigned this Jan 22, 2025
Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request involves modifications to theme and application import services in the Appsmith server. The changes primarily focus on refining the handling of themes during import processes, simplifying theme management logic, and ensuring proper initialization of application-related lists. The modifications aim to improve code clarity, prevent potential null pointer exceptions, and streamline the theme import and publishing mechanisms.

Changes

File Change Summary
.../ApplicationImportServiceCEImpl.java - Added constants PUBLISHED and UNPUBLISHED
- Improved list initialization to prevent null pointer exceptions
.../ThemeServiceCEImpl.java - Modified publishTheme method
- Added logic to handle theme publishing with null publishedModeThemeId
.../ThemeImportableServiceCEImpl.java - Simplified theme import logic
- Removed publishedModeTheme handling
- Focused on updating unpublishedThemeId
.../ImportServiceTests.java - Updated assertions for publishedModeThemeId
- Modified test expectations for theme imports

Sequence Diagram

sequenceDiagram
    participant Import Service
    participant Theme Service
    participant Application
    
    Import Service->>Theme Service: importEntities()
    Theme Service->>Application: Update unpublishedThemeId
    Theme Service->>Theme Service: Simplify theme import logic
    Theme Service-->>Import Service: Return import result
Loading

Possibly related PRs

Suggested Labels

Bug, Production, Needs Triaging, Templates Product, Partial-import-export, ok-to-test, Widgets & Accelerators Pod

Suggested Reviewers

  • nidhi-nair
  • subrata71

Poem

🌈 Themes dance, imports flow free
Code refactored with gentle glee
Null pointers banished, logic clean
In Appsmith's realm, a coder's dream!
🚀 Simplicity reigns supreme

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 the ok-to-test Required label for CI label Jan 22, 2025
@github-actions github-actions bot added skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo labels Jan 22, 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: 0

🧹 Nitpick comments (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java (1)

375-376: Consider extracting page list initialization to a helper method.

The map creation logic could be moved to a private helper method to improve readability and maintainability.

+    private Map<String, List<ApplicationPage>> createApplicationPageListMap(Application application) {
+        List<ApplicationPage> unPublishedPages = CollectionUtils.isEmpty(application.getPages())
+                ? new ArrayList<>()
+                : application.getPages();
+        List<ApplicationPage> publishedPages = CollectionUtils.isEmpty(application.getPublishedPages())
+                ? new ArrayList<>()
+                : application.getPublishedPages();
+        return Map.of(PUBLISHED, publishedPages, UNPUBLISHED, unPublishedPages);
+    }

     // In the original method:
-    List<ApplicationPage> unPublishedPages = CollectionUtils.isEmpty(application.getPages())
-            ? new ArrayList<>()
-            : application.getPages();
-    List<ApplicationPage> publishedPages = CollectionUtils.isEmpty(application.getPublishedPages())
-            ? new ArrayList<>()
-            : application.getPublishedPages();
-    Map<String, List<ApplicationPage>> mapOfApplicationPageList =
-            Map.of(PUBLISHED, publishedPages, UNPUBLISHED, unPublishedPages);
+    Map<String, List<ApplicationPage>> mapOfApplicationPageList = createApplicationPageListMap(application);
app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCEImpl.java (1)

272-274: Consider adding error handling for getDefaultThemeId failure.

While the code structure is good, it might be worth adding explicit error handling in case getDefaultThemeId() fails.

 return publishedThemeIdMono.flatMap(publishedThemeId -> saveThemeForApplication(
     publishedThemeId, editModeTheme, application, ApplicationMode.PUBLISHED));
+    })
+    .onErrorResume(error -> {
+        log.error("Error while publishing theme: {}", error.getMessage());
+        return Mono.error(new AppsmithException(AppsmithError.THEME_PUBLISH_ERROR));
+    });
app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java (1)

Line range hint 80-93: Consider optimizing Application object creation.

Instead of creating a new Application object just to update theme IDs, consider using a builder pattern or creating a utility method for dry run operations.

-                        Application application = new Application();
-                        application.setUnpublishedThemeId(editModeThemeId);
-                        application.setId(importableArtifact.getId());
+                        Application application = Application.builder()
+                                .id(importableArtifact.getId())
+                                .unpublishedThemeId(editModeThemeId)
+                                .build();
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b14669e and 0e9f7c2.

📒 Files selected for processing (4)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • 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 (10)
app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java (1)

367-373: LGTM! Defensive null handling for page lists.

The initialization of empty ArrayLists when the pages are null is a good practice to prevent NullPointerExceptions.

app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCEImpl.java (3)

264-266: Documentation accurately reflects the implementation.

The comment clearly explains the unique aspect of theme publishing, which helps future maintainers understand the design decision.


267-268: Important context captured in comments.

The comment effectively documents the specific cases (import and new application) where this null handling is necessary.


269-270: Well-structured null handling with reactive patterns.

Good use of Mono.justOrEmpty() with switchIfEmpty() to handle the null published theme ID case. This maintains the reactive nature of the code while providing a clean fallback to the default theme.

app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java (1)

74-77: LGTM! Good variable naming improvement.

The rename from editModeTheme to editModeThemeMono better reflects the reactive nature of the variable.

app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (5)

1019-1019: LGTM! Verifying published theme handling

The assertion correctly verifies that published mode theme ID is not set during application import.


1141-1141: LGTM! Theme repository verification

The test properly verifies theme repository interaction after application import.


1294-1294: LGTM! Consistent theme verification

The assertion maintains consistency in verifying theme handling behavior across test cases.


4739-4739: LGTM! Theme verification in page import

The assertion correctly verifies theme handling during application import with page modifications.


5291-5291: LGTM! Theme verification with faulty DSL

The assertion maintains consistent theme verification even in error scenarios.

@sondermanish sondermanish merged commit 928a00e into release Jan 23, 2025
50 checks passed
@sondermanish sondermanish deleted the chore/theme-import branch January 23, 2025 05:07
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 Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Remove setting of published entities from Import flow entirely
2 participants