Skip to content

Commit

Permalink
Fixes #36846 - Override REX job names for package install by search
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Oct 19, 2023
1 parent dc02aab commit 8ef6a08
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const PackageInstallModal = ({
const selectedPackageNames = () => selectedResults.map(({ name }) => name);

const installViaRex = () => {
triggerPackageInstall(fetchBulkParams());
triggerPackageInstall(fetchBulkParams(), selectedPackageNames().join(', '));
selectNone();
closeModal();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -462,7 +469,6 @@ export const PackagesTab = () => {
);

const resetFilters = () => setPackageStatusSelected(PACKAGE_STATUS);

return (
<div>
<div id="packages-tab">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 }) =>
Expand All @@ -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 }) =>
Expand All @@ -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,
},
});

Expand Down Expand Up @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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,
});
Expand Down

0 comments on commit 8ef6a08

Please sign in to comment.