fleet/frontend/pages/ManageControlsPage/Scripts/Scripts.tsx

83 lines
2.1 KiB
TypeScript
Raw Normal View History

import React from "react";
import { InjectedRouter, Params } from "react-router/lib/Router";
2023-10-10 22:00:45 +00:00
import useTeamIdParam from "hooks/useTeamIdParam";
2023-10-10 22:00:45 +00:00
import { API_NO_TEAM_ID } from "interfaces/team";
2023-10-10 22:00:45 +00:00
import { FLEET_WEBSITE_URL } from "utilities/constants";
import SideNav from "pages/admin/components/SideNav";
import CustomLink from "components/CustomLink";
import useScriptNavItems from "./ScriptsNavItems";
2023-10-10 22:00:45 +00:00
const baseClass = "scripts";
2023-10-10 22:00:45 +00:00
export interface ScriptsLocation {
search: string;
pathname: string;
query: {
team_id?: string;
status?: string;
page?: string;
2023-10-10 22:00:45 +00:00
};
}
interface IScriptsProps {
params: Params;
router: InjectedRouter;
location: ScriptsLocation;
}
2023-10-10 22:00:45 +00:00
const Scripts = ({ router, location, params }: IScriptsProps) => {
const { section } = params;
2023-10-10 22:00:45 +00:00
const { teamIdForApi } = useTeamIdParam({
location,
router,
includeAllTeams: false,
includeNoTeam: true,
});
2023-10-10 22:00:45 +00:00
const SCRIPTS_NAV_ITEMS = useScriptNavItems(teamIdForApi);
2023-10-10 22:00:45 +00:00
const DEFAULT_SCRIPTS_SECTION = SCRIPTS_NAV_ITEMS[0];
2023-10-10 22:00:45 +00:00
const currentFormSection =
SCRIPTS_NAV_ITEMS.find((item) => item.urlSection === section) ??
DEFAULT_SCRIPTS_SECTION;
2023-10-10 22:00:45 +00:00
const CurrentCard = currentFormSection.Card;
2023-10-10 22:00:45 +00:00
return (
<div className={baseClass}>
<p className={`${baseClass}__description`}>
Change configuration and remediate issues on macOS, Windows, and Linux
hosts.{" "}
2023-10-10 22:00:45 +00:00
<CustomLink
text="Learn more"
url={`${FLEET_WEBSITE_URL}/docs/using-fleet/scripts`}
2023-10-10 22:00:45 +00:00
newTab
/>
</p>
<SideNav
className={`${baseClass}__side-nav`}
navItems={SCRIPTS_NAV_ITEMS}
activeItem={currentFormSection.urlSection}
CurrentCard={
<CurrentCard
// potential undefined for teamIdForApi is an implemenation artifact - it can be assumed
// to always be defined here
key={teamIdForApi ?? API_NO_TEAM_ID}
teamId={teamIdForApi ?? API_NO_TEAM_ID} // Scripts must be scoped to a team
router={router}
location={location}
/>
}
/>
2023-10-10 22:00:45 +00:00
</div>
);
};
export default Scripts;