Adds more execution environment resource to delete warnings

This commit is contained in:
Alex Corey 2021-03-16 16:48:54 -04:00
parent 6e401fa02f
commit be148b5fd4
7 changed files with 52 additions and 22 deletions

View File

@ -168,7 +168,10 @@ function ToolbarDeleteButton({
deleteMessages.push(warningMessage);
}
if (deleteMessage) {
if (itemsToDelete[0]?.type !== 'inventory') {
if (
itemsToDelete[0]?.type !== 'inventory' &&
(itemsToDelete.length > 1 || deleteDetails)
) {
deleteMessages.push(deleteMessage);
} else if (deleteDetails || itemsToDelete.length > 1) {
deleteMessages.push(deleteMessage);
@ -206,6 +209,10 @@ function ToolbarDeleteButton({
</AlertModal>
);
}
const shouldShowDeleteWarning =
warningMessage ||
(itemsToDelete.length === 1 && deleteDetails) ||
(itemsToDelete.length > 1 && deleteMessage);
return (
<>
@ -270,7 +277,7 @@ function ToolbarDeleteButton({
<br />
</span>
))}
{(deleteDetails || deleteMessage || warningMessage) && (
{shouldShowDeleteWarning && (
<WarningMessage
variant="warning"
isInline

View File

@ -191,6 +191,6 @@ describe('<ExecutionEnvironmentDetails/>', () => {
});
expect(
wrapper.find('DeleteButton').prop('deleteDetailsRequests')
).toHaveLength(2);
).toHaveLength(4);
});
});

View File

@ -195,6 +195,6 @@ describe('<ExecutionEnvironmentList/>', () => {
});
expect(
wrapper.find('ToolbarDeleteButton').prop('deleteDetailsRequests')
).toHaveLength(2);
).toHaveLength(4);
});
});

View File

@ -182,7 +182,7 @@ function InventorySourceList({ i18n }) {
pluralizedItemName={i18n._(t`Inventory Sources`)}
deleteDetailsRequests={deleteDetailsRequests}
deleteMessage={i18n._(
'{numItemsToDelete, plural, one {This inventory source is currently being used workflow job template nodes. Are you sure you want to delete it?} other {Deleting these inventory sources could impact some workflow job template nodes that rely on them. Are you sure you want to delete anyway?}}',
'{numItemsToDelete, plural, one {This inventory source is currently being used by workflow job template nodes. Are you sure you want to delete it?} other {Deleting these inventory sources could impact workflow job template nodes that rely on them. Are you sure you want to delete anyway?}}',
{ numItemsToDelete: selected.length }
)}
/>,

View File

@ -77,7 +77,7 @@ describe('<OrganizationDetail />', () => {
expect(
component.find('DeleteButton').prop('deleteDetailsRequests')
).toHaveLength(4);
).toHaveLength(7);
});
test('should render the expected instance group', async () => {

View File

@ -102,7 +102,7 @@ describe('<OrganizationsList />', () => {
);
expect(
wrapper.find('ToolbarDeleteButton').prop('deleteDetailsRequests')
).toHaveLength(4);
).toHaveLength(7);
});
test('Items are rendered after loading', async () => {

View File

@ -117,14 +117,26 @@ export const relatedResourceDeleteRequests = {
request: async () => {
try {
const { data } = await InventoriesAPI.updateSources(inventoryId);
return WorkflowJobTemplateNodesAPI.read({
unified_job_template: data[0].inventory_source,
});
let total = 0;
await Promise.all(
data.map(async datum => {
const {
data: { count },
} = await WorkflowJobTemplateNodesAPI.read({
unified_job_template: datum.inventory_source,
});
if (count > 0) {
total += count;
}
})
);
console.log(total, 'total');
return { data: { count: total } };
} catch (err) {
throw new Error(err);
}
},
label: i18n._(t`Workflow Job Template Node`),
label: i18n._(t`Workflow Job Template Nodes`),
},
],
@ -231,26 +243,37 @@ export const relatedResourceDeleteRequests = {
{
request: async () =>
OrganizationsAPI.read({
execution_environment: selected.id,
default_environment: selected.id,
}),
label: [i18n._(t`Organizations`)],
},
{
request: async () => {
try {
const { data } = await WorkflowJobTemplateNodesAPI.read({
const {
data: { results },
} = await InventorySourcesAPI.read({
execution_environment: selected.id,
});
if (
data.summary_fields.unified_job_template.unified_job_type ===
'inventory_update'
) {
await InventorySourcesAPI.read();
}
} catch {}
let total = 0;
await Promise.all(
results.map(async result => {
const {
data: { count },
} = await WorkflowJobTemplateNodesAPI.read({
unified_job_template: result.id,
});
if (count > 0) {
total += count;
}
})
);
return { data: { count: total } };
} catch (err) {
throw new Error(err);
}
},
label: [i18n._(t`Organizations`)],
label: [i18n._(t`Workflow Job Template Nodes`)],
},
],
};