fleet/frontend/pages/ManageControlsPage/SetupExperience/cards/InstallSoftware/InstallSoftware.tsx
jacobshandling 4b484dbfd1
UI: Add linux setup software end-user demo video, fix positioning (#32880)
- Add video asset
- Update component rendering it to have unique copy and video for each
platform
- Fix a [padding
issue](https://fleetdm.slack.com/archives/C084F4MKYSJ/p1757600659471109)
- Adjust vertical position of tab nav to compensate for library-specific
positioning

<img width="1505" height="1153" alt="Screenshot 2025-09-11 at 12 01
20 PM"
src="https://github.com/user-attachments/assets/c26e8ff5-97fd-4430-ba59-1a86a9756a1c"
/>

<img width="1505" height="1153" alt="Screenshot 2025-09-11 at 12 01
26 PM"
src="https://github.com/user-attachments/assets/cbfb72ae-6b00-4f5d-bda2-5ef6b737a0b0"
/>

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-09-11 15:18:12 -07:00

202 lines
6.2 KiB
TypeScript

import React, { useCallback, useState } from "react";
import { useQuery } from "react-query";
import { AxiosError } from "axios";
import { Tab, TabList, TabPanel, Tabs } from "react-tabs";
import mdmAPI, {
IGetSetupExperienceSoftwareResponse,
} from "services/entities/mdm";
import configAPI from "services/entities/config";
import teamsAPI, { ILoadTeamResponse } from "services/entities/teams";
import { ISoftwareTitle } from "interfaces/software";
import { DEFAULT_USE_QUERY_OPTIONS, SUPPORT_LINK } from "utilities/constants";
import { IConfig } from "interfaces/config";
import { API_NO_TEAM_ID, ITeamConfig } from "interfaces/team";
import { SetupExperiencePlatform } from "interfaces/platform";
import SectionHeader from "components/SectionHeader";
import DataError from "components/DataError";
import Spinner from "components/Spinner";
import TabNav from "components/TabNav";
import TabText from "components/TabText";
import CustomLink from "components/CustomLink";
import TurnOnMdmMessage from "components/TurnOnMdmMessage";
import InstallSoftwarePreview from "./components/InstallSoftwarePreview";
import AddInstallSoftware from "./components/AddInstallSoftware";
import SelectSoftwareModal from "./components/SelectSoftwareModal";
import SetupExperienceContentContainer from "../../components/SetupExperienceContentContainer";
import { ISetupExperienceCardProps } from "../../SetupExperienceNavItems";
import getManualAgentInstallSetting from "../../helpers";
const baseClass = "install-software";
// This is so large because we want to get all the software titles that are
// available for install so we can correctly display the selected count.
const PER_PAGE_SIZE = 3000;
const DEFAULT_PLATFORM: SetupExperiencePlatform = "macos";
export const PLATFORM_BY_INDEX: SetupExperiencePlatform[] = [
"macos",
"windows",
"linux",
];
const InstallSoftware = ({
currentTeamId,
router,
}: ISetupExperienceCardProps) => {
const [showSelectSoftwareModal, setShowSelectSoftwareModal] = useState(false);
const [
selectedPlatform,
setSelectedPlatform,
] = useState<SetupExperiencePlatform>(DEFAULT_PLATFORM);
const {
data: softwareTitles,
isLoading,
isError,
refetch: refetchSoftwareTitles,
} = useQuery<
IGetSetupExperienceSoftwareResponse,
AxiosError,
ISoftwareTitle[] | null
>(
["install-software", currentTeamId, selectedPlatform],
() =>
mdmAPI.getSetupExperienceSoftware({
platform: selectedPlatform,
team_id: currentTeamId,
per_page: PER_PAGE_SIZE,
}),
{
enabled: selectedPlatform !== "windows", // remove next iteration
...DEFAULT_USE_QUERY_OPTIONS,
select: (res) => res.software_titles,
}
);
const { data: globalConfig, isLoading: isLoadingGlobalConfig } = useQuery<
IConfig,
Error
>(["config", currentTeamId], () => configAPI.loadAll(), {
...DEFAULT_USE_QUERY_OPTIONS,
});
const { data: teamConfig, isLoading: isLoadingTeamConfig } = useQuery<
ILoadTeamResponse,
Error,
ITeamConfig
>(["team", currentTeamId], () => teamsAPI.load(currentTeamId), {
...DEFAULT_USE_QUERY_OPTIONS,
enabled: currentTeamId !== API_NO_TEAM_ID,
select: (res) => res.team,
});
const onSave = async () => {
setShowSelectSoftwareModal(false);
refetchSoftwareTitles();
};
const handleTabChange = useCallback((index: number) => {
setSelectedPlatform(PLATFORM_BY_INDEX[index]);
}, []);
const hasManualAgentInstall = getManualAgentInstallSetting(
currentTeamId,
globalConfig,
teamConfig
);
const renderTabContent = (platform: SetupExperiencePlatform) => {
if (platform === "windows") {
return (
<div className={`${baseClass}__windows`}>
<b>Windows setup experience is coming soon.</b>
<p>
Need to customize setup for Windows users?{" "}
<CustomLink url={SUPPORT_LINK} text="Let us know" newTab />
</p>
</div>
);
}
if (isLoading || isLoadingGlobalConfig || isLoadingTeamConfig) {
return <Spinner />;
}
if (isError) {
return <DataError />;
}
if (softwareTitles || softwareTitles === null) {
const appleMdmAndAbmEnabled =
globalConfig?.mdm.enabled_and_configured &&
globalConfig?.mdm.apple_bm_enabled_and_configured;
// TODO - incorporate Windows MDM condition when implementing Windows software install on setup
if (platform === "macos" && !appleMdmAndAbmEnabled) {
return (
<TurnOnMdmMessage
header="Additional configuration required"
info="To customize, first turn on automatic enrollment."
buttonText="Turn on"
router={router}
/>
);
}
return (
<SetupExperienceContentContainer>
<AddInstallSoftware
currentTeamId={currentTeamId}
hasManualAgentInstall={hasManualAgentInstall}
softwareTitles={softwareTitles}
onAddSoftware={() => setShowSelectSoftwareModal(true)}
platform={platform}
/>
<InstallSoftwarePreview platform={platform} />
</SetupExperienceContentContainer>
);
}
return null;
};
return (
<section className={baseClass}>
<SectionHeader title="Install software" />
<TabNav>
<Tabs
selectedIndex={PLATFORM_BY_INDEX.indexOf(selectedPlatform)}
onSelect={handleTabChange}
>
<TabList>
<Tab>
<TabText>macOS</TabText>
</Tab>
<Tab>
<TabText>Windows</TabText>
</Tab>
<Tab>
<TabText>Linux</TabText>
</Tab>
</TabList>
<TabPanel>{renderTabContent(PLATFORM_BY_INDEX[0])}</TabPanel>
<TabPanel>{renderTabContent(PLATFORM_BY_INDEX[1])}</TabPanel>
<TabPanel>{renderTabContent(PLATFORM_BY_INDEX[2])}</TabPanel>
</Tabs>
</TabNav>
{showSelectSoftwareModal && softwareTitles && (
<SelectSoftwareModal
currentTeamId={currentTeamId}
softwareTitles={softwareTitles}
platform={selectedPlatform}
onSave={onSave}
onExit={() => setShowSelectSoftwareModal(false)}
/>
)}
</section>
);
};
export default InstallSoftware;