Skip to content

Commit

Permalink
Show a toast when the job is already in the process of launching
Browse files Browse the repository at this point in the history
  • Loading branch information
mabashian committed Sep 6, 2023
1 parent 480aaea commit 56230ba
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions awx/ui/src/components/LaunchButton/LaunchButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
WorkflowJobsAPI,
WorkflowJobTemplatesAPI,
} from 'api';
import useToast, { AlertVariant } from 'hooks/useToast';
import AlertModal from '../AlertModal';
import ErrorDetail from '../ErrorDetail';
import LaunchPrompt from '../LaunchPrompt';
Expand Down Expand Up @@ -45,9 +46,20 @@ function LaunchButton({ resource, children }) {
const [isLaunching, setIsLaunching] = useState(false);
const [resourceCredentials, setResourceCredentials] = useState([]);
const [error, setError] = useState(null);
const { addToast, Toast, toastProps } = useToast();

const showToast = () => {
addToast({
id: resource.id,
title: t`A job has already been launched`,
variant: AlertVariant.info,
hasTimeout: true,
});
};

const handleLaunch = async () => {
if (isLaunching) {
showToast();
return;
}
setIsLaunching(true);
Expand Down Expand Up @@ -108,6 +120,7 @@ function LaunchButton({ resource, children }) {

const launchWithParams = async (params) => {
if (isLaunching) {
showToast();
return;
}
setIsLaunching(true);
Expand Down Expand Up @@ -149,6 +162,7 @@ function LaunchButton({ resource, children }) {
let relaunch;

if (isLaunching) {
showToast();
return;
}
setIsLaunching(true);
Expand Down Expand Up @@ -207,6 +221,7 @@ function LaunchButton({ resource, children }) {
handleRelaunch,
isLaunching,
})}
<Toast {...toastProps} />
{error && (
<AlertModal
isOpen={error}
Expand Down

0 comments on commit 56230ba

Please sign in to comment.