Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For R.C. - Fleet UI: Platform of policy mismatch current selected software unrelease bug fix #25490

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading