Skip to content

Commit

Permalink
Fleet UI: Platform of policy mismatch current selected software unrel…
Browse files Browse the repository at this point in the history
…ease bug fix (#25489)
  • Loading branch information
RachelElysia authored Jan 16, 2025
1 parent c84d535 commit 51fecdd
Showing 1 changed file with 52 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ interface IInstallSoftwareModal {
teamId: number;
}

const generateSoftwareOptionHelpText = (title: IEnhancedSoftwareTitle) => {
const vppOption = title.source === "apps" && !!title.app_store_app;
let platformString = "";
let versionString = "";

if (vppOption) {
platformString = "macOS (App Store) • ";
versionString = title.app_store_app?.version || "";
} else {
if (title.platform && title.extension) {
platformString = `${PLATFORM_DISPLAY_NAMES[title.platform]} (.${
title.extension
}) • `;
}
versionString = title.software_package?.version || "";
}

return `${platformString}${versionString}`;
};

const InstallSoftwareModal = ({
onExit,
onSubmit,
Expand Down Expand Up @@ -174,28 +194,10 @@ const InstallSoftwareModal = ({
(title) => title.platform && policyPlatforms.includes(title.platform)
)
.map((title) => {
const vppOption = title.source === "apps" && !!title.app_store_app;
const platformString = () => {
if (vppOption) {
return "macOS (App Store) • ";
}

return title.extension
? `${
title.platform && PLATFORM_DISPLAY_NAMES[title.platform]
} (.${title.extension}) • `
: "";
};
const versionString = () => {
return vppOption
? title.app_store_app?.version
: title.software_package?.version ?? "";
};

return {
label: title.name,
value: title.id,
helpText: `${platformString()}${versionString()}`,
helpText: generateSoftwareOptionHelpText(title),
};
});
},
Expand All @@ -206,13 +208,41 @@ const InstallSoftwareModal = ({
const memoizedAvailableSoftwareOptions = useMemo(() => {
const cache = new Map();
return (policy: IFormPolicy) => {
const key = policy.platform;
let options = availableSoftwareOptions(policy) || [];
const installOptionsByPlatformMismatchSelectedInstaller =
policy.swIdToInstall &&
!options.some((opt) => opt.value === policy.swIdToInstall);

// More unique cache key if installOptionsByPlatformMismatchSelectedInstaller
const key = `${policy.platform}${
installOptionsByPlatformMismatchSelectedInstaller
? `-${policy.swIdToInstall}`
: ""
}`;
if (!cache.has(key)) {
cache.set(key, availableSoftwareOptions(policy));
// Add the current software if it's not in the options
// due to user-created a platform mismatch
if (installOptionsByPlatformMismatchSelectedInstaller) {
const currentSoftware = titlesAvailableForInstall?.find(
(title) => title.id === policy.swIdToInstall
);
if (currentSoftware) {
options = [
{
label: currentSoftware.name,
value: currentSoftware.id,
helpText: generateSoftwareOptionHelpText(currentSoftware),
},
...options,
];
}
}

cache.set(key, options);
}
return cache.get(key);
};
}, [availableSoftwareOptions]);
}, [availableSoftwareOptions, titlesAvailableForInstall]);

const renderPolicySwInstallOption = (policy: IFormPolicy) => {
const {
Expand Down

0 comments on commit 51fecdd

Please sign in to comment.