Merge pull request #9975 from mabashian/9852-delete-inv-src

Fixes bug where users could not delete a single inventory source

SUMMARY
link #9852
Also fixes a bug that I came across with deletion warnings.  The deletion warning was showing a count for workflow nodes that referenced any inventory source with the same parent inventory.  For example:
Create an inventory
Create two inventory sources invsrc1 and invsrc2
Create a workflow with a node that syncs invsrc1
Attempt to delete invsrc2
The warning will indicate that there's 1 workflow node that uses the inventory source but that's actually not true.  There should be no deletion warning in this case.
This PR addresses ^^
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

UI

Reviewed-by: Jake McDermott <yo@jakemcdermott.me>
Reviewed-by: Tiago Góes <tiago.goes2009@gmail.com>
This commit is contained in:
softwarefactory-project-zuul[bot]
2021-04-22 15:29:08 +00:00
committed by GitHub
4 changed files with 13 additions and 34 deletions

View File

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

View File

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

View File

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

View File

@@ -113,37 +113,20 @@ export const relatedResourceDeleteRequests = {
}, },
], ],
inventorySource: (inventoryId, inventorySource) => [ inventorySource: inventorySourceId => [
{ {
request: async () => { request: async () =>
try { WorkflowJobTemplateNodesAPI.read({
const { data } = await InventoriesAPI.updateSources(inventoryId); unified_job_template: inventorySourceId,
}),
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);
}
},
label: i18n._(t`Workflow Job Template Nodes`), label: i18n._(t`Workflow Job Template Nodes`),
}, },
{ {
request: async () => InventorySourcesAPI.readGroups(inventorySource.id), request: async () => InventorySourcesAPI.readGroups(inventorySourceId),
label: i18n._(t`Groups`), label: i18n._(t`Groups`),
}, },
{ {
request: async () => InventorySourcesAPI.readHosts(inventorySource.id), request: async () => InventorySourcesAPI.readHosts(inventorySourceId),
label: i18n._(t`Hosts`), label: i18n._(t`Hosts`),
}, },
], ],