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

DAC-340 [FE] Stop a test campaign #48

Merged
merged 9 commits into from
Mar 9, 2023
9 changes: 6 additions & 3 deletions react-web/src/pages/certification/Certification.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
margin-bottom: 20px;
color: $body-text-gray;
}
.btn {
.footer {
display: flex;
margin: 0 auto;
min-width: 160px;
justify-content: center;
column-gap: 10px;
.btn {
display: flex;
}
}
}

Expand Down
32 changes: 26 additions & 6 deletions react-web/src/pages/certification/Certification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import CreateCertificate from "components/CreateCertificate/CreateCertificate";

import { useAppDispatch, useAppSelector } from "store/store";
import { clearUuid, setUuid } from "./slices/certification.slice";
import { deleteTestHistoryData } from "pages/testHistory/slices/deleteTestHistory.slice";
import { useConfirm } from "material-ui-confirm";

const TIMEOFFSET = 1000;

Expand All @@ -42,6 +44,7 @@ const Certification = () => {
const { uuid } = useAppSelector((state) => state.certification);
const { userDetails } = useAppSelector((state) => state.auth);
const dispatch = useAppDispatch();
const confirm = useConfirm();
const [submitting, setSubmitting] = useState(false);
const [formSubmitted, setFormSubmitted] = useState(false);
const [timelineConfig, setTimelineConfig] = useState(TIMELINE_CONFIG);
Expand Down Expand Up @@ -188,6 +191,14 @@ const Certification = () => {
exportObjectToJsonFile(resultData);
};

const abortRun = () => {
confirm({ title: "", description: "Are sure you want to abort this run!" })
.then(async () => {
await dispatch(deleteTestHistoryData({ url: "/run/" + uuid + "?delete=true" }));
resetStates()
}).catch(() => { });
}

useEffect(() => {
if (uuid.length) {
triggerFetchRunStatus();
Expand Down Expand Up @@ -252,17 +263,26 @@ const Certification = () => {
disabled={submitting}
{...form.register("commit")}
/>
<div className="footer">
<Button
type="submit"
className="btn btn-primary"
buttonLabel={"Start Testing"}
showLoader={
submitting &&
(runStatus !== "finished" && runState !== "failed")
}
buttonLabel={"Start Testing"}
showLoader={
submitting &&
(runStatus !== "finished" && runState !== "failed")
}
disabled={!form.formState.isValid || submitting}
onClick={(_) => setFormSubmitted(true)}
/>
{(apiFetching && submitting) && (
<Button
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if adding some extra status condition for this button is the case, but I'm wondering if you have to add a condition for this abort button's visibility when the certification has already started.
There is no way to abort/delete a Run after the certification was started. At least not for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be ideal to hold this until ready-for-certification runStatus is integrated. Will revisit this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarification - 'Abort Run' button will be visible only until status: finished, i.e. only visible when the test campaign is still running.

I've integrated aborted and ready-for-certification statuses into History table, also made sure to prevent delete of any campaign from history if the runStatus: ready-for-certification.

type="button"
displayStyle="primary-outline"
buttonLabel="Abort Run"
onClick={(_) => abortRun()}
/>
)}
</div>
</Form>
</div>
</div>
Expand Down
33 changes: 21 additions & 12 deletions react-web/src/pages/testHistory/TestHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ICampaign {
finishedAt: string;
syncedAt: string;
repoUrl: string;
runStatus: "queued" | "failed" | "succeeded" | "certified";
runStatus: "queued" | "failed" | "succeeded" | "certified" | "ready-for-certification" | "aborted";
runId: string;
}

Expand Down Expand Up @@ -163,6 +163,13 @@ const TestHistory = () => {
</button>
</>
);
} else if (value === "aborted") {
return <span
style={{ color: "red" }}
className={highlightLabelFor === runId ? "cell-highlight" : ""}>Aborted</span>;
} else if (value === "ready-for-certification") {
return <span
className={highlightLabelFor === runId ? "cell-highlight" : ""}>Ready for Certification</span>;
}
};

Expand Down Expand Up @@ -249,7 +256,7 @@ const TestHistory = () => {
disableSortBy: true,
accessor: "viewReport",
Cell: (props: any) => {
if (props.row.original.runStatus === "succeeded" || props.row.original.runStatus === "certified") {
if (props.row.original.runStatus === "succeeded" || props.row.original.runStatus === "ready-for-certification" || props.row.original.runStatus === "certified") {
return (
<Button
size="small"
Expand Down Expand Up @@ -287,16 +294,18 @@ const TestHistory = () => {
disableSortBy: true,
accessor: "delete",
Cell: (props: any) => {
return (<>
<button
className="trash-icon-btn"
onClick={() => {
onDelete(props.row.original.runId);
}}
>
<img className="icon-trash" src="images/trash.svg" alt="delete" title="Delete Campaign" />
</button>
</>);
if (props.row.original.runStatus !== "certified" && props.row.original.runStatus !== "ready-for-certification") {
return (<>
<button
className="trash-icon-btn"
onClick={() => {
onDelete(props.row.original.runId);
}}
>
<img className="icon-trash" src="images/trash.svg" alt="delete" title="Delete Campaign" />
</button>
</>);
}
},
}
],
Expand Down