From bfedbe561c37174dc7d3f4c902bce665e0f10b8b Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Thu, 19 Dec 2019 09:55:04 -0800 Subject: [PATCH] add delete button to InventoryDetail --- .../src/components/Card/CardActionsRow.jsx | 4 +- .../components/DeleteButton/DeleteButton.jsx | 50 +++++++++++++++++++ .../src/components/DeleteButton/index.js | 1 + .../InventoryDetail/InventoryDetail.jsx | 31 +++++++++--- 4 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 awx/ui_next/src/components/DeleteButton/DeleteButton.jsx create mode 100644 awx/ui_next/src/components/DeleteButton/index.js diff --git a/awx/ui_next/src/components/Card/CardActionsRow.jsx b/awx/ui_next/src/components/Card/CardActionsRow.jsx index 045483a06a..8312207fa9 100644 --- a/awx/ui_next/src/components/Card/CardActionsRow.jsx +++ b/awx/ui_next/src/components/Card/CardActionsRow.jsx @@ -7,8 +7,8 @@ const CardActionsWrapper = styled.div` justify-content: flex-end; margin-top: 20px; - & > :not(:first-child) { - margin-left: 20px; + & > .pf-c-card__actions > :not(:first-child) { + margin-left: 0.5rem; } `; diff --git a/awx/ui_next/src/components/DeleteButton/DeleteButton.jsx b/awx/ui_next/src/components/DeleteButton/DeleteButton.jsx new file mode 100644 index 0000000000..69a84e7f79 --- /dev/null +++ b/awx/ui_next/src/components/DeleteButton/DeleteButton.jsx @@ -0,0 +1,50 @@ +import React, { useState } from 'react'; +import { withI18n } from '@lingui/react'; +import { t } from '@lingui/macro'; +import { Button } from '@patternfly/react-core'; +import AlertModal from '@components/AlertModal'; +import { CardActionsRow } from '@components/Card'; + +function DeleteButton({ onConfirm, modalTitle, name, i18n }) { + const [isOpen, setIsOpen] = useState(false); + + return ( + <> + + setIsOpen(false)} + > + {i18n._(t`Are you sure you want to delete:`)} +
+ {name} + + + + +
+ + ); +} + +export default withI18n()(DeleteButton); diff --git a/awx/ui_next/src/components/DeleteButton/index.js b/awx/ui_next/src/components/DeleteButton/index.js new file mode 100644 index 0000000000..991ad79b29 --- /dev/null +++ b/awx/ui_next/src/components/DeleteButton/index.js @@ -0,0 +1 @@ +export { default } from './DeleteButton'; diff --git a/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx b/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx index 182978fd21..81a765982a 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { Link } from 'react-router-dom'; +import { Link, useHistory } from 'react-router-dom'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; import { Button } from '@patternfly/react-core'; @@ -7,6 +7,7 @@ import { CardBody, CardActionsRow } from '@components/Card'; import { DetailList, Detail, UserDateDetail } from '@components/DetailList'; import { ChipGroup, Chip } from '@components/Chip'; import { VariablesDetail } from '@components/CodeMirrorInput'; +import DeleteButton from '@components/DeleteButton'; import ContentError from '@components/ContentError'; import ContentLoading from '@components/ContentLoading'; import { InventoriesAPI } from '@api'; @@ -16,6 +17,7 @@ function InventoryDetail({ inventory, i18n }) { const [instanceGroups, setInstanceGroups] = useState([]); const [hasContentLoading, setHasContentLoading] = useState(true); const [contentError, setContentError] = useState(null); + const history = useHistory(); useEffect(() => { (async () => { @@ -31,7 +33,15 @@ function InventoryDetail({ inventory, i18n }) { })(); }, [inventory.id]); - const { organization } = inventory.summary_fields; + const deleteInventory = async () => { + await InventoriesAPI.destroy(inventory.id); + history.push(`/inventories`); + }; + + const { + organization, + user_capabilities: userCapabilities, + } = inventory.summary_fields; if (hasContentLoading) { return ; @@ -85,16 +95,25 @@ function InventoryDetail({ inventory, i18n }) { user={inventory.summary_fields.modified_by} /> - {inventory.summary_fields.user_capabilities.edit && ( - + + {userCapabilities.edit && ( - - )} + )} + {userCapabilities.delete && ( + + {i18n._(t`Delete`)} + + )} + ); }