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