mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #44330, Resolves #44331 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests. (I'd defer integration tests to a separate PR since this one is pretty large already.) - [x] QA'd all new/changed functionality manually. I've tested this on both the setup flow and the organization settings page. I haven't had the time to test this on other places where we render the logo (macOS setup experience / MDM migration dialog). https://github.com/user-attachments/assets/95d4eae5-3da6-40f4-98a1-8575b97d96b3 ## New Fleet configuration settings - [x] Setting(s) is/are explicitly excluded from GitOps. Will handle GitOps in a separate PR. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Organizations can upload custom logos for light and dark modes. * Registration and Org Settings support logo file upload, preview, per-mode replace/delete, and validation (size & image formats). * Activity feed records logo changes/deletions; site nav displays uploaded logos per theme. * File uploader/preview adds a Fleet logo graphic option and improved logo validation. * Config/GitOps outputs now include separate dark/light logo fields. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
167 lines
4.7 KiB
TypeScript
167 lines
4.7 KiB
TypeScript
import React from "react";
|
|
|
|
import classnames from "classnames";
|
|
|
|
import { IFileDetails } from "utilities/file/fileUtils";
|
|
|
|
import Button from "components/buttons/Button";
|
|
import { ISupportedGraphicNames } from "components/FileUploader/FileUploader";
|
|
import Graphic from "components/Graphic";
|
|
import Icon from "components/Icon";
|
|
import GitOpsModeTooltipWrapper from "components/GitOpsModeTooltipWrapper";
|
|
|
|
export type IFileDetailsSupportedGraphicNames =
|
|
| ISupportedGraphicNames
|
|
| "app-store"; // For VPP apps (non-editable)
|
|
|
|
interface IFileDetailsProps {
|
|
graphicNames:
|
|
| IFileDetailsSupportedGraphicNames
|
|
| IFileDetailsSupportedGraphicNames[];
|
|
fileDetails: IFileDetails;
|
|
canEdit: boolean;
|
|
/** If present, will default to a custom editor section instead of edit icon */
|
|
customEditor?: () => React.ReactNode;
|
|
/** If present, replaces the default Graphic on the left of the file
|
|
* details (e.g. to render a preview thumbnail of an uploaded image). */
|
|
customPreview?: React.ReactNode;
|
|
/** If present, will show a trash icon */
|
|
onDeleteFile?: () => void;
|
|
onFileSelect?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
accept?: string;
|
|
progress?: number;
|
|
/** Set to false for one instance we allow users to edit a file as it shows them the YAML */
|
|
gitopsCompatible?: boolean;
|
|
gitOpsModeEnabled?: boolean;
|
|
}
|
|
|
|
const baseClass = "file-details";
|
|
|
|
const FileDetails = ({
|
|
graphicNames,
|
|
fileDetails,
|
|
canEdit,
|
|
customEditor,
|
|
customPreview,
|
|
onDeleteFile,
|
|
onFileSelect,
|
|
accept,
|
|
progress,
|
|
gitopsCompatible = true,
|
|
gitOpsModeEnabled = false,
|
|
}: IFileDetailsProps) => {
|
|
const inputRef = React.useRef<HTMLInputElement | null>(null);
|
|
|
|
const handleClickEdit = (disabled?: boolean) => {
|
|
if (disabled) return;
|
|
inputRef.current?.click();
|
|
};
|
|
|
|
const infoClasses = classnames(`${baseClass}__info`, {
|
|
[`${baseClass}__info--disabled-by-gitops-mode`]:
|
|
gitOpsModeEnabled && gitopsCompatible,
|
|
});
|
|
|
|
const renderEditButton = (disabled?: boolean) => {
|
|
if (customEditor) {
|
|
return (
|
|
<div
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
}}
|
|
>
|
|
{customEditor()}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className={`${baseClass}__edit`}>
|
|
<Button
|
|
disabled={disabled}
|
|
className={`${baseClass}__edit-button`}
|
|
variant="icon"
|
|
onClick={() => handleClickEdit(disabled)}
|
|
title="Replace file"
|
|
>
|
|
<Icon name="pencil" color="ui-fleet-black-75" />
|
|
</Button>
|
|
<input
|
|
ref={inputRef}
|
|
type="file"
|
|
accept={accept}
|
|
onChange={onFileSelect}
|
|
className="file-input-visually-hidden"
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<div className={baseClass}>
|
|
{/* disabling at this level preserves funcitonality of GitOpsModeTooltipWrapper around the edit icon */}
|
|
<div className={infoClasses}>
|
|
{customPreview ?? (
|
|
<Graphic
|
|
name={
|
|
typeof graphicNames === "string" ? graphicNames : graphicNames[0]
|
|
}
|
|
/>
|
|
)}
|
|
<div className={`${baseClass}__content`}>
|
|
<div className={`${baseClass}__name`}>{fileDetails.name}</div>
|
|
{fileDetails.description && (
|
|
<div className={`${baseClass}__description`}>
|
|
{fileDetails.description}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
{!progress &&
|
|
canEdit &&
|
|
onFileSelect &&
|
|
(gitopsCompatible ? (
|
|
<GitOpsModeTooltipWrapper
|
|
position="left"
|
|
tipOffset={4}
|
|
renderChildren={(disableChildren) =>
|
|
renderEditButton(disableChildren)
|
|
}
|
|
/>
|
|
) : (
|
|
renderEditButton()
|
|
))}
|
|
{!progress && onDeleteFile && (
|
|
<div className={`${baseClass}__delete`}>
|
|
<Button
|
|
className={`${baseClass}__delete-button`}
|
|
variant="icon"
|
|
onClick={onDeleteFile}
|
|
>
|
|
<label htmlFor="delete-file">
|
|
<Icon name="trash" color="ui-fleet-black-75" />
|
|
</label>
|
|
</Button>
|
|
</div>
|
|
)}
|
|
{!!progress && (
|
|
<div className={`${baseClass}__progress-wrapper`}>
|
|
<div className={`${baseClass}__progress-bar`}>
|
|
<div
|
|
className={`${baseClass}__progress-bar--uploaded`}
|
|
style={{
|
|
width: `${progress * 100}%`,
|
|
}}
|
|
title="upload progress bar"
|
|
/>
|
|
</div>
|
|
<div className={`${baseClass}__progress-text`}>
|
|
{Math.round(progress * 100)}%
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default FileDetails;
|