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:
softwarefactory-project-zuul[bot] 2020-11-13 18:37:07 +00:00 committed by GitHub
commit 0d843899e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 5 deletions

View File

@ -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>
)}
</>

View File

@ -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 () => {