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

[backend/frontend] Filters options should not be limit to 10 #1430

Merged
merged 1 commit into from
Sep 13, 2024
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
Expand Up @@ -20,8 +20,8 @@
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -177,7 +177,7 @@

@GetMapping(ATTACK_PATTERN_URI + "/options")
public List<FilterUtilsJpa.Option> optionsByName(@RequestParam(required = false) final String searchText) {
return fromIterable(this.attackPatternRepository.findAll(byName(searchText), PageRequest.of(0, 10)))
return fromIterable(this.attackPatternRepository.findAll(byName(searchText), Sort.by(Sort.Direction.ASC, "name")))

Check warning on line 180 in openbas-api/src/main/java/io/openbas/rest/attack_pattern/AttackPatternApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/attack_pattern/AttackPatternApi.java#L180

Added line #L180 was not covered by tests
.stream()
.map(i -> new FilterUtilsJpa.Option(i.getId(), i.getName()))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -335,7 +335,7 @@

@GetMapping(INJECT0R_URI + "/options")
public List<FilterUtilsJpa.Option> optionsByName(@RequestParam(required = false) final String searchText) {
return fromIterable(this.injectorRepository.findAll(byName(searchText), PageRequest.of(0, 10)))
return fromIterable(this.injectorRepository.findAll(byName(searchText), Sort.by(Sort.Direction.ASC, "name")))

Check warning on line 338 in openbas-api/src/main/java/io/openbas/rest/injector/InjectorApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/injector/InjectorApi.java#L338

Added line #L338 was not covered by tests
.stream()
.map(i -> new FilterUtilsJpa.Option(i.getId(), i.getName()))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -128,7 +128,7 @@

@GetMapping(KILL_CHAIN_PHASE_URI + "/options")
public List<FilterUtilsJpa.Option> optionsByName(@RequestParam(required = false) final String searchText) {
return fromIterable(this.killChainPhaseRepository.findAll(byName(searchText), PageRequest.of(0, 10)))
return fromIterable(this.killChainPhaseRepository.findAll(byName(searchText), Sort.by(Sort.Direction.ASC, "name")))

Check warning on line 131 in openbas-api/src/main/java/io/openbas/rest/kill_chain_phase/KillChainPhaseApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/kill_chain_phase/KillChainPhaseApi.java#L131

Added line #L131 was not covered by tests
.stream()
.map(i -> new FilterUtilsJpa.Option(i.getId(), i.getName()))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
Expand Down Expand Up @@ -244,7 +245,7 @@

@GetMapping(SCENARIO_URI + "/options")
public List<FilterUtilsJpa.Option> optionsByName(@RequestParam(required = false) final String searchText) {
return fromIterable(this.scenarioRepository.findAll(byName(searchText), PageRequest.of(0, 10)))
return fromIterable(this.scenarioRepository.findAll(byName(searchText), Sort.by(Sort.Direction.ASC, "name")))

Check warning on line 248 in openbas-api/src/main/java/io/openbas/rest/scenario/ScenarioApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/scenario/ScenarioApi.java#L248

Added line #L248 was not covered by tests
.stream()
.map(i -> new FilterUtilsJpa.Option(i.getId(), i.getName()))
.toList();
Expand Down
4 changes: 2 additions & 2 deletions openbas-api/src/main/java/io/openbas/rest/tag/TagApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -96,7 +96,7 @@

@GetMapping(TAG_URI + "/options")
public List<FilterUtilsJpa.Option> optionsByName(@RequestParam(required = false) final String searchText) {
return fromIterable(this.tagRepository.findAll(byName(searchText), PageRequest.of(0, 10)))
return fromIterable(this.tagRepository.findAll(byName(searchText), Sort.by(Sort.Direction.ASC, "name")))

Check warning on line 99 in openbas-api/src/main/java/io/openbas/rest/tag/TagApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/tag/TagApi.java#L99

Added line #L99 was not covered by tests
.stream()
.map(i -> new FilterUtilsJpa.Option(i.getId(), i.getName()))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const BasicSelectInput: FunctionComponent<Props & { propertySchema: Prope
e.stopPropagation();
}
}}
key={option.id}
onClick={() => onClick(option.id)}
style={{
whiteSpace: 'nowrap',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const useRetrieveOptions = () => {
case 'scenario_tags':
case 'exercise_tags':
case 'inject_tags':
case 'payload_tags':
searchTagByIdAsOption(ids).then((response) => {
setOptions(response.data);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const useSearchOptions = () => {
case 'scenario_tags':
case 'exercise_tags':
case 'inject_tags':
case 'payload_tags':
searchTagAsOption(search).then((response) => {
setOptions(response.data);
});
Expand Down