mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
## For #26229 – Part 1

- This PR contains the core abstractions, routes, API updates, and types
for GitOps mode in the UI. Since this work will touch essentially every
part of the Fleet UI, it is ripe for merge conflicts. To mitigate such
conflicts, I'll be merging this work in a number of iterative PRs. ~To
effectively gate any of this work from showing until it is all merged to
`main`, [this commit](feedbb2d4c) hides
the settings section that allows enabling/disabling this setting,
effectively feature flagging the entire thing. In the last of these
iterative PRs, that commit will be reverted to engage the entire
feature. For testing purposes, reviewers can `git revert
feedbb2d4c25ec2e304e1f18d409cee62f6752ed` locally~ The new settings
section for this feature is feature flagged until all PRs are merged -
to show the setting section while testing, run `ALLOW_GITOPS_MODE=true
NODE_ENV=development yarn run webpack --progress --watch` in place of
`make generate-dev`
- Changes file will be added and feature flag removed in the last PR
- [x] Settings page with routing, form, API integration (hidden until
last PR)
- [x] Activities
- [x] Navbar indicator
- Apply GOM conditional UI to:
- [x] Manage enroll secret modal: .5
- Controls >
- [x] Scripts:
- Setup experience >
- [x] Install software > Select software modal
- [x] OS Settings >
- [x] Custom settings
- [x] Disk encryption
- [x] OS Updates
2/18/25, added to this PR:
- [x] Controls > Setup experience > Run script
- [x] Software >
- [x] Manage automations modal
- [x] Add software >
- [x] App Store (VPP)
- [x] Custom package
- [x] Queries
- [x] Manage
- [x] Automations modal
- [x] New
- [x] Edit
- [x] Policies
- [x] Manage
- [x] New
- [x] Edit
- Manage automations
- [x] Calendar events
- [x] Manual QA for all new/changed functionality
---------
Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
152 lines
4.6 KiB
TypeScript
152 lines
4.6 KiB
TypeScript
import React, { useCallback, useContext, useState } from "react";
|
|
import { InjectedRouter, Params } from "react-router/lib/Router";
|
|
import { useQuery } from "react-query";
|
|
import { useErrorHandler } from "react-error-boundary";
|
|
|
|
import { IConfig } from "interfaces/config";
|
|
import { IApiError } from "interfaces/errors";
|
|
import configAPI from "services/entities/config";
|
|
import { AppContext } from "context/app";
|
|
import { NotificationContext } from "context/notification";
|
|
import deepDifference from "utilities/deep_difference";
|
|
import Spinner from "components/Spinner";
|
|
import paths from "router/paths";
|
|
|
|
import SideNav from "../components/SideNav";
|
|
import ORG_SETTINGS_NAV_ITEMS from "./OrgSettingsNavItems";
|
|
import { DeepPartial } from "./cards/constants";
|
|
|
|
interface IOrgSettingsPageProps {
|
|
params: Params;
|
|
router: InjectedRouter; // v3
|
|
}
|
|
|
|
export const baseClass = "org-settings";
|
|
|
|
const OrgSettingsPage = ({ params, router }: IOrgSettingsPageProps) => {
|
|
const { section } = params;
|
|
const DEFAULT_SETTINGS_SECTION = ORG_SETTINGS_NAV_ITEMS[0];
|
|
|
|
const [isUpdatingSettings, setIsUpdatingSettings] = useState(false);
|
|
const { isFreeTier, isPremiumTier, setConfig, isSandboxMode } = useContext(
|
|
AppContext
|
|
);
|
|
|
|
if (isSandboxMode) {
|
|
// redirect to Integrations page in sandbox mode
|
|
router.push(paths.ADMIN_INTEGRATIONS);
|
|
}
|
|
const { renderFlash } = useContext(NotificationContext);
|
|
const handlePageError = useErrorHandler();
|
|
|
|
const {
|
|
data: appConfig,
|
|
isLoading: isLoadingAppConfig,
|
|
refetch: refetchConfig,
|
|
} = useQuery<IConfig, Error, IConfig>(["config"], () => configAPI.loadAll(), {
|
|
select: (data: IConfig) => data,
|
|
onSuccess: (data) => {
|
|
setConfig(data);
|
|
},
|
|
});
|
|
|
|
const onFormSubmit = useCallback(
|
|
(formUpdates: DeepPartial<IConfig>) => {
|
|
if (!appConfig) {
|
|
return false;
|
|
}
|
|
|
|
setIsUpdatingSettings(true);
|
|
|
|
const diff = deepDifference(formUpdates, appConfig);
|
|
// send all formUpdates.agent_options because diff overrides all agent options
|
|
diff.agent_options = formUpdates.agent_options;
|
|
|
|
configAPI
|
|
.update(diff)
|
|
.then(() => {
|
|
renderFlash("success", "Successfully updated settings.");
|
|
refetchConfig();
|
|
})
|
|
.catch((response: { data: IApiError }) => {
|
|
if (
|
|
response?.data.errors[0].reason.includes("could not dial smtp host")
|
|
) {
|
|
renderFlash(
|
|
"error",
|
|
"Could not connect to SMTP server. Please try again."
|
|
);
|
|
} else if (response?.data.errors) {
|
|
const reason = response?.data.errors[0].reason;
|
|
const agentOptionsInvalid =
|
|
reason.includes("unsupported key provided") ||
|
|
reason.includes("invalid value type");
|
|
const isAgentOptionsError =
|
|
agentOptionsInvalid ||
|
|
reason.includes("script_execution_timeout' value exceeds limit.");
|
|
renderFlash(
|
|
"error",
|
|
<>
|
|
Couldn't update{" "}
|
|
{isAgentOptionsError ? "agent options" : "settings"}: {reason}
|
|
{agentOptionsInvalid && (
|
|
<>
|
|
<br />
|
|
If you're not using the latest osquery, use the
|
|
fleetctl apply --force command to override validation.
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
})
|
|
.finally(() => {
|
|
setIsUpdatingSettings(false);
|
|
});
|
|
},
|
|
[appConfig, refetchConfig, renderFlash]
|
|
);
|
|
|
|
// filter out non-premium options
|
|
let navItems = ORG_SETTINGS_NAV_ITEMS;
|
|
if (!isPremiumTier) {
|
|
navItems = ORG_SETTINGS_NAV_ITEMS.filter(
|
|
(item) => item.urlSection !== "fleet-desktop"
|
|
);
|
|
}
|
|
|
|
const currentFormSection =
|
|
navItems.find((item) => item.urlSection === section) ??
|
|
DEFAULT_SETTINGS_SECTION;
|
|
|
|
const CurrentCard = currentFormSection.Card;
|
|
|
|
if (isFreeTier && section === "fleet-desktop") {
|
|
handlePageError({ status: 403 });
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div className={`${baseClass}`}>
|
|
<SideNav
|
|
className={`${baseClass}__side-nav`}
|
|
navItems={navItems}
|
|
activeItem={currentFormSection.urlSection}
|
|
CurrentCard={
|
|
!isLoadingAppConfig && appConfig ? (
|
|
<CurrentCard
|
|
appConfig={appConfig}
|
|
handleSubmit={onFormSubmit}
|
|
isUpdatingSettings={isUpdatingSettings}
|
|
isPremiumTier={isPremiumTier}
|
|
/>
|
|
) : (
|
|
<Spinner />
|
|
)
|
|
}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default OrgSettingsPage;
|