Skip to content

Commit

Permalink
fix: Invert logic of isActiveJobStatus helper function (#354)
Browse files Browse the repository at this point in the history
* Invert logic of isActiveJobStatus helper function

* Refactor delete job modal to use shared helper function
  • Loading branch information
deadlycoconuts authored Jul 28, 2023
1 parent 0302624 commit ec567ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
9 changes: 3 additions & 6 deletions ui/src/jobs/components/modal/DeleteJobModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTuringApi } from "../../../hooks/useTuringApi";
import { ConfirmationModal } from "../../../components/confirmation_modal/ConfirmationModal";
import { isEmpty } from "../../../utils/object";
import { EuiFieldText } from "@elastic/eui";
import { isActiveJobStatus } from "../../../services/job/JobStatus";

export const DeleteJobModal = ({
onSuccess,
Expand Down Expand Up @@ -38,13 +39,9 @@ export const DeleteJobModal = ({
}
}, [isLoaded, error, job, onSuccess, closeModal]);

const isActiveJobStatus = function(jobStatus) {
return ["failed", "failed_submission", "failed_building", "completed"].includes(jobStatus);
}

return (
<ConfirmationModal
title={isActiveJobStatus(job.status) ? 'Delete Ensembling Jobs' : 'Terminate Ensembling Jobs'}
title={isActiveJobStatus(job.status) ? "Terminate Ensembling Jobs" : "Delete Ensembling Jobs" }
onCancel={() => setDeleteConfirmation("")}
onConfirm={(arg) => {submitForm(arg); setDeleteConfirmation("")}}
isLoading={isLoading}
Expand All @@ -63,7 +60,7 @@ export const DeleteJobModal = ({
isInvalid={deleteConfirmation !== job.name} />
</div>
}
confirmButtonText={isActiveJobStatus(job.status) ? 'Delete' : 'Terminate'}
confirmButtonText={isActiveJobStatus(job.status) ? "Terminate" : "Delete"}
confirmButtonColor="danger">
{(onSubmit) =>
(deleteJobRef.current = openModal(onSubmit)) &&
Expand Down
24 changes: 10 additions & 14 deletions ui/src/jobs/list/ListEnsemblingJobsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useNavigate } from "react-router-dom";
import { useConfig } from "../../config";
import moment from "moment";
import { DeploymentStatusHealth } from "../../components/status_health/DeploymentStatusHealth";
import { JobStatus } from "../../services/job/JobStatus";
import { isActiveJobStatus, JobStatus } from "../../services/job/JobStatus";
import EnsemblersContext from "../../providers/ensemblers/context";
import { DateFromNow } from "@caraml-dev/ui-lib";
import { DeleteJobModal } from "../components/modal/DeleteJobModal";
Expand Down Expand Up @@ -68,10 +68,6 @@ export const ListEnsemblingJobsTable = ({
const onDeleteJob = (job) => {
deleteJobRef.current(job)
}

const isActiveJobStatus = function(jobStatus) {
return ["failed", "failed_submission", "failed_building", "completed"].includes(jobStatus);
}

const columns = [
{
Expand Down Expand Up @@ -159,15 +155,15 @@ export const ListEnsemblingJobsTable = ({
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false} >
<EuiButtonEmpty
onClick={() => onDeleteJob(item)}
color={"danger"}
iconType={isActiveJobStatus(item.status) ? "trash" : "minusInCircle" }
iconSide="left"
size="xs"
isDisabled={item.status === "terminating"}>
<EuiText size="xs"> {isActiveJobStatus(item.status) ? "Delete" : "Terminate" } </EuiText>
</EuiButtonEmpty>
<EuiButtonEmpty
onClick={() => onDeleteJob(item)}
color={"danger"}
iconType={isActiveJobStatus(item.status) ? "minusInCircle" : "trash" }
iconSide="left"
size="xs"
isDisabled={item.status === "terminating"}>
<EuiText size="xs"> {isActiveJobStatus(item.status) ? "Terminate" : "Delete" } </EuiText>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
4 changes: 4 additions & 0 deletions ui/src/services/job/JobStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ export const JobStatus = Enum({
iconType: "cross",
}),
});

export const isActiveJobStatus = function(jobStatus) {
return ["pending", "building", "running", "terminating"].includes(jobStatus);
};

0 comments on commit ec567ae

Please sign in to comment.