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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.appsmith.server.domains.ce;

import com.appsmith.server.domains.Layout;

import java.util.List;

public interface LayoutContainer {
List<Layout> getLayouts();

void setLayouts(List<Layout> layouts);

String getId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.appsmith.external.views.Git;
import com.appsmith.external.views.Views;
import com.appsmith.server.domains.Layout;
import com.appsmith.server.domains.ce.LayoutContainer;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.Getter;
Expand All @@ -26,7 +27,7 @@
@NoArgsConstructor
@ToString
@FieldNameConstants
public class PageDTO {
public class PageDTO implements LayoutContainer {

@Transient
@JsonView({Views.Public.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
public interface UpdateLayoutServiceCE {
Mono<LayoutDTO> updateLayout(String pageId, String applicationId, String layoutId, Layout layout);

Mono<LayoutDTO> updateLayout(
String pageId, String applicationId, String layoutId, Layout layout, CreatorContextType contextType);

Mono<Integer> updateMultipleLayouts(
String defaultApplicationId, UpdateMultiplePageLayoutDTO updateMultiplePageLayoutDTO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.appsmith.external.helpers.MustacheHelper;
import com.appsmith.external.models.CreatorContextType;
import com.appsmith.external.models.Executable;
import com.appsmith.server.applications.base.ApplicationService;
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.ExecutableDependencyEdge;
import com.appsmith.server.domains.Layout;
Expand All @@ -21,6 +20,7 @@
import com.appsmith.server.helpers.WidgetSpecificUtils;
import com.appsmith.server.newpages.base.NewPageService;
import com.appsmith.server.onload.internal.OnLoadExecutablesUtil;
import com.appsmith.server.refactors.resolver.ContextLayoutRefactorResolver;
import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.SessionUserService;
import com.appsmith.server.solutions.PagePermission;
Expand Down Expand Up @@ -59,6 +59,7 @@
import static com.appsmith.external.constants.spans.PageSpan.GET_PAGE_BY_ID;
import static com.appsmith.external.constants.spans.ce.LayoutSpanCE.UPDATE_LAYOUT_BASED_ON_CONTEXT;
import static com.appsmith.server.constants.CommonConstants.EVALUATION_VERSION;
import static com.appsmith.server.helpers.ContextTypeUtils.isPageContext;
import static java.lang.Boolean.FALSE;

@Slf4j
Expand All @@ -71,10 +72,10 @@ public class UpdateLayoutServiceCEImpl implements UpdateLayoutServiceCE {
private final NewPageService newPageService;
private final AnalyticsService analyticsService;
private final PagePermission pagePermission;
private final ApplicationService applicationService;
private final ObjectMapper objectMapper;
private final ObservationRegistry observationRegistry;
private final ObservationHelperImpl observationHelper;
private final ContextLayoutRefactorResolver contextLayoutRefactorResolver;

private final String layoutOnLoadActionErrorToastMessage =
"A cyclic dependency error has been encountered on current page, \nqueries on page load will not run. \n Please check debugger and Appsmith documentation for more information";
Expand Down Expand Up @@ -117,7 +118,7 @@ private Mono<Boolean> sendUpdateLayoutAnalyticsEvent(
});
}

private Mono<LayoutDTO> updateLayoutDsl(
protected Mono<LayoutDTO> updateLayoutDsl(
String creatorId,
String layoutId,
Layout layout,
Expand Down Expand Up @@ -247,22 +248,29 @@ private Mono<LayoutDTO> updateLayoutDsl(
return layoutDTOMono;
}

// TODO: Add contextType and change all its usage to conform to that so that we can get rid of the overloaded
// updateLayout method
@Override
public Mono<LayoutDTO> updateLayout(String pageId, String applicationId, String layoutId, Layout layout) {
return applicationService
.findById(applicationId)
.switchIfEmpty(Mono.error(new AppsmithException(
AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.APPLICATION_ID, applicationId)))
.flatMap(application -> {
Integer evaluationVersion = application.getEvaluationVersion();
if (evaluationVersion == null) {
evaluationVersion = EVALUATION_VERSION;
}
return contextLayoutRefactorResolver
.getContextLayoutRefactorHelper(null)
.getEvaluationVersionMono(applicationId)
.flatMap(evaluationVersion -> {
return updateLayoutDsl(pageId, layoutId, layout, evaluationVersion, CreatorContextType.PAGE)
.name(UPDATE_LAYOUT_DSL_METHOD);
});
}

@Override
public Mono<LayoutDTO> updateLayout(
String pageId, String applicationId, String layoutId, Layout layout, CreatorContextType contextType) {
if (isPageContext(contextType)) {
return updateLayout(pageId, applicationId, layoutId, layout);
} else {
return updateLayoutDsl(pageId, layoutId, layout, EVALUATION_VERSION, contextType);
}
}

@Override
public Mono<Integer> updateMultipleLayouts(
String baseApplicationId, UpdateMultiplePageLayoutDTO updateMultiplePageLayoutDTO) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.appsmith.server.layouts;

import com.appsmith.server.applications.base.ApplicationService;
import com.appsmith.server.helpers.ObservationHelperImpl;
import com.appsmith.server.newpages.base.NewPageService;
import com.appsmith.server.onload.internal.OnLoadExecutablesUtil;
import com.appsmith.server.refactors.resolver.ContextLayoutRefactorResolver;
import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.SessionUserService;
import com.appsmith.server.solutions.PagePermission;
Expand All @@ -13,26 +13,25 @@

@Service
public class UpdateLayoutServiceImpl extends UpdateLayoutServiceCEImpl implements UpdateLayoutService {

public UpdateLayoutServiceImpl(
OnLoadExecutablesUtil onLoadExecutablesUtil,
SessionUserService sessionUserService,
NewPageService newPageService,
AnalyticsService analyticsService,
PagePermission pagePermission,
ApplicationService applicationService,
ObjectMapper objectMapper,
ObservationRegistry observationRegistry,
ObservationHelperImpl observationHelper) {
ObservationHelperImpl observationHelper,
ContextLayoutRefactorResolver contextLayoutRefactorResolver) {
super(
onLoadExecutablesUtil,
sessionUserService,
newPageService,
analyticsService,
pagePermission,
applicationService,
objectMapper,
observationRegistry,
observationHelper);
observationHelper,
contextLayoutRefactorResolver);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.appsmith.server.newpages.refactors;

import com.appsmith.server.applications.base.ApplicationService;
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.Layout;
import com.appsmith.server.domains.NewPage;
import com.appsmith.server.domains.ce.LayoutContainer;
import com.appsmith.server.dtos.PageDTO;
import com.appsmith.server.dtos.RefactorEntityNameDTO;
import com.appsmith.server.dtos.RefactoringMetaDTO;
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.newpages.base.NewPageService;
import com.appsmith.server.refactors.ContextLayoutRefactoringService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.List;

import static com.appsmith.server.constants.ce.CommonConstantsCE.EVALUATION_VERSION;

@Component
@RequiredArgsConstructor
@Slf4j
public class PageLayoutRefactoringServiceImpl implements ContextLayoutRefactoringService<NewPage, PageDTO> {
private final NewPageService newPageService;
private final ApplicationService applicationService;

@Override
public Mono<PageDTO> updateContext(String contextId, LayoutContainer dto) {
return newPageService.saveUnpublishedPage((PageDTO) dto);
}

@Override
public Mono<PageDTO> getContextDTOMono(String contextId, boolean viewMode) {
return newPageService.findPageById(contextId, null, viewMode);
}

@Override
public Mono<PageDTO> getContextDTOMono(RefactoringMetaDTO refactoringMetaDTO) {
return refactoringMetaDTO.getPageDTOMono();
}

@Override
public Mono<Integer> getEvaluationVersionMono(
String contextId, RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) {
Mono<PageDTO> pageDTOMono = getContextDTOMono(contextId, false);
refactoringMetaDTO.setPageDTOMono(pageDTOMono);
return pageDTOMono.flatMap(
page -> applicationService.findById(page.getApplicationId()).map(application -> {
Integer evaluationVersion = application.getEvaluationVersion();
if (evaluationVersion == null) {
evaluationVersion = EVALUATION_VERSION;
}
return evaluationVersion;
}));
}

@Override
public Mono<Integer> getEvaluationVersionMono(String artifactId) {
return applicationService
.findById(artifactId)
.switchIfEmpty(Mono.error(new AppsmithException(
AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.APPLICATION_ID, artifactId)))
.map(application -> {
Integer evaluationVersion = application.getEvaluationVersion();
if (evaluationVersion == null) {
evaluationVersion = EVALUATION_VERSION;
}
return evaluationVersion;
});
}

@Override
public List<Layout> getLayouts(RefactoringMetaDTO refactoringMetaDTO) {
PageDTO updatedPage = refactoringMetaDTO.getUpdatedPage();
if (updatedPage == null) {
return null;
}
return updatedPage.getLayouts();
}

@Override
public Mono<PageDTO> updateLayoutByContextId(String contextId, Layout layout) {
// Implementation for updating page layout
return Mono.empty();
}

@Override
public String getId(RefactoringMetaDTO refactoringMetaDTO) {
return refactoringMetaDTO.getUpdatedPage() != null
? refactoringMetaDTO.getUpdatedPage().getId()
: null;
}

@Override
public String getArtifactId(RefactoringMetaDTO refactoringMetaDTO) {
return refactoringMetaDTO.getUpdatedPage() != null
? refactoringMetaDTO.getUpdatedPage().getApplicationId()
: null;
}

@Override
public void setUpdatedContext(RefactoringMetaDTO refactoringMetaDTO, LayoutContainer updatedContext) {
refactoringMetaDTO.setUpdatedPage((PageDTO) updatedContext);
}
}
Loading