Skip to content

Commit

Permalink
[backend/frontend] Filters options should not be limit to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
RomuDeuxfois authored Sep 13, 2024
1 parent 250b2f8 commit b2674d0
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 9 deletions.
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 @@ public void deleteAttackPattern(@PathVariable String attackPatternId) {

@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")))
.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 @@ public InjectorRegistration registerInjector(@Valid @RequestPart("input") Inject

@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")))
.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 @@ public void deleteKillChainPhase(@PathVariable String killChainPhaseId) {

@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")))
.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 @@ public Scenario updateScenarioRecurrence(

@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")))
.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 @@ public void deleteTag(@PathVariable String tagId) {

@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")))
.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

0 comments on commit b2674d0

Please sign in to comment.