mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
Merge pull request #7023 from nixocio/ui_issue_6971
Modify handleDelete for JobTemplateDetails and WorkflowJobTemplateDetail Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -11,6 +11,7 @@ function DeleteButton({
|
|||||||
i18n,
|
i18n,
|
||||||
variant,
|
variant,
|
||||||
children,
|
children,
|
||||||
|
isDisabled,
|
||||||
}) {
|
}) {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ function DeleteButton({
|
|||||||
<Button
|
<Button
|
||||||
variant={variant || 'danger'}
|
variant={variant || 'danger'}
|
||||||
aria-label={i18n._(t`Delete`)}
|
aria-label={i18n._(t`Delete`)}
|
||||||
|
isDisabled={isDisabled}
|
||||||
onClick={() => setIsOpen(true)}
|
onClick={() => setIsOpen(true)}
|
||||||
>
|
>
|
||||||
{children || i18n._(t`Delete`)}
|
{children || i18n._(t`Delete`)}
|
||||||
@@ -33,6 +35,7 @@ function DeleteButton({
|
|||||||
key="delete"
|
key="delete"
|
||||||
variant="danger"
|
variant="danger"
|
||||||
aria-label={i18n._(t`Delete`)}
|
aria-label={i18n._(t`Delete`)}
|
||||||
|
isDisabled={isDisabled}
|
||||||
onClick={onConfirm}
|
onClick={onConfirm}
|
||||||
>
|
>
|
||||||
{i18n._(t`Delete`)}
|
{i18n._(t`Delete`)}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { Fragment, useState, useEffect } from 'react';
|
import React, { Fragment, useState, useEffect, useCallback } from 'react';
|
||||||
import { Link, useHistory, useParams } from 'react-router-dom';
|
import { Link, useHistory, useParams } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import {
|
import {
|
||||||
@@ -29,6 +29,7 @@ import ErrorDetail from '../../../components/ErrorDetail';
|
|||||||
import LaunchButton from '../../../components/LaunchButton';
|
import LaunchButton from '../../../components/LaunchButton';
|
||||||
import { VariablesDetail } from '../../../components/CodeMirrorInput';
|
import { VariablesDetail } from '../../../components/CodeMirrorInput';
|
||||||
import { JobTemplatesAPI } from '../../../api';
|
import { JobTemplatesAPI } from '../../../api';
|
||||||
|
import useRequest, { useDismissableError } from '../../../util/useRequest';
|
||||||
|
|
||||||
function JobTemplateDetail({ i18n, template }) {
|
function JobTemplateDetail({ i18n, template }) {
|
||||||
const {
|
const {
|
||||||
@@ -59,7 +60,6 @@ function JobTemplateDetail({ i18n, template }) {
|
|||||||
webhook_key,
|
webhook_key,
|
||||||
} = template;
|
} = template;
|
||||||
const [contentError, setContentError] = useState(null);
|
const [contentError, setContentError] = useState(null);
|
||||||
const [deletionError, setDeletionError] = useState(null);
|
|
||||||
const [hasContentLoading, setHasContentLoading] = useState(false);
|
const [hasContentLoading, setHasContentLoading] = useState(false);
|
||||||
const [instanceGroups, setInstanceGroups] = useState([]);
|
const [instanceGroups, setInstanceGroups] = useState([]);
|
||||||
const { id: templateId } = useParams();
|
const { id: templateId } = useParams();
|
||||||
@@ -82,16 +82,18 @@ function JobTemplateDetail({ i18n, template }) {
|
|||||||
})();
|
})();
|
||||||
}, [templateId]);
|
}, [templateId]);
|
||||||
|
|
||||||
const handleDelete = async () => {
|
const {
|
||||||
setHasContentLoading(true);
|
request: deleteJobTemplate,
|
||||||
try {
|
isLoading,
|
||||||
|
error: deleteError,
|
||||||
|
} = useRequest(
|
||||||
|
useCallback(async () => {
|
||||||
await JobTemplatesAPI.destroy(templateId);
|
await JobTemplatesAPI.destroy(templateId);
|
||||||
history.push(`/templates`);
|
history.push(`/templates`);
|
||||||
} catch (error) {
|
}, [templateId, history])
|
||||||
setDeletionError(error);
|
);
|
||||||
}
|
|
||||||
setHasContentLoading(false);
|
const { error, dismissError } = useDismissableError(deleteError);
|
||||||
};
|
|
||||||
|
|
||||||
const canLaunch =
|
const canLaunch =
|
||||||
summary_fields.user_capabilities && summary_fields.user_capabilities.start;
|
summary_fields.user_capabilities && summary_fields.user_capabilities.start;
|
||||||
@@ -386,22 +388,23 @@ function JobTemplateDetail({ i18n, template }) {
|
|||||||
<DeleteButton
|
<DeleteButton
|
||||||
name={name}
|
name={name}
|
||||||
modalTitle={i18n._(t`Delete Job Template`)}
|
modalTitle={i18n._(t`Delete Job Template`)}
|
||||||
onConfirm={handleDelete}
|
onConfirm={deleteJobTemplate}
|
||||||
|
isDisabled={isLoading}
|
||||||
>
|
>
|
||||||
{i18n._(t`Delete`)}
|
{i18n._(t`Delete`)}
|
||||||
</DeleteButton>
|
</DeleteButton>
|
||||||
)}
|
)}
|
||||||
</CardActionsRow>
|
</CardActionsRow>
|
||||||
{/* Update delete modal to show dependencies https://github.com/ansible/awx/issues/5546 */}
|
{/* Update delete modal to show dependencies https://github.com/ansible/awx/issues/5546 */}
|
||||||
{deletionError && (
|
{error && (
|
||||||
<AlertModal
|
<AlertModal
|
||||||
isOpen={deletionError}
|
isOpen={error}
|
||||||
variant="error"
|
variant="error"
|
||||||
title={i18n._(t`Error!`)}
|
title={i18n._(t`Error!`)}
|
||||||
onClose={() => setDeletionError(null)}
|
onClose={dismissError}
|
||||||
>
|
>
|
||||||
{i18n._(t`Failed to delete job template.`)}
|
{i18n._(t`Failed to delete job template.`)}
|
||||||
<ErrorDetail error={deletionError} />
|
<ErrorDetail error={error} />
|
||||||
</AlertModal>
|
</AlertModal>
|
||||||
)}
|
)}
|
||||||
</CardBody>
|
</CardBody>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useCallback } from 'react';
|
||||||
import { Link, useHistory } from 'react-router-dom';
|
import { Link, useHistory } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
@@ -17,7 +17,6 @@ import AlertModal from '../../../components/AlertModal';
|
|||||||
import { CardBody, CardActionsRow } from '../../../components/Card';
|
import { CardBody, CardActionsRow } from '../../../components/Card';
|
||||||
import ChipGroup from '../../../components/ChipGroup';
|
import ChipGroup from '../../../components/ChipGroup';
|
||||||
import { VariablesDetail } from '../../../components/CodeMirrorInput';
|
import { VariablesDetail } from '../../../components/CodeMirrorInput';
|
||||||
import ContentLoading from '../../../components/ContentLoading';
|
|
||||||
import DeleteButton from '../../../components/DeleteButton';
|
import DeleteButton from '../../../components/DeleteButton';
|
||||||
import {
|
import {
|
||||||
DetailList,
|
DetailList,
|
||||||
@@ -28,6 +27,7 @@ import ErrorDetail from '../../../components/ErrorDetail';
|
|||||||
import LaunchButton from '../../../components/LaunchButton';
|
import LaunchButton from '../../../components/LaunchButton';
|
||||||
import Sparkline from '../../../components/Sparkline';
|
import Sparkline from '../../../components/Sparkline';
|
||||||
import { toTitleCase } from '../../../util/strings';
|
import { toTitleCase } from '../../../util/strings';
|
||||||
|
import useRequest, { useDismissableError } from '../../../util/useRequest';
|
||||||
|
|
||||||
function WorkflowJobTemplateDetail({ template, i18n }) {
|
function WorkflowJobTemplateDetail({ template, i18n }) {
|
||||||
const {
|
const {
|
||||||
@@ -48,9 +48,6 @@ function WorkflowJobTemplateDetail({ template, i18n }) {
|
|||||||
const urlOrigin = window.location.origin;
|
const urlOrigin = window.location.origin;
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const [deletionError, setDeletionError] = useState(null);
|
|
||||||
const [hasContentLoading, setHasContentLoading] = useState(false);
|
|
||||||
|
|
||||||
const renderOptionsField =
|
const renderOptionsField =
|
||||||
template.allow_simultaneous || template.webhook_service;
|
template.allow_simultaneous || template.webhook_service;
|
||||||
|
|
||||||
@@ -69,20 +66,18 @@ function WorkflowJobTemplateDetail({ template, i18n }) {
|
|||||||
</TextList>
|
</TextList>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (hasContentLoading) {
|
const {
|
||||||
return <ContentLoading />;
|
request: deleteWorkflowJobTemplate,
|
||||||
}
|
isLoading,
|
||||||
|
error: deleteError,
|
||||||
const handleDelete = async () => {
|
} = useRequest(
|
||||||
setHasContentLoading(true);
|
useCallback(async () => {
|
||||||
try {
|
|
||||||
await WorkflowJobTemplatesAPI.destroy(id);
|
await WorkflowJobTemplatesAPI.destroy(id);
|
||||||
history.push(`/templates`);
|
history.push(`/templates`);
|
||||||
} catch (error) {
|
}, [id, history])
|
||||||
setDeletionError(error);
|
);
|
||||||
}
|
|
||||||
setHasContentLoading(false);
|
const { error, dismissError } = useDismissableError(deleteError);
|
||||||
};
|
|
||||||
|
|
||||||
const inventoryValue = (kind, inventoryId) => {
|
const inventoryValue = (kind, inventoryId) => {
|
||||||
const inventorykind = kind === 'smart' ? 'smart_inventory' : 'inventory';
|
const inventorykind = kind === 'smart' ? 'smart_inventory' : 'inventory';
|
||||||
@@ -226,21 +221,22 @@ function WorkflowJobTemplateDetail({ template, i18n }) {
|
|||||||
<DeleteButton
|
<DeleteButton
|
||||||
name={name}
|
name={name}
|
||||||
modalTitle={i18n._(t`Delete Workflow Job Template`)}
|
modalTitle={i18n._(t`Delete Workflow Job Template`)}
|
||||||
onConfirm={handleDelete}
|
onConfirm={deleteWorkflowJobTemplate}
|
||||||
|
isDisabled={isLoading}
|
||||||
>
|
>
|
||||||
{i18n._(t`Delete`)}
|
{i18n._(t`Delete`)}
|
||||||
</DeleteButton>
|
</DeleteButton>
|
||||||
)}
|
)}
|
||||||
</CardActionsRow>
|
</CardActionsRow>
|
||||||
{deletionError && (
|
{error && (
|
||||||
<AlertModal
|
<AlertModal
|
||||||
isOpen={deletionError}
|
isOpen={error}
|
||||||
variant="error"
|
variant="error"
|
||||||
title={i18n._(t`Error!`)}
|
title={i18n._(t`Error!`)}
|
||||||
onClose={() => setDeletionError(null)}
|
onClose={dismissError}
|
||||||
>
|
>
|
||||||
{i18n._(t`Failed to delete workflow job template.`)}
|
{i18n._(t`Failed to delete workflow job template.`)}
|
||||||
<ErrorDetail error={deletionError} />
|
<ErrorDetail error={error} />
|
||||||
</AlertModal>
|
</AlertModal>
|
||||||
)}
|
)}
|
||||||
</CardBody>
|
</CardBody>
|
||||||
|
|||||||
Reference in New Issue
Block a user