mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
Fix bug where delete/cancel buttons in kebab would not actually make delete/cancel requests
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { Fragment, useState } from 'react';
|
import React, { Fragment, useEffect, useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
@@ -43,6 +43,7 @@ function DataListToolbar({
|
|||||||
}) {
|
}) {
|
||||||
const showExpandCollapse = onCompact && onExpand;
|
const showExpandCollapse = onCompact && onExpand;
|
||||||
const [kebabIsOpen, setKebabIsOpen] = useState(false);
|
const [kebabIsOpen, setKebabIsOpen] = useState(false);
|
||||||
|
const [kebabModalIsOpen, setKebabkebabModalIsOpen] = useState(false);
|
||||||
const [advancedSearchShown, setAdvancedSearchShown] = useState(false);
|
const [advancedSearchShown, setAdvancedSearchShown] = useState(false);
|
||||||
|
|
||||||
const onShowAdvancedSearch = shown => {
|
const onShowAdvancedSearch = shown => {
|
||||||
@@ -50,6 +51,12 @@ function DataListToolbar({
|
|||||||
setKebabIsOpen(false);
|
setKebabIsOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!kebabModalIsOpen) {
|
||||||
|
setKebabIsOpen(false);
|
||||||
|
}
|
||||||
|
}, [kebabModalIsOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Toolbar
|
<Toolbar
|
||||||
id={`${qsConfig.namespace}-list-toolbar`}
|
id={`${qsConfig.namespace}-list-toolbar`}
|
||||||
@@ -104,18 +111,27 @@ function DataListToolbar({
|
|||||||
)}
|
)}
|
||||||
{advancedSearchShown && (
|
{advancedSearchShown && (
|
||||||
<ToolbarItem>
|
<ToolbarItem>
|
||||||
<Dropdown
|
<KebabifiedProvider
|
||||||
toggle={<KebabToggle onToggle={setKebabIsOpen} />}
|
value={{
|
||||||
isOpen={kebabIsOpen}
|
isKebabified: true,
|
||||||
isPlain
|
onKebabModalChange: isOpen => setKebabkebabModalIsOpen(isOpen),
|
||||||
dropdownItems={additionalControls.map(control => {
|
}}
|
||||||
return (
|
>
|
||||||
<KebabifiedProvider value={{ isKebabified: true }}>
|
<Dropdown
|
||||||
{control}
|
toggle={
|
||||||
</KebabifiedProvider>
|
<KebabToggle
|
||||||
);
|
onToggle={isOpen => {
|
||||||
})}
|
if (!kebabModalIsOpen) {
|
||||||
/>
|
setKebabIsOpen(isOpen);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
isOpen={kebabIsOpen}
|
||||||
|
isPlain
|
||||||
|
dropdownItems={additionalControls}
|
||||||
|
/>
|
||||||
|
</KebabifiedProvider>
|
||||||
</ToolbarItem>
|
</ToolbarItem>
|
||||||
)}
|
)}
|
||||||
{!advancedSearchShown && (
|
{!advancedSearchShown && (
|
||||||
|
|||||||
@@ -276,6 +276,7 @@ function JobList({ i18n, defaultParams, showTypeColumn = false }) {
|
|||||||
pluralizedItemName="Jobs"
|
pluralizedItemName="Jobs"
|
||||||
/>,
|
/>,
|
||||||
<JobListCancelButton
|
<JobListCancelButton
|
||||||
|
key="cancel"
|
||||||
onCancel={handleJobCancel}
|
onCancel={handleJobCancel}
|
||||||
jobsToCancel={selected}
|
jobsToCancel={selected}
|
||||||
/>,
|
/>,
|
||||||
|
|||||||
@@ -62,14 +62,17 @@ function JobListCancelButton({ i18n, jobsToCancel, onCancel }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Kebabified>
|
<Kebabified>
|
||||||
{({ isKebabified }) => (
|
{({ isKebabified, onKebabModalChange }) => (
|
||||||
<>
|
<>
|
||||||
{isKebabified ? (
|
{isKebabified ? (
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
key="cancel-job"
|
key="cancel-job"
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
component="Button"
|
component="button"
|
||||||
onClick={() => setIsModalOpen(true)}
|
onClick={() => {
|
||||||
|
onKebabModalChange(true);
|
||||||
|
setIsModalOpen(true);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{cancelJobText}
|
{cancelJobText}
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
@@ -92,14 +95,24 @@ function JobListCancelButton({ i18n, jobsToCancel, onCancel }) {
|
|||||||
variant="danger"
|
variant="danger"
|
||||||
title={cancelJobText}
|
title={cancelJobText}
|
||||||
isOpen={isModalOpen}
|
isOpen={isModalOpen}
|
||||||
onClose={() => setIsModalOpen(false)}
|
onClose={() => {
|
||||||
|
if (isKebabified) {
|
||||||
|
onKebabModalChange(false);
|
||||||
|
}
|
||||||
|
setIsModalOpen(false);
|
||||||
|
}}
|
||||||
actions={[
|
actions={[
|
||||||
<Button
|
<Button
|
||||||
id="cancel-job-confirm-button"
|
id="cancel-job-confirm-button"
|
||||||
key="delete"
|
key="delete"
|
||||||
variant="danger"
|
variant="danger"
|
||||||
aria-label={cancelJobText}
|
aria-label={cancelJobText}
|
||||||
onClick={handleCancel}
|
onClick={() => {
|
||||||
|
if (isKebabified) {
|
||||||
|
onKebabModalChange(false);
|
||||||
|
}
|
||||||
|
handleCancel();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{cancelJobText}
|
{cancelJobText}
|
||||||
</Button>,
|
</Button>,
|
||||||
@@ -108,7 +121,12 @@ function JobListCancelButton({ i18n, jobsToCancel, onCancel }) {
|
|||||||
key="cancel"
|
key="cancel"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
aria-label={i18n._(t`Return`)}
|
aria-label={i18n._(t`Return`)}
|
||||||
onClick={() => setIsModalOpen(false)}
|
onClick={() => {
|
||||||
|
if (isKebabified) {
|
||||||
|
onKebabModalChange(false);
|
||||||
|
}
|
||||||
|
setIsModalOpen(false);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{i18n._(t`Return`)}
|
{i18n._(t`Return`)}
|
||||||
</Button>,
|
</Button>,
|
||||||
|
|||||||
@@ -140,14 +140,17 @@ class ToolbarDeleteButton extends React.Component {
|
|||||||
// See: https://github.com/patternfly/patternfly-react/issues/1894
|
// See: https://github.com/patternfly/patternfly-react/issues/1894
|
||||||
return (
|
return (
|
||||||
<Kebabified>
|
<Kebabified>
|
||||||
{({ isKebabified }) => (
|
{({ isKebabified, onKebabModalChange }) => (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
{isKebabified ? (
|
{isKebabified ? (
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
key="add"
|
key="add"
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
component="Button"
|
component="button"
|
||||||
onClick={this.handleConfirmDelete}
|
onClick={() => {
|
||||||
|
onKebabModalChange(true);
|
||||||
|
this.handleConfirmDelete();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{i18n._(t`Delete`)}
|
{i18n._(t`Delete`)}
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
@@ -170,13 +173,23 @@ class ToolbarDeleteButton extends React.Component {
|
|||||||
variant="danger"
|
variant="danger"
|
||||||
title={modalTitle}
|
title={modalTitle}
|
||||||
isOpen={isModalOpen}
|
isOpen={isModalOpen}
|
||||||
onClose={this.handleCancelDelete}
|
onClose={() => {
|
||||||
|
if (isKebabified) {
|
||||||
|
onKebabModalChange(false);
|
||||||
|
}
|
||||||
|
this.handleCancelDelete();
|
||||||
|
}}
|
||||||
actions={[
|
actions={[
|
||||||
<Button
|
<Button
|
||||||
key="delete"
|
key="delete"
|
||||||
variant="danger"
|
variant="danger"
|
||||||
aria-label={i18n._(t`confirm delete`)}
|
aria-label={i18n._(t`confirm delete`)}
|
||||||
onClick={this.handleDelete}
|
onClick={() => {
|
||||||
|
if (isKebabified) {
|
||||||
|
onKebabModalChange(false);
|
||||||
|
}
|
||||||
|
this.handleDelete();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{i18n._(t`Delete`)}
|
{i18n._(t`Delete`)}
|
||||||
</Button>,
|
</Button>,
|
||||||
@@ -184,7 +197,12 @@ class ToolbarDeleteButton extends React.Component {
|
|||||||
key="cancel"
|
key="cancel"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
aria-label={i18n._(t`cancel delete`)}
|
aria-label={i18n._(t`cancel delete`)}
|
||||||
onClick={this.handleCancelDelete}
|
onClick={() => {
|
||||||
|
if (isKebabified) {
|
||||||
|
onKebabModalChange(false);
|
||||||
|
}
|
||||||
|
this.handleCancelDelete();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{i18n._(t`Cancel`)}
|
{i18n._(t`Cancel`)}
|
||||||
</Button>,
|
</Button>,
|
||||||
|
|||||||
Reference in New Issue
Block a user