2023-05-18 15:59:14 +00:00
|
|
|
import React, { useContext } from "react";
|
2023-02-21 15:31:19 +00:00
|
|
|
import { Params } from "react-router/lib/Router";
|
|
|
|
|
|
2023-03-20 19:30:13 +00:00
|
|
|
import { AppContext } from "context/app";
|
2023-02-21 15:31:19 +00:00
|
|
|
import SideNav from "pages/admin/components/SideNav";
|
2023-03-08 19:43:00 +00:00
|
|
|
import { useQuery } from "react-query";
|
2023-05-18 15:59:14 +00:00
|
|
|
import { ProfileSummaryResponse } from "interfaces/mdm";
|
2023-03-31 17:40:14 +00:00
|
|
|
import { API_NO_TEAM_ID, APP_CONTEXT_NO_TEAM_ID } from "interfaces/team";
|
2023-03-08 19:43:00 +00:00
|
|
|
import mdmAPI from "services/entities/mdm";
|
2023-02-21 15:31:19 +00:00
|
|
|
|
|
|
|
|
import MAC_OS_SETTINGS_NAV_ITEMS from "./MacOSSettingsNavItems";
|
2023-04-05 18:34:30 +00:00
|
|
|
import AggregateMacSettingsIndicators from "./AggregateMacSettingsIndicators";
|
2023-02-21 15:31:19 +00:00
|
|
|
|
|
|
|
|
const baseClass = "mac-os-settings";
|
|
|
|
|
|
|
|
|
|
interface IMacOSSettingsProps {
|
|
|
|
|
params: Params;
|
2023-04-05 16:58:26 +00:00
|
|
|
location: {
|
|
|
|
|
search: string;
|
|
|
|
|
};
|
2023-02-21 15:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-05 16:58:26 +00:00
|
|
|
const MacOSSettings = ({
|
|
|
|
|
location: { search: queryString },
|
|
|
|
|
params,
|
|
|
|
|
}: IMacOSSettingsProps) => {
|
2023-02-21 15:31:19 +00:00
|
|
|
const { section } = params;
|
2023-03-20 19:30:13 +00:00
|
|
|
const { currentTeam } = useContext(AppContext);
|
|
|
|
|
|
2023-04-05 18:34:30 +00:00
|
|
|
// TODO: consider using useTeamIdParam hook here instead in the future
|
2023-03-20 19:30:13 +00:00
|
|
|
const teamId =
|
2023-03-31 17:40:14 +00:00
|
|
|
currentTeam?.id === undefined || currentTeam.id < APP_CONTEXT_NO_TEAM_ID
|
|
|
|
|
? API_NO_TEAM_ID // coerce undefined and -1 to 0 for 'No team'
|
|
|
|
|
: currentTeam.id;
|
2023-03-08 19:43:00 +00:00
|
|
|
|
2023-05-05 13:44:05 +00:00
|
|
|
const {
|
|
|
|
|
data: aggregateProfileStatusData,
|
|
|
|
|
refetch: refetchAggregateProfileStatus,
|
2023-05-18 15:59:14 +00:00
|
|
|
isLoading: isLoadingAggregateProfileStatus,
|
2023-05-05 13:44:05 +00:00
|
|
|
} = useQuery<ProfileSummaryResponse>(
|
|
|
|
|
["aggregateProfileStatuses", teamId],
|
|
|
|
|
() => mdmAPI.getAggregateProfileStatuses(teamId),
|
|
|
|
|
{
|
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
|
retry: false,
|
|
|
|
|
}
|
|
|
|
|
);
|
2023-03-08 19:43:00 +00:00
|
|
|
|
2023-02-21 15:31:19 +00:00
|
|
|
const DEFAULT_SETTINGS_SECTION = MAC_OS_SETTINGS_NAV_ITEMS[0];
|
|
|
|
|
|
|
|
|
|
const currentFormSection =
|
|
|
|
|
MAC_OS_SETTINGS_NAV_ITEMS.find((item) => item.urlSection === section) ??
|
|
|
|
|
DEFAULT_SETTINGS_SECTION;
|
|
|
|
|
|
|
|
|
|
const CurrentCard = currentFormSection.Card;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={baseClass}>
|
2023-02-22 18:56:49 +00:00
|
|
|
<p className={`${baseClass}__description`}>
|
|
|
|
|
Remotely enforce settings on macOS hosts assigned to this team.
|
|
|
|
|
</p>
|
2023-05-18 15:59:14 +00:00
|
|
|
<AggregateMacSettingsIndicators
|
|
|
|
|
isLoading={isLoadingAggregateProfileStatus}
|
|
|
|
|
teamId={teamId}
|
|
|
|
|
aggregateProfileStatusData={aggregateProfileStatusData}
|
|
|
|
|
/>
|
2023-02-21 15:31:19 +00:00
|
|
|
<SideNav
|
|
|
|
|
className={`${baseClass}__side-nav`}
|
2023-04-05 16:58:26 +00:00
|
|
|
navItems={MAC_OS_SETTINGS_NAV_ITEMS.map((navItem) => ({
|
|
|
|
|
...navItem,
|
|
|
|
|
path: navItem.path.concat(queryString),
|
|
|
|
|
}))}
|
2023-02-21 15:31:19 +00:00
|
|
|
activeItem={currentFormSection.urlSection}
|
2023-03-08 19:43:00 +00:00
|
|
|
CurrentCard={
|
|
|
|
|
<CurrentCard
|
2023-03-31 17:40:14 +00:00
|
|
|
key={teamId}
|
2023-03-14 20:03:02 +00:00
|
|
|
currentTeamId={teamId}
|
2023-05-05 13:44:05 +00:00
|
|
|
onMutation={refetchAggregateProfileStatus}
|
2023-03-08 19:43:00 +00:00
|
|
|
/>
|
|
|
|
|
}
|
2023-02-21 15:31:19 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default MacOSSettings;
|