Communicate action execute on load changes in update layout (#2825)
* 1. Update on load actions correctly 2. Send the changed actions with their changes as well as messages back to the client as part of the response. * Added test case to assert that the action updates are correctly recorded in updateLayout. * Code cleanup + added more comments for code readability * Incorporated review comments.
This commit is contained in:
parent
fbf6021080
commit
078870f7c9
|
|
@ -2,11 +2,11 @@ package com.appsmith.server.controllers;
|
|||
|
||||
import com.appsmith.external.models.ActionExecutionResult;
|
||||
import com.appsmith.server.constants.Url;
|
||||
import com.appsmith.server.domains.Layout;
|
||||
import com.appsmith.server.dtos.ActionDTO;
|
||||
import com.appsmith.server.dtos.ActionMoveDTO;
|
||||
import com.appsmith.server.dtos.ActionViewDTO;
|
||||
import com.appsmith.server.dtos.ExecuteActionDTO;
|
||||
import com.appsmith.server.dtos.LayoutDTO;
|
||||
import com.appsmith.server.dtos.RefactorNameDTO;
|
||||
import com.appsmith.server.dtos.ResponseDTO;
|
||||
import com.appsmith.server.services.ActionCollectionService;
|
||||
|
|
@ -82,7 +82,7 @@ public class ActionController {
|
|||
}
|
||||
|
||||
@PutMapping("/refactor")
|
||||
public Mono<ResponseDTO<Layout>> refactorActionName(@RequestBody RefactorNameDTO refactorNameDTO) {
|
||||
public Mono<ResponseDTO<LayoutDTO>> refactorActionName(@RequestBody RefactorNameDTO refactorNameDTO) {
|
||||
return layoutActionService.refactorActionName(refactorNameDTO)
|
||||
.map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.appsmith.server.controllers;
|
|||
|
||||
import com.appsmith.server.constants.Url;
|
||||
import com.appsmith.server.domains.Layout;
|
||||
import com.appsmith.server.dtos.LayoutDTO;
|
||||
import com.appsmith.server.dtos.RefactorNameDTO;
|
||||
import com.appsmith.server.dtos.ResponseDTO;
|
||||
import com.appsmith.server.services.LayoutActionService;
|
||||
|
|
@ -46,7 +47,7 @@ public class LayoutController {
|
|||
}
|
||||
|
||||
@PutMapping("/{layoutId}/pages/{pageId}")
|
||||
public Mono<ResponseDTO<Layout>> updateLayout(@PathVariable String pageId, @PathVariable String layoutId, @RequestBody Layout layout) {
|
||||
public Mono<ResponseDTO<LayoutDTO>> updateLayout(@PathVariable String pageId, @PathVariable String layoutId, @RequestBody Layout layout) {
|
||||
return layoutActionService.updateLayout(pageId, layoutId, layout)
|
||||
.map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null));
|
||||
}
|
||||
|
|
@ -58,7 +59,7 @@ public class LayoutController {
|
|||
}
|
||||
|
||||
@PutMapping("/refactor")
|
||||
public Mono<ResponseDTO<Layout>> refactorWidgetName(@RequestBody RefactorNameDTO refactorNameDTO) {
|
||||
public Mono<ResponseDTO<LayoutDTO>> refactorWidgetName(@RequestBody RefactorNameDTO refactorNameDTO) {
|
||||
return layoutActionService.refactorWidgetName(refactorNameDTO)
|
||||
.map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.appsmith.server.dtos;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
/**
|
||||
* This class would be used to send any action updates that have happened as part of update layout. The client should
|
||||
* consume this structure to update the actions in its local storage (instead of fetching all the page actions afresh).
|
||||
*/
|
||||
public class LayoutActionUpdateDTO {
|
||||
String id;
|
||||
String name;
|
||||
Boolean executeOnLoad;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.appsmith.server.dtos;
|
||||
|
||||
import com.appsmith.server.domains.ScreenType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minidev.json.JSONObject;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class LayoutDTO {
|
||||
|
||||
private String id;
|
||||
|
||||
ScreenType screen;
|
||||
|
||||
JSONObject dsl;
|
||||
|
||||
List<HashSet<DslActionDTO>> layoutOnLoadActions;
|
||||
|
||||
// All the actions which have been updated as part of updateLayout function call
|
||||
List<LayoutActionUpdateDTO> actionUpdates;
|
||||
|
||||
// All the toast messages that the developer user should be displayed to inform about the consequences of update layout.
|
||||
List<String> messages;
|
||||
|
||||
public Set<String> userPermissions = new HashSet<>();
|
||||
}
|
||||
|
|
@ -4,16 +4,17 @@ import com.appsmith.server.domains.Layout;
|
|||
import com.appsmith.server.dtos.ActionDTO;
|
||||
import com.appsmith.server.dtos.ActionMoveDTO;
|
||||
import com.appsmith.server.dtos.RefactorNameDTO;
|
||||
import com.appsmith.server.dtos.LayoutDTO;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface LayoutActionService {
|
||||
Mono<Layout> updateLayout(String pageId, String layoutId, Layout layout);
|
||||
Mono<LayoutDTO> updateLayout(String pageId, String layoutId, Layout layout);
|
||||
|
||||
Mono<ActionDTO> moveAction(ActionMoveDTO actionMoveDTO);
|
||||
|
||||
Mono<Layout> refactorWidgetName(RefactorNameDTO refactorNameDTO);
|
||||
Mono<LayoutDTO> refactorWidgetName(RefactorNameDTO refactorNameDTO);
|
||||
|
||||
Mono<Layout> refactorActionName(RefactorNameDTO refactorNameDTO);
|
||||
Mono<LayoutDTO> refactorActionName(RefactorNameDTO refactorNameDTO);
|
||||
|
||||
Mono<ActionDTO> updateAction(String id, ActionDTO action);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ import com.appsmith.server.domains.Layout;
|
|||
import com.appsmith.server.dtos.ActionDTO;
|
||||
import com.appsmith.server.dtos.ActionMoveDTO;
|
||||
import com.appsmith.server.dtos.DslActionDTO;
|
||||
import com.appsmith.server.dtos.LayoutActionUpdateDTO;
|
||||
import com.appsmith.server.dtos.PageDTO;
|
||||
import com.appsmith.server.dtos.RefactorNameDTO;
|
||||
import com.appsmith.server.dtos.LayoutDTO;
|
||||
import com.appsmith.server.exceptions.AppsmithError;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
import com.appsmith.server.helpers.MustacheHelper;
|
||||
|
|
@ -121,7 +123,7 @@ public class LayoutActionServiceImpl implements LayoutActionService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mono<Layout> refactorWidgetName(RefactorNameDTO refactorNameDTO) {
|
||||
public Mono<LayoutDTO> refactorWidgetName(RefactorNameDTO refactorNameDTO) {
|
||||
String pageId = refactorNameDTO.getPageId();
|
||||
String layoutId = refactorNameDTO.getLayoutId();
|
||||
String oldName = refactorNameDTO.getOldName();
|
||||
|
|
@ -136,7 +138,7 @@ public class LayoutActionServiceImpl implements LayoutActionService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mono<Layout> refactorActionName(RefactorNameDTO refactorNameDTO) {
|
||||
public Mono<LayoutDTO> refactorActionName(RefactorNameDTO refactorNameDTO) {
|
||||
String pageId = refactorNameDTO.getPageId();
|
||||
String layoutId = refactorNameDTO.getLayoutId();
|
||||
String oldName = refactorNameDTO.getOldName();
|
||||
|
|
@ -167,7 +169,7 @@ public class LayoutActionServiceImpl implements LayoutActionService {
|
|||
* @param newName
|
||||
* @return
|
||||
*/
|
||||
private Mono<Layout> refactorName(String pageId, String layoutId, String oldName, String newName) {
|
||||
private Mono<LayoutDTO> refactorName(String pageId, String layoutId, String oldName, String newName) {
|
||||
String regexPattern = preWord + oldName + postWord;
|
||||
Pattern oldNamePattern = Pattern.compile(regexPattern);
|
||||
|
||||
|
|
@ -466,11 +468,11 @@ public class LayoutActionServiceImpl implements LayoutActionService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mono<Layout> updateLayout(String pageId, String layoutId, Layout layout) {
|
||||
public Mono<LayoutDTO> updateLayout(String pageId, String layoutId, Layout layout) {
|
||||
JSONObject dsl = layout.getDsl();
|
||||
if (dsl == null) {
|
||||
// There is no DSL here. No need to process anything. Return as is.
|
||||
return Mono.just(layout);
|
||||
return Mono.just(generateResponseDTO(layout));
|
||||
}
|
||||
|
||||
Set<String> widgetNames = new HashSet<>();
|
||||
|
|
@ -496,6 +498,8 @@ public class LayoutActionServiceImpl implements LayoutActionService {
|
|||
Set<ActionDependencyEdge> edges = new HashSet<>();
|
||||
Set<String> actionsUsedInDSL = new HashSet<>();
|
||||
List<ActionDTO> flatmapPageLoadActions = new ArrayList<>();
|
||||
List<LayoutActionUpdateDTO> actionUpdates = new ArrayList<>();
|
||||
List<String> messages = new ArrayList<>();
|
||||
|
||||
Mono<List<HashSet<DslActionDTO>>> allOnLoadActionsMono = pageLoadActionsUtil
|
||||
.findAllOnLoadActions(dynamicBindingNames, actionNames, pageId, edges, actionsUsedInDSL, flatmapPageLoadActions);
|
||||
|
|
@ -504,7 +508,9 @@ public class LayoutActionServiceImpl implements LayoutActionService {
|
|||
return allOnLoadActionsMono
|
||||
.flatMap(allOnLoadActions -> {
|
||||
// Update these actions to be executed on load, unless the user has touched the executeOnLoad setting for this
|
||||
return newActionService.setOnLoad((flatmapPageLoadActions)).thenReturn(allOnLoadActions);
|
||||
return newActionService
|
||||
.updateActionsExecuteOnLoad(flatmapPageLoadActions, pageId, actionUpdates, messages)
|
||||
.thenReturn(allOnLoadActions);
|
||||
})
|
||||
.zipWith(newPageService.findByIdAndLayoutsId(pageId, layoutId, MANAGE_PAGES, false)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.ACL_NO_RESOURCE_FOUND,
|
||||
|
|
@ -542,7 +548,26 @@ public class LayoutActionServiceImpl implements LayoutActionService {
|
|||
}
|
||||
}
|
||||
return Mono.empty();
|
||||
})
|
||||
.map(savedLayout -> {
|
||||
LayoutDTO layoutDTO = generateResponseDTO(savedLayout);
|
||||
layoutDTO.setActionUpdates(actionUpdates);
|
||||
layoutDTO.setMessages(messages);
|
||||
return layoutDTO;
|
||||
});
|
||||
}
|
||||
|
||||
private LayoutDTO generateResponseDTO(Layout layout) {
|
||||
|
||||
LayoutDTO layoutDTO = new LayoutDTO();
|
||||
|
||||
layoutDTO.setId(layout.getId());
|
||||
layoutDTO.setDsl(layout.getDsl());
|
||||
layoutDTO.setScreen(layout.getScreen());
|
||||
layoutDTO.setLayoutOnLoadActions(layout.getLayoutOnLoadActions());
|
||||
layoutDTO.setUserPermissions(layout.getUserPermissions());
|
||||
|
||||
return layoutDTO;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.appsmith.server.domains.NewAction;
|
|||
import com.appsmith.server.dtos.ActionDTO;
|
||||
import com.appsmith.server.dtos.ActionViewDTO;
|
||||
import com.appsmith.server.dtos.ExecuteActionDTO;
|
||||
import com.appsmith.server.dtos.LayoutActionUpdateDTO;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
|
@ -57,5 +58,5 @@ public interface NewActionService extends CrudService<NewAction, String> {
|
|||
|
||||
Flux<NewAction> findByPageId(String pageId);
|
||||
|
||||
Mono<Boolean> setOnLoad(List<ActionDTO> actions);
|
||||
Mono<Boolean> updateActionsExecuteOnLoad(List<ActionDTO> actions, String pageId, List<LayoutActionUpdateDTO> actionUpdates, List<String> messages);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import com.appsmith.server.domains.User;
|
|||
import com.appsmith.server.dtos.ActionDTO;
|
||||
import com.appsmith.server.dtos.ActionViewDTO;
|
||||
import com.appsmith.server.dtos.ExecuteActionDTO;
|
||||
import com.appsmith.server.dtos.LayoutActionUpdateDTO;
|
||||
import com.appsmith.server.exceptions.AppsmithError;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
import com.appsmith.server.helpers.MustacheHelper;
|
||||
|
|
@ -42,6 +43,7 @@ import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
|||
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
|
@ -57,6 +59,7 @@ import java.time.Instant;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
|
@ -916,25 +919,147 @@ public class NewActionServiceImpl extends BaseService<NewActionRepository, NewAc
|
|||
return repository.findByPageId(pageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* !!!WARNING!!! This function edits the parameters actionUpdates and messages which are eventually returned back to
|
||||
* the caller with the updates values.
|
||||
* @param onLoadActions : All the actions which have been found to be on page load
|
||||
* @param pageId
|
||||
* @param actionUpdates : Empty array list which would be set in this function with all the page actions whose
|
||||
* execute on load setting has changed (whether flipped from true to false, or vice versa)
|
||||
* @param messages : Empty array list which would be set in this function with all the messages that should be
|
||||
* displayed to the developer user communicating the action executeOnLoad changes.
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> setOnLoad(List<ActionDTO> actions) {
|
||||
if (actions == null) {
|
||||
return Mono.just(FALSE);
|
||||
}
|
||||
public Mono<Boolean> updateActionsExecuteOnLoad(List<ActionDTO> onLoadActions,
|
||||
String pageId,
|
||||
List<LayoutActionUpdateDTO> actionUpdates,
|
||||
List<String> messages) {
|
||||
|
||||
List<ActionDTO> toUpdateActions = new ArrayList<>();
|
||||
for (ActionDTO action : actions) {
|
||||
// If a user has ever set execute on load, this field can not be changed automatically. It has to be
|
||||
// explicitly changed by the user again. Add the action to update only if this condition is false.
|
||||
if (FALSE.equals(action.getUserSetOnLoad())) {
|
||||
action.setExecuteOnLoad(TRUE);
|
||||
toUpdateActions.add(action);
|
||||
}
|
||||
}
|
||||
|
||||
return Flux.fromIterable(toUpdateActions)
|
||||
.flatMap(actionDTO -> updateUnpublishedAction(actionDTO.getId(), actionDTO))
|
||||
.then(Mono.just(TRUE));
|
||||
MultiValueMap<String, String> params = CollectionUtils.toMultiValueMap(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH));
|
||||
params.add(FieldName.PAGE_ID, pageId);
|
||||
|
||||
// Fetch all the actions which exist in this page.
|
||||
Flux<ActionDTO> pageActionsFlux = this.getUnpublishedActions(params).cache();
|
||||
|
||||
// Before we update the actions, fetch all the actions which are currently set to execute on load.
|
||||
Mono<List<ActionDTO>> existingOnPageLoadActionsMono = pageActionsFlux
|
||||
.flatMap(action -> {
|
||||
if (TRUE.equals(action.getExecuteOnLoad())) {
|
||||
return Mono.just(action);
|
||||
}
|
||||
return Mono.empty();
|
||||
})
|
||||
.collectList();
|
||||
|
||||
return existingOnPageLoadActionsMono
|
||||
.zipWith(pageActionsFlux.collectList())
|
||||
.flatMap( tuple -> {
|
||||
List<ActionDTO> existingOnPageLoadActions = tuple.getT1();
|
||||
List<ActionDTO> pageActions = tuple.getT2();
|
||||
|
||||
// There are no actions in this page. No need to proceed further since no actions would get updated
|
||||
if (pageActions.isEmpty()) {
|
||||
return Mono.just(FALSE);
|
||||
}
|
||||
|
||||
// No actions require an update if no actions have been found as page load actions as well as
|
||||
// existing on load page actions are empty
|
||||
if (existingOnPageLoadActions.isEmpty() && (onLoadActions == null || onLoadActions.isEmpty())) {
|
||||
return Mono.just(FALSE);
|
||||
}
|
||||
|
||||
// Extract names of existing pageload actions and new page load actions for quick lookup.
|
||||
Set<String> existingOnPageLoadActionNames = existingOnPageLoadActions
|
||||
.stream()
|
||||
.map(action -> action.getName())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<String> newOnLoadActionNames = onLoadActions
|
||||
.stream()
|
||||
.map(action -> action.getName())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
|
||||
// Calculate the actions which would need to be updated from execute on load TRUE to FALSE.
|
||||
Set<String> turnedOffActionNames = new HashSet<>();
|
||||
turnedOffActionNames.addAll(existingOnPageLoadActionNames);
|
||||
turnedOffActionNames.removeAll(newOnLoadActionNames);
|
||||
|
||||
// Calculate the actions which would need to be updated from execute on load FALSE to TRUE
|
||||
Set<String> turnedOnActionNames = new HashSet<>();
|
||||
turnedOnActionNames.addAll(newOnLoadActionNames);
|
||||
turnedOnActionNames.removeAll(existingOnPageLoadActionNames);
|
||||
|
||||
for (ActionDTO action : pageActions) {
|
||||
|
||||
String actionName = action.getName();
|
||||
// If a user has ever set execute on load, this field can not be changed automatically. It has to be
|
||||
// explicitly changed by the user again. Add the action to update only if this condition is false.
|
||||
if (FALSE.equals(action.getUserSetOnLoad())) {
|
||||
|
||||
// If this action is no longer an onload action, turn the execute on load to false
|
||||
if (turnedOffActionNames.contains(actionName)) {
|
||||
action.setExecuteOnLoad(FALSE);
|
||||
toUpdateActions.add(action);
|
||||
}
|
||||
|
||||
// If this action is newly found to be on load, turn execute on load to true
|
||||
if (turnedOnActionNames.contains(actionName)) {
|
||||
action.setExecuteOnLoad(TRUE);
|
||||
toUpdateActions.add(action);
|
||||
}
|
||||
} else {
|
||||
// Remove the action name from either of the lists (if present) because this action should
|
||||
// not be updated
|
||||
turnedOnActionNames.remove(actionName);
|
||||
turnedOffActionNames.remove(actionName);
|
||||
}
|
||||
}
|
||||
|
||||
// Add newly turned on page actions to report back to the caller
|
||||
actionUpdates.addAll(
|
||||
addActionUpdatesForActionNames(pageActions, turnedOnActionNames)
|
||||
);
|
||||
|
||||
// Add newly turned off page actions to report back to the caller
|
||||
actionUpdates.addAll(
|
||||
addActionUpdatesForActionNames(pageActions, turnedOffActionNames)
|
||||
);
|
||||
|
||||
// Now add messages that would eventually be displayed to the developer user informing them
|
||||
// about the action setting change.
|
||||
if (!turnedOffActionNames.isEmpty()) {
|
||||
messages.add(turnedOffActionNames.toString() + " will no longer be executed on page load");
|
||||
}
|
||||
|
||||
if (!turnedOnActionNames.isEmpty()) {
|
||||
messages.add(turnedOnActionNames.toString() + " will be executed automatically on page load");
|
||||
}
|
||||
|
||||
// Finally update the actions which require an update
|
||||
return Flux.fromIterable(toUpdateActions)
|
||||
.flatMap(actionDTO -> updateUnpublishedAction(actionDTO.getId(), actionDTO))
|
||||
.then(Mono.just(TRUE));
|
||||
});
|
||||
}
|
||||
|
||||
private List<LayoutActionUpdateDTO> addActionUpdatesForActionNames(List<ActionDTO> pageActions,
|
||||
Set<String> actionNames) {
|
||||
|
||||
return pageActions
|
||||
.stream()
|
||||
.filter(pageAction -> actionNames.contains(pageAction.getName()))
|
||||
.map(pageAction -> {
|
||||
LayoutActionUpdateDTO layoutActionUpdateDTO = new LayoutActionUpdateDTO();
|
||||
layoutActionUpdateDTO.setId(pageAction.getId());
|
||||
layoutActionUpdateDTO.setName(pageAction.getName());
|
||||
layoutActionUpdateDTO.setExecuteOnLoad(pageAction.getExecuteOnLoad());
|
||||
return layoutActionUpdateDTO;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import com.appsmith.server.domains.Plugin;
|
|||
import com.appsmith.server.domains.User;
|
||||
import com.appsmith.server.dtos.ActionDTO;
|
||||
import com.appsmith.server.dtos.DslActionDTO;
|
||||
import com.appsmith.server.dtos.LayoutActionUpdateDTO;
|
||||
import com.appsmith.server.dtos.LayoutDTO;
|
||||
import com.appsmith.server.dtos.PageDTO;
|
||||
import com.appsmith.server.dtos.RefactorNameDTO;
|
||||
import com.appsmith.server.helpers.MockPluginExecutor;
|
||||
|
|
@ -37,6 +39,7 @@ import reactor.test.StepVerifier;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -216,7 +219,7 @@ public class LayoutActionServiceTest {
|
|||
|
||||
ActionDTO createdAction = newActionService.createAction(action).block();
|
||||
|
||||
Layout firstLayout = layoutActionService.updateLayout(testPage.getId(), layout.getId(), layout).block();
|
||||
LayoutDTO firstLayout = layoutActionService.updateLayout(testPage.getId(), layout.getId(), layout).block();
|
||||
|
||||
|
||||
RefactorNameDTO refactorNameDTO = new RefactorNameDTO();
|
||||
|
|
@ -225,7 +228,7 @@ public class LayoutActionServiceTest {
|
|||
refactorNameDTO.setOldName("beforeNameChange");
|
||||
refactorNameDTO.setNewName("PostNameChange");
|
||||
|
||||
Layout postNameChangeLayout = layoutActionService.refactorActionName(refactorNameDTO).block();
|
||||
LayoutDTO postNameChangeLayout = layoutActionService.refactorActionName(refactorNameDTO).block();
|
||||
|
||||
Mono<NewAction> postNameChangeActionMono = newActionService.findById(createdAction.getId(), READ_ACTIONS);
|
||||
|
||||
|
|
@ -238,11 +241,105 @@ public class LayoutActionServiceTest {
|
|||
DslActionDTO actionDTO = postNameChangeLayout.getLayoutOnLoadActions().get(0).iterator().next();
|
||||
assertThat(actionDTO.getName()).isEqualTo("PostNameChange");
|
||||
|
||||
// JSONObject newDsl = new JSONObject(Map.of("widgetName", "firstWidget", "mustacheProp", "{{ PostNameChange.data }}"));
|
||||
dsl.put("testField", "{{ PostNameChange.data }}");
|
||||
assertThat(postNameChangeLayout.getDsl()).isEqualTo(dsl);
|
||||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUserDetails(value = "api_user")
|
||||
public void actionExecuteOnLoadChangeOnUpdateLayout() {
|
||||
Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())).thenReturn(Mono.just(new MockPluginExecutor()));
|
||||
|
||||
ActionDTO action1 = new ActionDTO();
|
||||
action1.setName("firstAction");
|
||||
action1.setPageId(testPage.getId());
|
||||
ActionConfiguration actionConfiguration1 = new ActionConfiguration();
|
||||
actionConfiguration1.setHttpMethod(HttpMethod.GET);
|
||||
action1.setActionConfiguration(actionConfiguration1);
|
||||
action1.setDatasource(datasource);
|
||||
|
||||
ActionDTO action2 = new ActionDTO();
|
||||
action2.setName("secondAction");
|
||||
action2.setPageId(testPage.getId());
|
||||
ActionConfiguration actionConfiguration2 = new ActionConfiguration();
|
||||
actionConfiguration2.setHttpMethod(HttpMethod.GET);
|
||||
action2.setActionConfiguration(actionConfiguration2);
|
||||
action2.setDatasource(datasource);
|
||||
|
||||
JSONObject dsl = new JSONObject();
|
||||
dsl.put("widgetName", "firstWidget");
|
||||
JSONArray temp = new JSONArray();
|
||||
temp.addAll(List.of(new JSONObject(Map.of("key", "testField"))));
|
||||
dsl.put("dynamicBindingPathList", temp);
|
||||
dsl.put("testField", "{{ firstAction.data }}");
|
||||
|
||||
Layout layout = testPage.getLayouts().get(0);
|
||||
layout.setDsl(dsl);
|
||||
|
||||
ActionDTO createdAction1 = newActionService.createAction(action1).block();
|
||||
ActionDTO createdAction2 = newActionService.createAction(action2).block();
|
||||
|
||||
Mono<LayoutDTO> updateLayoutMono = layoutActionService.updateLayout(testPage.getId(), layout.getId(), layout);
|
||||
|
||||
StepVerifier.create(updateLayoutMono)
|
||||
.assertNext(updatedLayout -> {
|
||||
log.debug("{}", updatedLayout.getMessages());
|
||||
DslActionDTO actionDTO = updatedLayout.getLayoutOnLoadActions().get(0).iterator().next();
|
||||
assertThat(actionDTO.getName()).isEqualTo("firstAction");
|
||||
|
||||
List<LayoutActionUpdateDTO> actionUpdates = updatedLayout.getActionUpdates();
|
||||
assertThat(actionUpdates.size()).isEqualTo(1);
|
||||
assertThat(actionUpdates.get(0).getName()).isEqualTo("firstAction");
|
||||
assertThat(actionUpdates.get(0).getExecuteOnLoad()).isTrue();
|
||||
})
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(newActionService.findById(createdAction1.getId()))
|
||||
.assertNext(newAction -> assertThat(newAction.getUnpublishedAction().getExecuteOnLoad()).isTrue());
|
||||
|
||||
StepVerifier.create(newActionService.findById(createdAction2.getId()))
|
||||
.assertNext(newAction -> assertThat(newAction.getUnpublishedAction().getExecuteOnLoad()).isFalse());
|
||||
|
||||
dsl = new JSONObject();
|
||||
dsl.put("widgetName", "firstWidget");
|
||||
temp = new JSONArray();
|
||||
temp.addAll(List.of(new JSONObject(Map.of("key", "testField"))));
|
||||
dsl.put("dynamicBindingPathList", temp);
|
||||
dsl.put("testField", "{{ secondAction.data }}");
|
||||
|
||||
layout.setDsl(dsl);
|
||||
|
||||
updateLayoutMono = layoutActionService.updateLayout(testPage.getId(), layout.getId(), layout);
|
||||
|
||||
StepVerifier.create(updateLayoutMono)
|
||||
.assertNext(updatedLayout -> {
|
||||
log.debug("{}", updatedLayout.getMessages());
|
||||
DslActionDTO actionDTO = updatedLayout.getLayoutOnLoadActions().get(0).iterator().next();
|
||||
assertThat(actionDTO.getName()).isEqualTo("secondAction");
|
||||
|
||||
List<LayoutActionUpdateDTO> actionUpdates = updatedLayout.getActionUpdates();
|
||||
assertThat(actionUpdates.size()).isEqualTo(2);
|
||||
|
||||
Optional<LayoutActionUpdateDTO> firstActionUpdateOptional = actionUpdates.stream().filter(actionUpdate -> actionUpdate.getName().equals("firstAction")).findFirst();
|
||||
LayoutActionUpdateDTO firstActionUpdate = firstActionUpdateOptional.get();
|
||||
assertThat(firstActionUpdate).isNotNull();
|
||||
assertThat(firstActionUpdate.getExecuteOnLoad()).isFalse();
|
||||
|
||||
Optional<LayoutActionUpdateDTO> secondActionUpdateOptional = actionUpdates.stream().filter(actionUpdate -> actionUpdate.getName().equals("secondAction")).findFirst();
|
||||
LayoutActionUpdateDTO secondActionUpdate = secondActionUpdateOptional.get();
|
||||
assertThat(secondActionUpdate).isNotNull();
|
||||
assertThat(secondActionUpdate.getExecuteOnLoad()).isTrue();
|
||||
})
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(newActionService.findById(createdAction1.getId()))
|
||||
.assertNext(newAction -> assertThat(newAction.getUnpublishedAction().getExecuteOnLoad()).isFalse());
|
||||
|
||||
StepVerifier.create(newActionService.findById(createdAction2.getId()))
|
||||
.assertNext(newAction -> assertThat(newAction.getUnpublishedAction().getExecuteOnLoad()).isTrue());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,12 @@ import com.appsmith.server.constants.FieldName;
|
|||
import com.appsmith.server.domains.Application;
|
||||
import com.appsmith.server.domains.Datasource;
|
||||
import com.appsmith.server.domains.Layout;
|
||||
import com.appsmith.server.domains.NewAction;
|
||||
import com.appsmith.server.domains.NewPage;
|
||||
import com.appsmith.server.domains.Plugin;
|
||||
import com.appsmith.server.domains.PluginType;
|
||||
import com.appsmith.server.domains.User;
|
||||
import com.appsmith.server.dtos.ActionDTO;
|
||||
import com.appsmith.server.dtos.DslActionDTO;
|
||||
import com.appsmith.server.dtos.LayoutDTO;
|
||||
import com.appsmith.server.dtos.PageDTO;
|
||||
import com.appsmith.server.exceptions.AppsmithError;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
|
|
@ -205,7 +204,7 @@ public class LayoutServiceTest {
|
|||
|
||||
Layout startLayout = layoutService.createLayout(page.getId(), testLayout).block();
|
||||
|
||||
Mono<Layout> updatedLayoutMono = layoutActionService.updateLayout("random-impossible-id-page", startLayout.getId(), updateLayout);
|
||||
Mono<LayoutDTO> updatedLayoutMono = layoutActionService.updateLayout("random-impossible-id-page", startLayout.getId(), updateLayout);
|
||||
|
||||
StepVerifier
|
||||
.create(updatedLayoutMono)
|
||||
|
|
@ -238,7 +237,7 @@ public class LayoutServiceTest {
|
|||
|
||||
Mono<Layout> startLayoutMono = pageMono.flatMap(page -> layoutService.createLayout(page.getId(), testLayout));
|
||||
|
||||
Mono<Layout> updatedLayoutMono = Mono.zip(pageMono, startLayoutMono)
|
||||
Mono<LayoutDTO> updatedLayoutMono = Mono.zip(pageMono, startLayoutMono)
|
||||
.flatMap(tuple -> {
|
||||
PageDTO page = tuple.getT1();
|
||||
Layout startLayout = tuple.getT2();
|
||||
|
|
@ -276,7 +275,7 @@ public class LayoutServiceTest {
|
|||
|
||||
Mono<PageDTO> pageMono = createPage(app, testPage).cache();
|
||||
|
||||
Mono<Layout> testMono = pageMono
|
||||
Mono<LayoutDTO> testMono = pageMono
|
||||
.flatMap(page1 -> {
|
||||
List<Mono<ActionDTO>> monos = new ArrayList<>();
|
||||
|
||||
|
|
@ -464,7 +463,7 @@ public class LayoutServiceTest {
|
|||
|
||||
Mono<PageDTO> pageMono = createPage(app, testPage).cache();
|
||||
|
||||
Mono<Layout> testMono = pageMono
|
||||
Mono<LayoutDTO> testMono = pageMono
|
||||
.flatMap(page1 -> {
|
||||
List<Mono<ActionDTO>> monos = new ArrayList<>();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user