From 8ef6a08adafefc058a489a95ee0af9fea4aa6ba9 Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Thu, 19 Oct 2023 16:46:02 -0400 Subject: [PATCH] Fixes #36846 - Override REX job names for package install by search --- .../Tabs/PackagesTab/PackageInstallModal.js | 2 +- .../Tabs/PackagesTab/PackagesTab.js | 18 +++++--- .../Tabs/RemoteExecutionActions.js | 44 ++++++++++++------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackageInstallModal.js b/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackageInstallModal.js index 6f137b4e1f3..a73f2e2786d 100644 --- a/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackageInstallModal.js +++ b/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackageInstallModal.js @@ -124,7 +124,7 @@ const PackageInstallModal = ({ const selectedPackageNames = () => selectedResults.map(({ name }) => name); const installViaRex = () => { - triggerPackageInstall(fetchBulkParams()); + triggerPackageInstall(fetchBulkParams(), selectedPackageNames().join(', ')); selectNone(); closeModal(); }; diff --git a/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js b/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js index 1baedc0d0f1..5d88f64c9d5 100644 --- a/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js +++ b/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js @@ -231,9 +231,10 @@ export const PackagesTab = () => { isPolling: isRemoveInProgress, } = useRexJobPolling(packageRemoveAction); - const packageBulkRemoveAction = bulkParams => removePackages({ + const packageBulkRemoveAction = (bulkParams, packageNames) => removePackages({ hostname, search: bulkParams, + descriptionFormat: `Remove package(s) ${packageNames}`, }); const { @@ -253,10 +254,11 @@ export const PackagesTab = () => { isPolling: isUpgradeInProgress, } = useRexJobPolling(packageUpgradeAction, getHostDetails({ hostname })); - const packageBulkUpgradeAction = bulkParams => updatePackages({ + const packageBulkUpgradeAction = (bulkParams, descriptionFormat) => updatePackages({ hostname, search: bulkParams, versions: JSON.stringify(selectedNVRAVersions || []), + descriptionFormat, }); const { @@ -266,7 +268,7 @@ export const PackagesTab = () => { } = useRexJobPolling(packageBulkUpgradeAction, getHostDetails({ hostname })); const packageInstallAction - = bulkParams => installPackageBySearch({ hostname, search: bulkParams }); + = (bulkParams, packageNames) => installPackageBySearch({ hostname, search: bulkParams, descriptionFormat: `Install package(s) ${packageNames}` }); const { triggerJobStart: triggerPackageInstall, @@ -306,9 +308,10 @@ export const PackagesTab = () => { const removePackagesViaRemoteExecution = () => { const selected = fetchBulkParams(); + const packageNames = selectedResults.map(({ name }) => name); setIsBulkActionOpen(false); selectNone(); - triggerBulkPackageRemove(selected); + triggerBulkPackageRemove(selected, packageNames.join(', ')); }; const removeBulk = () => removePackagesViaRemoteExecution(); @@ -321,9 +324,13 @@ export const PackagesTab = () => { const upgradeBulkViaRemoteExecution = () => { const selected = fetchBulkParams(); + const packageNames = selectedResults.map(({ name }) => name); + const allRowsSelected = areAllRowsSelected(); + let descriptionFormatText = allRowsSelected ? 'Upgrade all packages' : `Upgrade package(s) ${packageNames.join(', ')}`; + if (selectAllMode && !allRowsSelected) descriptionFormatText = 'Upgrade lots of packages'; // we don't know the package names in the exclusion set setIsBulkActionOpen(false); selectNone(); - triggerBulkPackageUpgrade(selected); + triggerBulkPackageUpgrade(selected, descriptionFormatText); }; const upgradeBulk = () => upgradeBulkViaRemoteExecution(); @@ -462,7 +469,6 @@ export const PackagesTab = () => { ); const resetFilters = () => setPackageStatusSelected(PACKAGE_STATUS); - return (
diff --git a/webpack/components/extensions/HostDetails/Tabs/RemoteExecutionActions.js b/webpack/components/extensions/HostDetails/Tabs/RemoteExecutionActions.js index 36122a20e58..6ee0681d6b7 100644 --- a/webpack/components/extensions/HostDetails/Tabs/RemoteExecutionActions.js +++ b/webpack/components/extensions/HostDetails/Tabs/RemoteExecutionActions.js @@ -9,13 +9,16 @@ import { PACKAGE_SEARCH_QUERY } from './PackagesTab/YumInstallablePackagesConsta import { PACKAGES_SEARCH_QUERY, SELECTED_UPDATE_VERSIONS } from './PackagesTab/HostPackagesConstants'; // PARAM BUILDING -const baseParams = ({ feature, hostname, inputs = {} }) => ({ - job_invocation: { - feature, - inputs, - search_query: `name ^ (${hostname})`, - }, -}); +const baseParams = (params) => { + const { hostname, inputs = {} } = params; + return ({ + job_invocation: { + search_query: `name ^ (${hostname})`, + inputs, + ...params, + }, + }); +}; const runCommandParams = ({ hostname, command }) => baseParams({ @@ -33,11 +36,12 @@ const katelloPackageInstallParams = ({ hostname, packageName }) => }); // used when we know package Id(s) -const katelloPackageInstallBySearchParams = ({ hostname, search }) => +const katelloPackageInstallBySearchParams = ({ hostname, search, descriptionFormat }) => baseParams({ hostname, inputs: { [PACKAGE_SEARCH_QUERY]: search }, feature: REX_FEATURES.KATELLO_PACKAGE_INSTALL_BY_SEARCH, + description_format: descriptionFormat, }); const katelloPackageRemoveParams = ({ hostname, packageName }) => @@ -47,11 +51,12 @@ const katelloPackageRemoveParams = ({ hostname, packageName }) => feature: REX_FEATURES.KATELLO_PACKAGE_REMOVE, }); -const katelloPackagesRemoveParams = ({ hostname, search }) => +const katelloPackagesRemoveParams = ({ hostname, search, descriptionFormat }) => baseParams({ hostname, inputs: { [PACKAGES_SEARCH_QUERY]: search }, feature: REX_FEATURES.KATELLO_PACKAGES_REMOVE_BY_SEARCH, + description_format: descriptionFormat, }); const katelloPackageUpdateParams = ({ hostname, packageName }) => @@ -61,11 +66,14 @@ const katelloPackageUpdateParams = ({ hostname, packageName }) => feature: REX_FEATURES.KATELLO_PACKAGE_UPDATE, }); -const katelloPackagesUpdateParams = ({ hostname, search, versions }) => ({ +const katelloPackagesUpdateParams = ({ + hostname, search, versions, descriptionFormat, +}) => ({ job_invocation: { feature: REX_FEATURES.KATELLO_PACKAGES_UPDATE_BY_SEARCH, inputs: { [PACKAGES_SEARCH_QUERY]: search, [SELECTED_UPDATE_VERSIONS]: versions }, search_query: `name ^ (${hostname})`, + description_format: descriptionFormat, }, }); @@ -134,11 +142,11 @@ export const installPackage = ({ hostname, packageName, handleSuccess }) => post errorToast, }); -export const installPackageBySearch = ({ hostname, search }) => post({ +export const installPackageBySearch = ({ hostname, search, descriptionFormat }) => post({ type: API_OPERATIONS.POST, key: REX_JOB_INVOCATIONS_KEY, url: foremanApi.getApiUrl('/job_invocations'), - params: katelloPackageInstallBySearchParams({ hostname, search }), + params: katelloPackageInstallBySearchParams({ hostname, search, descriptionFormat }), handleSuccess: showRexToast, errorToast, }); @@ -152,11 +160,11 @@ export const removePackage = ({ hostname, packageName }) => post({ errorToast, }); -export const removePackages = ({ hostname, search }) => post({ +export const removePackages = ({ hostname, search, descriptionFormat }) => post({ type: API_OPERATIONS.POST, key: REX_JOB_INVOCATIONS_KEY, url: foremanApi.getApiUrl('/job_invocations'), - params: katelloPackagesRemoveParams({ hostname, search }), + params: katelloPackagesRemoveParams({ hostname, search, descriptionFormat }), handleSuccess: showRexToast, errorToast, }); @@ -170,11 +178,15 @@ export const updatePackage = ({ hostname, packageName }) => post({ errorToast, }); -export const updatePackages = ({ hostname, search, versions }) => post({ +export const updatePackages = ({ + hostname, search, versions, descriptionFormat, +}) => post({ type: API_OPERATIONS.POST, key: REX_JOB_INVOCATIONS_KEY, url: foremanApi.getApiUrl('/job_invocations'), - params: katelloPackagesUpdateParams({ hostname, search, versions }), + params: katelloPackagesUpdateParams({ + hostname, search, versions, descriptionFormat, + }), handleSuccess: showRexToast, errorToast, });