Skip to content

Commit

Permalink
[backend/frontend] Sort simulation by updated date (#1153)
Browse files Browse the repository at this point in the history
* [backend/frontend] Sort simulation by updated date

* [backend/frontend] Fix lint
  • Loading branch information
RomuDeuxfois authored Jun 25, 2024
1 parent a4c2163 commit 17f21f4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ private void select(CriteriaBuilder cb, CriteriaQuery<Tuple> cq, Root<Exercise>
exerciseRoot.get("subtitle").alias("exercise_subtitle"),
exerciseRoot.get("category").alias("exercise_category"),
exerciseRoot.get("start").alias("exercise_start_date"),
exerciseRoot.get("updatedAt").alias("exercise_updated_at"),
tagIdsExpression.alias("exercise_tags"),
injectIdsExpression.alias("exercise_injects")
).distinct(true);
Expand All @@ -141,6 +142,7 @@ private List<ExerciseSimple> execution(TypedQuery<Tuple> query) {
exerciseSimple.setSubtitle(tuple.get("exercise_subtitle", String.class));
exerciseSimple.setCategory(tuple.get("exercise_category", String.class));
exerciseSimple.setStart(tuple.get("exercise_start_date", Instant.class));
exerciseSimple.setUpdatedAt(tuple.get("exercise_updated_at", Instant.class));
exerciseSimple.setTags(
Arrays.stream(tuple.get("exercise_tags", String[].class))
.map(t -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import static io.openbas.utils.ResultUtils.computeGlobalExpectationResults;
import static io.openbas.utils.ResultUtils.computeTargetResults;
import static java.time.Instant.now;

@Setter
@Getter
Expand All @@ -55,6 +56,9 @@ public class ExerciseSimple {
@JsonProperty("exercise_start_date")
private Instant start;

@JsonProperty("exercise_updated_at")
private Instant updatedAt = now();

@JsonSerialize(using = MultiIdSetDeserializer.class)
@JsonProperty("exercise_tags")
private Set<Tag> tags = new HashSet<>();
Expand All @@ -73,6 +77,7 @@ public static ExerciseSimple fromExercise(Exercise exercise) {
ExerciseSimple simple = new ExerciseSimple();
BeanUtils.copyProperties(exercise, simple);
simple.setStart(exercise.getStart().orElse(null));
simple.setUpdatedAt(exercise.getUpdatedAt());
simple.setExpectationResultByTypes(computeGlobalExpectationResults(exercise.getInjects()));
simple.setTargets(computeTargetResults(exercise.getInjects()));
return simple;
Expand Down Expand Up @@ -102,6 +107,7 @@ public static ExerciseSimple fromRawExercise(RawExercise exercise, List<Inject>
simple.setSubtitle(exercise.getExercise_subtitle());
simple.setStatus(ExerciseStatus.valueOf(exercise.getExercise_status()));
simple.setStart(exercise.getExercise_start_date());
simple.setUpdatedAt(exercise.getExercise_updated_at());

// We set the ExpectationResults
simple.setExpectationResultByTypes(AtomicTestingUtils
Expand Down
24 changes: 12 additions & 12 deletions openbas-front/src/admin/components/atomic_testings/InjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const inlineStyles: Record<string, CSSProperties> = {
width: '15%',
},
inject_status: {
width: '15%',
width: '10%',
},
inject_targets: {
width: '20%',
Expand All @@ -68,7 +68,7 @@ const inlineStyles: Record<string, CSSProperties> = {
cursor: 'default',
},
inject_updated_at: {
width: '10%',
width: '15%',
},
};

Expand All @@ -83,7 +83,7 @@ const InjectList: FunctionComponent<Props> = ({
}) => {
// Standard hooks
const classes = useStyles();
const { t, fldt, tPick } = useFormatter();
const { t, fldt, tPick, nsdt } = useFormatter();

// Filter and sort hook
const [injects, setInjects] = useState<InjectResultDTO[]>([]);
Expand Down Expand Up @@ -118,14 +118,6 @@ const InjectList: FunctionComponent<Props> = ({
isSortable: false,
value: (injectDto: InjectResultDTO) => fldt(injectDto.inject_status?.tracking_sent_date),
},
{
field: 'inject_targets',
label: 'Target',
isSortable: false,
value: (injectDto: InjectResultDTO) => {
return (<ItemTargets targets={injectDto.inject_targets} />);
},
},
{
field: 'inject_status',
label: 'Status',
Expand All @@ -134,6 +126,14 @@ const InjectList: FunctionComponent<Props> = ({
return (<ItemStatus isInject={true} status={injectDto.inject_status?.status_name} label={t(injectDto.inject_status?.status_name)} variant="inList" />);
},
},
{
field: 'inject_targets',
label: 'Target',
isSortable: false,
value: (injectDto: InjectResultDTO) => {
return (<ItemTargets targets={injectDto.inject_targets} />);
},
},
{
field: 'inject_expectations',
label: 'Global score',
Expand All @@ -148,7 +148,7 @@ const InjectList: FunctionComponent<Props> = ({
field: 'inject_updated_at',
label: 'Updated',
isSortable: true,
value: (injectDto: InjectResultDTO) => fldt(injectDto.inject_updated_at),
value: (injectDto: InjectResultDTO) => nsdt(injectDto.inject_updated_at),
},
];

Expand Down
2 changes: 1 addition & 1 deletion openbas-front/src/admin/components/scenarios/Scenarios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const inlineStyles: Record<string, CSSProperties> = {
cursor: 'default',
},
scenario_tags: {
width: '18%',
width: '15%',
},
scenario_updated_at: {
width: '10%',
Expand Down
31 changes: 20 additions & 11 deletions openbas-front/src/admin/components/simulations/ExerciseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,25 @@ const useStyles = makeStyles(() => ({

const inlineStyles: Record<string, CSSProperties> = {
exercise_name: {
width: '20%',
width: '15%',
},
exercise_start_date: {
width: '15%',
},
exercise_status: {
width: '10%',
},
exercise_tags: {
width: '15%',
},
exercise_targets: {
width: '20%',
},
exercise_global_score: {
width: '20%',
width: '10%',
},
exercise_tags: {
width: '15%',
},
exercise_updated_at: {
width: '15%',
},
};

Expand Down Expand Up @@ -106,12 +109,6 @@ const ExerciseList: FunctionComponent<Props> = ({
isSortable: true,
value: (exercise: ExerciseSimple) => <ExerciseStatus variant="list" exerciseStatus={exercise.exercise_status} />,
},
{
field: 'exercise_tags',
label: 'Tags',
isSortable: true,
value: (exercise: ExerciseSimple) => <ItemTags variant="list" tags={exercise.exercise_tags} />,
},
{
field: 'exercise_targets',
label: 'Target',
Expand All @@ -124,6 +121,18 @@ const ExerciseList: FunctionComponent<Props> = ({
isSortable: false,
value: (exercise: ExerciseSimple) => <AtomicTestingResult expectations={exercise.exercise_global_score} />,
},
{
field: 'exercise_tags',
label: 'Tags',
isSortable: true,
value: (exercise: ExerciseSimple) => <ItemTags variant="list" tags={exercise.exercise_tags} />,
},
{
field: 'exercise_updated_at',
label: 'Updated',
isSortable: true,
value: (exercise: ExerciseSimple) => nsdt(exercise.exercise_updated_at),
},
];

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Exercises = () => {

const [exercises, setExercises] = useState<EndpointStore[]>([]);
const [searchPaginationInput, setSearchPaginationInput] = useState<SearchPaginationInput>({
sorts: initSorting('exercise_start_date'),
sorts: initSorting('exercise_updated_at'),
});

// Export
Expand Down
3 changes: 3 additions & 0 deletions openbas-front/src/utils/api-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ export interface ExerciseSimple {
/** @uniqueItems true */
exercise_tags?: Tag[];
exercise_targets: InjectTargetWithResult[];
/** @format date-time */
exercise_updated_at?: string;
}

export interface ExerciseTeamPlayersEnableInput {
Expand Down Expand Up @@ -1099,6 +1101,7 @@ export interface InjectInput {
}

export interface InjectOutput {
inject_content?: object;
/**
* @format int64
* @min 0
Expand Down

0 comments on commit 17f21f4

Please sign in to comment.