Skip to content

Commit

Permalink
Add delete and replay all
Browse files Browse the repository at this point in the history
  • Loading branch information
johanah29 committed Aug 30, 2024
1 parent 3abb47d commit cd8f157
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
11 changes: 7 additions & 4 deletions openbas-front/src/admin/components/injects/InjectTestList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { makeStyles } from '@mui/styles';
import React, { CSSProperties, FunctionComponent, useEffect, useState } from 'react';
import { List, ListItem, ListItemButton, ListItemIcon, ListItemSecondaryAction, ListItemText, Tooltip } from '@mui/material';
import { List, ListItem, ListItemButton, ListItemIcon, ListItemSecondaryAction, ListItemText } from '@mui/material';
import type { InjectTestStatus, SearchPaginationInput } from '../../../utils/api-types';
import { useFormatter } from '../../../components/i18n';
import ItemStatus from '../../../components/ItemStatus';
Expand Down Expand Up @@ -81,7 +81,6 @@ const InjectTestList: FunctionComponent<Props> = ({
}
}, [statusId]);


// Headers
const headers = [
{
Expand Down Expand Up @@ -117,7 +116,7 @@ const InjectTestList: FunctionComponent<Props> = ({
searchPaginationInput={searchPaginationInput}
setContent={setTests}
>
<InjectTestReplayAll tests={tests} />
<InjectTestReplayAll injectIds={tests?.map((test: InjectTestStatus) => test.inject_id!)} onTest={(result) => setTests(result)} />
</PaginationComponent>
<List style={{ marginTop: 40 }}>
<ListItem
Expand Down Expand Up @@ -179,7 +178,11 @@ const InjectTestList: FunctionComponent<Props> = ({
/>
</ListItemButton>
<ListItemSecondaryAction>
<InjectTestPopover injectTestStatus={test} />
<InjectTestPopover
injectTestStatus={test}
onTest={(result) => setTests(tests?.map((existing) => (existing.status_id !== result.status_id ? existing : result)))}
onDelete={(result) => setTests(tests.filter((existing) => (existing.status_id !== result)))}
/>
</ListItemSecondaryAction>
</ListItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import DialogTest from '../../../components/common/DialogTest';

interface Props {
injectTestStatus: InjectTestStatus;
onTest?: (result: InjectTestStatus) => void;
onDelete?: (result: string) => void;
}

const InjectTestPopover: FunctionComponent<Props> = ({
injectTestStatus,
onDelete,
onTest,
}) => {
// Standard hooks
const { t } = useFormatter();
Expand All @@ -38,6 +42,9 @@ const InjectTestPopover: FunctionComponent<Props> = ({
const handleCloseDelete = () => setOpenDelete(false);
const submitDelete = () => {
deleteInjectTest(injectTestStatus.status_id);
if (onDelete) {
onDelete(injectTestStatus.status_id!);
}
handleCloseDelete();
};

Expand All @@ -53,7 +60,8 @@ const InjectTestPopover: FunctionComponent<Props> = ({

const submitTest = () => {
testInject(injectTestStatus.inject_id!).then((result: { data: InjectTestStatus }) => {
setInjectTestResult(result.data);
onTest?.(result.data);
return result;
});
handleCloseTest();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { bulkTestInjects } from '../../../actions/injects/inject-action';
import DialogTest from '../../../components/common/DialogTest';

interface Props {
tests: InjectTestStatus[] | null;
injectIds: string[] | undefined;
onTest?: (result: InjectTestStatus[]) => void;
}

const ImportUploaderMapper: FunctionComponent<Props> = ({
tests,
injectIds,
onTest,
}) => {
// Standard hooks
const { t } = useFormatter();
Expand All @@ -26,8 +28,9 @@ const ImportUploaderMapper: FunctionComponent<Props> = ({
};

const handleSubmitAllTest = () => {
bulkTestInjects(tests!.map((test: InjectTestStatus) => test.inject_id!)).then((result: { data: InjectTestStatus[] }) => {
console.log(result);
bulkTestInjects(injectIds!).then((result: { data: InjectTestStatus[] }) => {
onTest?.(result.data);
return result;
});
handleCloseAllTest();
};
Expand All @@ -39,7 +42,7 @@ const ImportUploaderMapper: FunctionComponent<Props> = ({
<IconButton
aria-label="test"
disabled={
tests?.length === 0
injectIds?.length === 0
}
onClick={handleOpenAllTest}
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public abstract class BaseInjectStatus implements Base {
// endregion

@Queryable(searchable = true, property = "title")
@OneToOne
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "status_inject")
@JsonIgnore
protected Inject inject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package io.openbas.database.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.openbas.database.converter.InjectStatusExecutionConverter;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.annotations.UuidGenerator;

import java.time.Instant;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Setter
Expand Down

0 comments on commit cd8f157

Please sign in to comment.