mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
376be83062
## Addresses #14752 ### (see issue for detailed list of features implemented) ![script list alpha](https://github.com/fleetdm/fleet/assets/61553566/1b35da72-5ff9-47e2-9d4b-0e0334e2c2b8) ![details-scripts-mac](https://github.com/fleetdm/fleet/assets/61553566/6ccad298-d4bd-47fa-bd0b-193f87b68881) ![details-scripts-windows](https://github.com/fleetdm/fleet/assets/61553566/208bb2c4-eaf8-45c4-8a9b-dfd7590f2117) ![error](https://github.com/fleetdm/fleet/assets/61553566/c0f1ad90-345b-4356-922a-ad76da96db0e) - Also addresses #15140: ![fixed-dropdown-table-issue](https://github.com/fleetdm/fleet/assets/61553566/6a0d951d-156a-4d86-a1ab-9b00cd731e94) - Align host details > scripts > Status cells' icon alignments (see misaligned "pending" icon above): ![Screenshot 2023-11-14 at 4 08 01 PM](https://github.com/fleetdm/fleet/assets/61553566/a354d8c4-f56a-4cf0-8d58-1fc0ad662180) ## Checklist for submitter - [x] Changes file added for user-visible changes in `changes/` - [x] Added/updated tests - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import React from "react";
|
|
import classnames from "classnames";
|
|
|
|
import Button from "components/buttons/Button";
|
|
import Card from "components/Card";
|
|
import { GraphicNames } from "components/graphics";
|
|
import Graphic from "components/Graphic";
|
|
|
|
const baseClass = "file-uploader";
|
|
|
|
type ISupportedGraphicNames = Extract<
|
|
GraphicNames,
|
|
| "file-configuration-profile"
|
|
| "file-sh"
|
|
| "file-ps1"
|
|
| "file-py"
|
|
| "file-script"
|
|
| "file-pdf"
|
|
| "file-pkg"
|
|
| "file-p7m"
|
|
| "file-pem"
|
|
>;
|
|
|
|
interface IFileUploaderProps {
|
|
graphicName: ISupportedGraphicNames | ISupportedGraphicNames[];
|
|
message: string;
|
|
additionalInfo?: string;
|
|
/** Controls the loading spinner on the upload button */
|
|
isLoading?: boolean;
|
|
/** A comma seperated string of one or more file types accepted to upload.
|
|
* This is the same as the html accept attribute.
|
|
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept
|
|
*/
|
|
accept?: string;
|
|
className?: string;
|
|
onFileUpload: (files: FileList | null) => void;
|
|
}
|
|
|
|
/**
|
|
* A component that encapsulates the UI for uploading a file.
|
|
*/
|
|
const FileUploader = ({
|
|
graphicName: graphicNames,
|
|
message,
|
|
additionalInfo,
|
|
isLoading = false,
|
|
accept,
|
|
className,
|
|
onFileUpload,
|
|
}: IFileUploaderProps) => {
|
|
const classes = classnames(baseClass, className);
|
|
|
|
const renderGraphics = () => {
|
|
const graphicNamesArr =
|
|
typeof graphicNames === "string" ? [graphicNames] : graphicNames;
|
|
return graphicNamesArr.map((graphicName) => (
|
|
<Graphic
|
|
key={`${graphicName}-graphic`}
|
|
className={`${baseClass}__graphic`}
|
|
name={graphicName}
|
|
/>
|
|
));
|
|
};
|
|
return (
|
|
<Card color="gray" className={classes}>
|
|
<div className={`${baseClass}__graphics`}>{renderGraphics()}</div>
|
|
<p className={`${baseClass}__message`}>{message}</p>
|
|
{additionalInfo && (
|
|
<p className={`${baseClass}__additional-info`}>{additionalInfo}</p>
|
|
)}
|
|
<Button
|
|
className={`${baseClass}__upload-button`}
|
|
variant="brand"
|
|
isLoading={isLoading}
|
|
>
|
|
<label htmlFor="upload-profile">Upload</label>
|
|
</Button>
|
|
<input
|
|
accept={accept}
|
|
id="upload-profile"
|
|
type="file"
|
|
onChange={(e) => {
|
|
onFileUpload(e.target.files);
|
|
e.target.value = "";
|
|
}}
|
|
/>
|
|
</Card>
|
|
);
|
|
};
|
|
|
|
export default FileUploader;
|