mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 20:51:21 -03:30
project: Add disable sync button feature.
Disable sync button if there is any pending, waiting or running job
This commit is contained in:
parent
03d8987d93
commit
e6735b595c
@ -208,7 +208,10 @@ function ProjectDetail({ project, i18n }) {
|
||||
</Button>
|
||||
)}
|
||||
{summary_fields.user_capabilities?.start && (
|
||||
<ProjectSyncButton projectId={project.id} />
|
||||
<ProjectSyncButton
|
||||
projectId={project.id}
|
||||
lastJobStatus={summary_fields.last_job.status}
|
||||
/>
|
||||
)}
|
||||
{summary_fields.user_capabilities?.delete && (
|
||||
<DeleteButton
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import { useRouteMatch } from 'react-router-dom';
|
||||
import { Button } from '@patternfly/react-core';
|
||||
import { Button, Tooltip } from '@patternfly/react-core';
|
||||
import { SyncIcon } from '@patternfly/react-icons';
|
||||
|
||||
import { number } from 'prop-types';
|
||||
@ -12,7 +12,7 @@ import AlertModal from '../../../components/AlertModal';
|
||||
import ErrorDetail from '../../../components/ErrorDetail';
|
||||
import { ProjectsAPI } from '../../../api';
|
||||
|
||||
function ProjectSyncButton({ i18n, projectId }) {
|
||||
function ProjectSyncButton({ i18n, projectId, lastJobStatus = null }) {
|
||||
const match = useRouteMatch();
|
||||
|
||||
const { request: handleSync, error: syncError } = useRequest(
|
||||
@ -24,16 +24,39 @@ function ProjectSyncButton({ i18n, projectId }) {
|
||||
|
||||
const { error, dismissError } = useDismissableError(syncError);
|
||||
const isDetailsView = match.url.endsWith('/details');
|
||||
const isDisabled = ['pending', 'waiting', 'running'].includes(lastJobStatus);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
ouiaId={`${projectId}-sync-button`}
|
||||
aria-label={i18n._(t`Sync Project`)}
|
||||
variant={isDetailsView ? 'secondary' : 'plain'}
|
||||
onClick={handleSync}
|
||||
>
|
||||
{match.url.endsWith('/details') ? i18n._(t`Sync`) : <SyncIcon />}
|
||||
</Button>
|
||||
{isDisabled ? (
|
||||
<Tooltip
|
||||
content={i18n._(
|
||||
t`This project is currently on sync and cannot be clicked until sync process completed`
|
||||
)}
|
||||
position="top"
|
||||
>
|
||||
<div>
|
||||
<Button
|
||||
ouiaId={`${projectId}-sync-button`}
|
||||
aria-label={i18n._(t`Sync Project`)}
|
||||
variant={isDetailsView ? 'secondary' : 'plain'}
|
||||
isDisabled={isDisabled}
|
||||
>
|
||||
{match.url.endsWith('/details') ? i18n._(t`Sync`) : <SyncIcon />}
|
||||
</Button>
|
||||
</div>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Button
|
||||
ouiaId={`${projectId}-sync-button`}
|
||||
aria-label={i18n._(t`Sync Project`)}
|
||||
variant={isDetailsView ? 'secondary' : 'plain'}
|
||||
isDisabled={isDisabled}
|
||||
onClick={handleSync}
|
||||
>
|
||||
{match.url.endsWith('/details') ? i18n._(t`Sync`) : <SyncIcon />}
|
||||
</Button>
|
||||
)}
|
||||
{error && (
|
||||
<AlertModal
|
||||
isOpen={error}
|
||||
|
||||
@ -34,7 +34,7 @@ export default function useWsProjects(initialProject) {
|
||||
// to `Pending`, then `Waiting`, then `Running`, then result
|
||||
// (which are `successful`, `failed`, `error`, `cancelled`.
|
||||
// For second sync, if the status response is `pending` and we have
|
||||
// running and waiting jobs, we should not update our UI to `Pending`,
|
||||
// running or waiting jobs, we should not update our UI to `Pending`,
|
||||
// otherwise our most recent sync tooltip UI will lose our current running
|
||||
// job and we cannot navigate to the job link through the link provided
|
||||
// by most recent sync tooltip.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user