Fixes bug where users could not delete a single inventory source

This commit is contained in:
mabashian 2021-04-21 14:42:38 -04:00
parent ddcbef8545
commit c48fbec30c
4 changed files with 13 additions and 34 deletions

View File

@ -98,8 +98,7 @@ function InventorySourceDetail({ inventorySource, i18n }) {
};
const deleteDetailsRequests = relatedResourceDeleteRequests.inventorySource(
inventorySource.inventory,
inventorySource
inventorySource.id
);
const VERBOSITY = {

View File

@ -145,8 +145,7 @@ function InventorySourceList({ i18n }) {
const listUrl = `/inventories/${inventoryType}/${id}/sources/`;
const deleteDetailsRequests = relatedResourceDeleteRequests.inventorySource(
id,
selected[0]
selected[0]?.id
);
return (
<>

View File

@ -91,9 +91,8 @@ describe('delete details', () => {
await getRelatedResourceDeleteCounts(
relatedResourceDeleteRequests.inventorySource(1)
);
expect(InventoriesAPI.updateSources).toBeCalledWith(1);
expect(WorkflowJobTemplateNodesAPI.read).toBeCalledWith({
unified_job_template: 2,
unified_job_template: 1,
});
});
@ -105,11 +104,11 @@ describe('delete details', () => {
});
test('should call return error for inventory source list', async () => {
InventoriesAPI.updateSources.mockRejectedValue({
WorkflowJobTemplateNodesAPI.read.mockRejectedValue({
response: {
config: {
method: 'post',
url: '/api/v2/inventories/1/ad_hoc_commands',
method: 'get',
url: '/api/v2/workflow_job_template_nodesP',
},
data: 'An error occurred',
status: 403,
@ -119,7 +118,6 @@ describe('delete details', () => {
relatedResourceDeleteRequests.inventorySource(1)
);
expect(InventoriesAPI.updateSources).toBeCalledWith(1);
expect(error).toBeDefined();
});

View File

@ -113,37 +113,20 @@ export const relatedResourceDeleteRequests = {
},
],
inventorySource: (inventoryId, inventorySource) => [
inventorySource: inventorySourceId => [
{
request: async () => {
try {
const { data } = await InventoriesAPI.updateSources(inventoryId);
const results = await Promise.all(
data.map(async datum =>
WorkflowJobTemplateNodesAPI.read({
unified_job_template: datum.inventory_source,
})
)
);
const total = results.reduce(
({ data: { count: acc } }, { data: { count: cur } }) => acc + cur,
{ data: { count: 0 } }
);
return { data: { count: total } };
} catch (err) {
throw new Error(err);
}
},
request: async () =>
WorkflowJobTemplateNodesAPI.read({
unified_job_template: inventorySourceId,
}),
label: i18n._(t`Workflow Job Template Nodes`),
},
{
request: async () => InventorySourcesAPI.readGroups(inventorySource.id),
request: async () => InventorySourcesAPI.readGroups(inventorySourceId),
label: i18n._(t`Groups`),
},
{
request: async () => InventorySourcesAPI.readHosts(inventorySource.id),
request: async () => InventorySourcesAPI.readHosts(inventorySourceId),
label: i18n._(t`Hosts`),
},
],