mirror of
https://github.com/fleetdm/fleet
synced 2026-05-21 16:08:47 +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>
144 lines
3.9 KiB
TypeScript
144 lines
3.9 KiB
TypeScript
import React, { useState } from "react";
|
|
import { uniqueId } from "lodash";
|
|
|
|
import { stringToClipboard } from "utilities/copy_text";
|
|
import { IEnrollSecret } from "interfaces/enroll_secret";
|
|
|
|
import Button from "components/buttons/Button";
|
|
// @ts-ignore
|
|
import InputField from "components/forms/fields/InputField";
|
|
import Icon from "components/Icon";
|
|
import GitOpsModeTooltipWrapper from "components/GitOpsModeTooltipWrapper";
|
|
|
|
const baseClass = "enroll-secrets";
|
|
|
|
interface IEnrollSecretRowProps {
|
|
secret: IEnrollSecret;
|
|
toggleSecretEditorModal?: () => void;
|
|
toggleDeleteSecretModal?: () => void;
|
|
setSelectedSecret?: React.Dispatch<
|
|
React.SetStateAction<IEnrollSecret | undefined>
|
|
>;
|
|
}
|
|
const EnrollSecretRow = ({
|
|
secret,
|
|
toggleSecretEditorModal,
|
|
toggleDeleteSecretModal,
|
|
setSelectedSecret,
|
|
}: IEnrollSecretRowProps): JSX.Element | null => {
|
|
const [showSecret, setShowSecret] = useState(false);
|
|
const [copyMessage, setCopyMessage] = useState("");
|
|
|
|
const onCopySecret = (evt: React.MouseEvent) => {
|
|
evt.preventDefault();
|
|
|
|
stringToClipboard(secret.secret)
|
|
.then(() => setCopyMessage("Copied!"))
|
|
.catch(() => setCopyMessage("Copy failed"));
|
|
|
|
// Clear message after 1 second
|
|
setTimeout(() => setCopyMessage(""), 1000);
|
|
|
|
return false;
|
|
};
|
|
|
|
const onToggleSecret = (evt: React.MouseEvent) => {
|
|
evt.preventDefault();
|
|
|
|
setShowSecret(!showSecret);
|
|
return false;
|
|
};
|
|
|
|
const onEditSecretClick = (evt: React.MouseEvent<HTMLButtonElement>) => {
|
|
evt.preventDefault();
|
|
if (toggleSecretEditorModal && setSelectedSecret) {
|
|
setSelectedSecret(secret);
|
|
toggleSecretEditorModal();
|
|
}
|
|
};
|
|
|
|
const onDeleteSecretClick = (evt: React.MouseEvent<HTMLButtonElement>) => {
|
|
evt.preventDefault();
|
|
if (toggleDeleteSecretModal && setSelectedSecret) {
|
|
setSelectedSecret(secret);
|
|
toggleDeleteSecretModal();
|
|
}
|
|
};
|
|
|
|
const renderCopyShowButtons = () => {
|
|
return (
|
|
<div className={`${baseClass}__action-overlay`}>
|
|
{copyMessage && (
|
|
<div
|
|
className={`${baseClass}__copy-message`}
|
|
>{`${copyMessage} `}</div>
|
|
)}
|
|
<div className="buttons">
|
|
<Button
|
|
variant="unstyled"
|
|
className={`${baseClass}__copy-secret-icon`}
|
|
onClick={onCopySecret}
|
|
>
|
|
<Icon name="copy" />
|
|
</Button>
|
|
<Button
|
|
variant="unstyled"
|
|
className={`${baseClass}__show-secret-icon`}
|
|
onClick={onToggleSecret}
|
|
>
|
|
<Icon name="eye" />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const renderEditDeleteButtons = () => (
|
|
<GitOpsModeTooltipWrapper
|
|
tipOffset={8}
|
|
renderChildren={(disableChildren) => (
|
|
<div className="buttons">
|
|
<Button
|
|
disabled={disableChildren}
|
|
onClick={onEditSecretClick}
|
|
className={`${baseClass}__edit-secret-icon`}
|
|
variant="text-icon"
|
|
>
|
|
<Icon name="pencil" />
|
|
</Button>
|
|
<Button
|
|
onClick={onDeleteSecretClick}
|
|
disabled={disableChildren}
|
|
className={`${baseClass}__delete-secret-icon`}
|
|
variant="text-icon"
|
|
>
|
|
<Icon name="trash" />
|
|
</Button>
|
|
</div>
|
|
)}
|
|
/>
|
|
);
|
|
|
|
return (
|
|
<div
|
|
className={`${baseClass}__secret`}
|
|
key={uniqueId()}
|
|
data-testid="osquery-secret"
|
|
>
|
|
{/* TODO: replace with InputFieldHiddenContent component */}
|
|
<InputField
|
|
readOnly
|
|
inputWrapperClass={`${baseClass}__secret-input`}
|
|
name={`osqueryd-secret-${uniqueId()}`}
|
|
type={showSecret ? "text" : "password"}
|
|
value={secret.secret}
|
|
/>
|
|
{renderCopyShowButtons()}
|
|
{toggleSecretEditorModal &&
|
|
toggleDeleteSecretModal &&
|
|
renderEditDeleteButtons()}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default EnrollSecretRow;
|