Skip to content

Commit

Permalink
chore: Removed setting of published theme while application import (#…
Browse files Browse the repository at this point in the history
…38806)

## 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
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12912937730>
> Commit: 0e9f7c2
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12912937730&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git, @tag.ImportExport`
> Spec:
> <hr>Wed, 22 Jan 2025 18:43:17 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

- **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

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
sondermanish authored Jan 23, 2025
1 parent b14669e commit 928a00e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import static com.appsmith.server.constants.FieldName.PUBLISHED;
import static com.appsmith.server.constants.FieldName.UNPUBLISHED;
import static com.appsmith.server.helpers.ImportExportUtils.setPropertiesToExistingApplication;
import static com.appsmith.server.helpers.ImportExportUtils.setPublishedApplicationProperties;
import static org.springframework.util.StringUtils.hasText;
Expand Down Expand Up @@ -361,11 +363,18 @@ public Mono<Application> updateAndSaveArtifactInContext(
application.setWorkspaceId(importingMetaDTO.getWorkspaceId());
application.setIsPublic(null);
application.setPolicies(null);
Map<String, List<ApplicationPage>> mapOfApplicationPageList = Map.of(
FieldName.PUBLISHED,
application.getPublishedPages(),
FieldName.UNPUBLISHED,
application.getPages());

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);

mappedImportableResourcesDTO
.getResourceStoreFromArtifactExchangeJson()
.putAll(mapOfApplicationPageList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,18 @@ public Mono<Theme> publishTheme(String applicationId) {
editModeTheme.getId(),
applicationPermission.getEditPermission()))
.thenReturn(editModeTheme);
} else { // a customized theme is set as edit mode theme, copy that theme for published mode
return saveThemeForApplication(
application.getPublishedModeThemeId(),
editModeTheme,
application,
ApplicationMode.PUBLISHED);
} else {
// Unlike other entities themes doesn't have a concept of published and unpublished,
// hence while publishing the themes, contents from unpublished needs to be copied to
// published theme and for that the theme needs to exist.
// In cases of import and new application published theme should be null,
// hence the need of default themeId
Mono<String> publishedThemeIdMono = Mono.justOrEmpty(application.getPublishedModeThemeId())
.switchIfEmpty(getDefaultThemeId());

// a customized theme is set as edit mode theme, copy that theme for published mode
return publishedThemeIdMono.flatMap(publishedThemeId -> saveThemeForApplication(
publishedThemeId, editModeTheme, application, ApplicationMode.PUBLISHED));
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,21 @@ public Mono<Void> importEntities(
return Mono.empty().then();
}
return importableArtifactMono.flatMap(importableArtifact -> {
Mono<Theme> editModeTheme = updateExistingAppThemeFromJSON(
Mono<Theme> editModeThemeMono = updateExistingAppThemeFromJSON(
importableArtifact,
importableArtifact.getUnpublishedThemeId(),
artifactExchangeJson.getUnpublishedTheme(),
mappedImportableResourcesDTO);

Mono<Theme> publishedModeTheme = updateExistingAppThemeFromJSON(
importableArtifact,
importableArtifact.getPublishedThemeId(),
artifactExchangeJson.getPublishedTheme(),
mappedImportableResourcesDTO);

return Mono.zip(editModeTheme, publishedModeTheme)
.flatMap(importedThemesTuple -> {
String editModeThemeId = importedThemesTuple.getT1().getId();
String publishedModeThemeId =
importedThemesTuple.getT2().getId();

return editModeThemeMono
.flatMap(editModeTheme -> {
String editModeThemeId = editModeTheme.getId();
importableArtifact.setUnpublishedThemeId(editModeThemeId);
importableArtifact.setPublishedThemeId(publishedModeThemeId);

// this will update the theme in the application and will be updated to db in the dry ops
// execution

Application application = new Application();
application.setPublishedModeThemeId(publishedModeThemeId);
application.setUnpublishedThemeId(editModeThemeId);
application.setId(importableArtifact.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ public void importArtifactFromValidJsonFileTest() {
assertThat(application.getModifiedBy()).isEqualTo("api_user");
assertThat(application.getUpdatedAt()).isNotNull();
assertThat(application.getEditModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNull();
assertThat(isPartialImport).isEqualTo(Boolean.TRUE);
assertThat(unConfiguredDatasourceList).isNotNull();

Expand Down Expand Up @@ -1138,22 +1138,14 @@ public void importApplicationInWorkspace_WhenCustomizedThemes_ThemesCreated() {

StepVerifier.create(resultMono.flatMap(applicationImportDTO -> Mono.zip(
Mono.just(applicationImportDTO),
themeRepository.findById(applicationImportDTO.getEditModeThemeId()),
themeRepository.findById(applicationImportDTO.getPublishedModeThemeId()))))
themeRepository.findById(applicationImportDTO.getEditModeThemeId()))))
.assertNext(tuple -> {
final Application application = tuple.getT1();
Theme editTheme = tuple.getT2();
Theme publishedTheme = tuple.getT3();

assertThat(editTheme.isSystemTheme()).isFalse();
assertThat(editTheme.getDisplayName()).isEqualTo("Custom edit theme");
assertThat(editTheme.getWorkspaceId()).isNull();
assertThat(editTheme.getApplicationId()).isNull();

assertThat(publishedTheme.isSystemTheme()).isFalse();
assertThat(publishedTheme.getDisplayName()).isEqualTo("Custom published theme");
assertThat(publishedTheme.getWorkspaceId()).isNullOrEmpty();
assertThat(publishedTheme.getApplicationId()).isNullOrEmpty();
})
.verifyComplete();
}
Expand Down Expand Up @@ -1299,7 +1291,7 @@ public void importArtifact_WithoutThemes_LegacyThemesAssigned() {
StepVerifier.create(resultMono)
.assertNext(applicationImportDTO -> {
assertThat(applicationImportDTO.getEditModeThemeId()).isNotEmpty();
assertThat(applicationImportDTO.getPublishedModeThemeId()).isNotEmpty();
assertThat(applicationImportDTO.getPublishedModeThemeId()).isNull();
})
.verifyComplete();
}
Expand Down Expand Up @@ -1532,7 +1524,7 @@ public void importApplication_withUnConfiguredDatasources_Success() {
assertThat(application.getModifiedBy()).isEqualTo("api_user");
assertThat(application.getUpdatedAt()).isNotNull();
assertThat(application.getEditModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNull();
assertThat(isPartialImport).isEqualTo(Boolean.TRUE);
assertThat(unConfiguredDatasourceList.size()).isNotEqualTo(0);

Expand Down Expand Up @@ -1860,7 +1852,7 @@ public void discardChange_addNewPageAfterImport_addedPageRemoved() {
assertThat(application.getModifiedBy()).isEqualTo("api_user");
assertThat(application.getUpdatedAt()).isNotNull();
assertThat(application.getEditModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNull();

assertThat(pageList).hasSize(3);

Expand Down Expand Up @@ -4744,7 +4736,7 @@ public void extractFileAndUpdateApplication_addNewPageAfterImport_addedPageRemov
assertThat(application.getModifiedBy()).isEqualTo("api_user");
assertThat(application.getUpdatedAt()).isNotNull();
assertThat(application.getEditModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNull();

assertThat(pageList).hasSize(3);

Expand Down Expand Up @@ -5296,7 +5288,7 @@ public void importApplication_WhenUpdateLayoutFailures_Success() throws URISynta
assertThat(application.getModifiedBy()).isEqualTo("api_user");
assertThat(application.getUpdatedAt()).isNotNull();
assertThat(application.getEditModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNotNull();
assertThat(application.getPublishedModeThemeId()).isNull();
assertThat(isPartialImport).isEqualTo(Boolean.TRUE);
assertThat(unConfiguredDatasourceList.size()).isNotEqualTo(0);

Expand Down

0 comments on commit 928a00e

Please sign in to comment.