mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 19:10:07 -03:30
Merge pull request #8519 from nixocio/ui_issue_8098
Remove groups/hosts when deleting inventory sources Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
commit
0d843899e1
@ -105,8 +105,37 @@ function InventorySourceList({ i18n }) {
|
||||
);
|
||||
const { error: syncError, dismissError } = useDismissableError(syncAllError);
|
||||
|
||||
const deleteRelatedInventoryResources = resourceId => {
|
||||
return [
|
||||
InventorySourcesAPI.destroyHosts(resourceId),
|
||||
InventorySourcesAPI.destroyGroups(resourceId),
|
||||
];
|
||||
};
|
||||
|
||||
const {
|
||||
isLoading: deleteRelatedResourcesLoading,
|
||||
deletionError: deleteRelatedResourcesError,
|
||||
deleteItems: handleDeleteRelatedResources,
|
||||
} = useDeleteItems(
|
||||
useCallback(async () => {
|
||||
return (
|
||||
Promise.all(
|
||||
selected
|
||||
.map(({ id: resourceId }) =>
|
||||
deleteRelatedInventoryResources(resourceId)
|
||||
)
|
||||
.flat()
|
||||
),
|
||||
[]
|
||||
);
|
||||
}, [selected])
|
||||
);
|
||||
|
||||
const handleDelete = async () => {
|
||||
await handleDeleteSources();
|
||||
await handleDeleteRelatedResources();
|
||||
if (!deleteRelatedResourcesError) {
|
||||
await handleDeleteSources();
|
||||
}
|
||||
setSelected([]);
|
||||
};
|
||||
const canAdd =
|
||||
@ -117,7 +146,12 @@ function InventorySourceList({ i18n }) {
|
||||
<>
|
||||
<PaginatedDataList
|
||||
contentError={fetchError}
|
||||
hasContentLoading={isLoading || isDeleteLoading || isSyncAllLoading}
|
||||
hasContentLoading={
|
||||
isLoading ||
|
||||
isDeleteLoading ||
|
||||
isSyncAllLoading ||
|
||||
deleteRelatedResourcesLoading
|
||||
}
|
||||
items={sources}
|
||||
itemCount={sourceCount}
|
||||
pluralizedItemName={i18n._(t`Inventory Sources`)}
|
||||
@ -193,16 +227,16 @@ function InventorySourceList({ i18n }) {
|
||||
</AlertModal>
|
||||
)}
|
||||
|
||||
{deletionError && (
|
||||
{(deletionError || deleteRelatedResourcesError) && (
|
||||
<AlertModal
|
||||
aria-label={i18n._(t`Delete error`)}
|
||||
isOpen={deletionError}
|
||||
isOpen={deletionError || deleteRelatedResourcesError}
|
||||
variant="error"
|
||||
title={i18n._(t`Error!`)}
|
||||
onClose={clearDeletionError}
|
||||
>
|
||||
{i18n._(t`Failed to delete one or more inventory sources.`)}
|
||||
<ErrorDetail error={deletionError} />
|
||||
<ErrorDetail error={deletionError || deleteRelatedResourcesError} />
|
||||
</AlertModal>
|
||||
)}
|
||||
</>
|
||||
|
||||
@ -165,6 +165,8 @@ describe('<InventorySourceList />', () => {
|
||||
wrapper.find('Button[aria-label="confirm delete"]').prop('onClick')()
|
||||
);
|
||||
expect(InventorySourcesAPI.destroy).toHaveBeenCalledWith(1);
|
||||
expect(InventorySourcesAPI.destroyHosts).toHaveBeenCalledWith(1);
|
||||
expect(InventorySourcesAPI.destroyGroups).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
test('should throw error after deletion failure', async () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user