Skip to content

Commit

Permalink
chore: code split for entity search (#31332)
Browse files Browse the repository at this point in the history
## Description
> Code split for entity search.
> 1. Move the methods to SearchEntityHelper to be readily available for
re-use.
> 2. Rename SearchEntitySolutionTest -> SearchEntitySolutionCETest

#### PR fixes following issue(s)
Fixes [[Task]: Add search functionality for workflows
#30843](#30843)

#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing
>
#### How Has This Been Tested?
> None, as this is just a refactor.

#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Improved code efficiency in search functionality by centralizing the
logic for creating pageable and sort objects.
- **Tests**
	- Renamed a test class to better reflect its purpose.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com>
  • Loading branch information
nsarupr and nsarupr authored Feb 28, 2024
1 parent d25ae85 commit f715cfd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.ArrayList;
import java.util.List;

import static com.appsmith.server.searchentities.helpers.SearchEntityHelper.getPageable;
import static com.appsmith.server.searchentities.helpers.SearchEntityHelper.getSort;
import static com.appsmith.server.searchentities.helpers.SearchEntityHelper.shouldSearchEntity;

@RequiredArgsConstructor
Expand Down Expand Up @@ -55,8 +57,8 @@ public Mono<SearchEntityDTO> searchEntity(
if (size == 0) {
return Mono.just(new SearchEntityDTO());
}
Pageable pageable = Pageable.ofSize(size).withPage(page);
Sort sort = Sort.by(Sort.Direction.DESC, FieldName.UPDATED_AT);
Pageable pageable = getPageable(page, size);
Sort sort = getSort();
searchString = StringUtils.hasLength(searchString) ? searchString.trim() : "";
// If no entities are specified, search for all entities.
Mono<List<Workspace>> workspacesMono = Mono.just(new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.appsmith.server.searchentities.helpers;

import com.appsmith.server.constants.FieldName;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

public class SearchEntityHelper {
/**
* This method checks if the entity should be searched based on the entities list provided. If the entities list is null or empty, then all entities are searched.
Expand All @@ -19,4 +23,12 @@ public static boolean shouldSearchEntity(Class<?> entity, String[] entities) {
}
return false;
}

public static Sort getSort() {
return Sort.by(Sort.Direction.DESC, FieldName.UPDATED_AT);
}

public static Pageable getPageable(int page, int size) {
return Pageable.ofSize(size).withPage(page);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

@SpringBootTest
class SearchEntitySolutionTest {
class SearchEntitySolutionCETest {

@Autowired
ApplicationPageService applicationPageService;
Expand Down

0 comments on commit f715cfd

Please sign in to comment.