Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FinalFormFileSelect #1461

Merged
merged 33 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
02d6bf2
Add final form file upload
NataliaVizintini Nov 29, 2023
2213164
show file list
NataliaVizintini Nov 29, 2023
fcfffed
trim file name after 20 characters
NataliaVizintini Dec 13, 2023
82d8f9c
Merge remote-tracking branch 'origin/main' into fileUpload
NataliaVizintini Dec 28, 2023
8b4fa03
Fix droppable typo
NataliaVizintini Dec 28, 2023
2ce68f8
Merge remote-tracking branch 'origin/main' into fileUpload
NataliaVizintini Jan 3, 2024
ff74d96
Add maxSize prop and fix multiple files
NataliaVizintini Jan 4, 2024
1f050af
Remove caption prop, use multiple, use fieldValue
NataliaVizintini Jan 5, 2024
13d9a71
Add fileRejection error
NataliaVizintini Jan 8, 2024
5a4f86f
Add error icon to droppable area
NataliaVizintini Jan 8, 2024
6ec78cf
Add maxSize helper text and make maxSize input in bytes
NataliaVizintini Jan 9, 2024
02dc985
Add File|File[] type for fieldValue
NataliaVizintini Jan 31, 2024
c39a517
Add props for button and dropzone
NataliaVizintini Feb 7, 2024
6b98852
Readable maxSize notation in story
NataliaVizintini Feb 7, 2024
3218d16
Merge main
NataliaVizintini Feb 22, 2024
19d6aeb
Simplify checks for fileList
NataliaVizintini Feb 22, 2024
e92d356
add textOverflow
NataliaVizintini Feb 23, 2024
bad31dc
Add maxWidth to fieldContainer
NataliaVizintini Feb 23, 2024
69986fc
Rename component and add maxFiles prop
NataliaVizintini Apr 8, 2024
2775acd
Overrideable icons, renamed props
NataliaVizintini Apr 9, 2024
16b75a3
Add changeset, remove Field suffix from component name
NataliaVizintini Apr 15, 2024
0b57351
Apply suggestions from code review
NataliaVizintini Apr 16, 2024
890d6e0
Use infoIcon and typography
NataliaVizintini Apr 16, 2024
4b1ca5d
Remove minWidth, change name to FinalFormFileSelect
NataliaVizintini Apr 17, 2024
2d83ec7
Fix padding for rejectedFileItem
NataliaVizintini Apr 17, 2024
e59d345
Update .changeset/strong-onions-cough.md
NataliaVizintini Apr 23, 2024
acc37dc
make props optional
NataliaVizintini Apr 23, 2024
494781e
merge main
NataliaVizintini Apr 25, 2024
00e9b8c
FieldValue - File
NataliaVizintini Apr 29, 2024
bd345b1
Apply suggestions from code review
NataliaVizintini Apr 30, 2024
8d59086
fix rename icon
NataliaVizintini Apr 30, 2024
60a666b
Add maximum files amount message and change button background
NataliaVizintini May 2, 2024
e9fff1c
Hide Dropzone and show Alert if maxFiles reached
NataliaVizintini May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions packages/admin/admin-stories/src/admin/form/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Card, CardContent, Grid } from "@mui/material";
import { storiesOf } from "@storybook/react";
import * as React from "react";
import { Form } from "react-final-form";
import { FormattedMessage } from "react-intl";

function Story() {
return (
Expand All @@ -27,10 +26,11 @@ function Story() {
<CardContent>
<Field
name="uploadMultipleDisabled"
label="File upload (dropzone only, multiple disabled)"
label="File upload (dropzone only, multiple, max file size 5 MB)"
dropzoneVariant="dropzoneOnly"
component={FinalFormFileUpload}
multipleFiles={false}
maxSize={5}
multiple
/>
</CardContent>
</Card>
Expand All @@ -42,15 +42,8 @@ function Story() {
name="uploadImages"
label="File upload (button only, accept only images)"
accept={{ "image/*": [] }}
maxSize={10}
dropzoneVariant="buttonOnly"
component={FinalFormFileUpload}
caption={
<FormattedMessage
id="comet.finalformfileupload.maximumfilesize"
defaultMessage="Maximum file size 10 MB"
/>
}
/>
</CardContent>
</Card>
Expand Down
13 changes: 4 additions & 9 deletions packages/admin/admin/src/form/FinalFormFileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Delete, Select } from "@comet/admin-icons";
import { Button, Chip, ComponentsOverrides, FormHelperText, IconButton, Theme } from "@mui/material";
import { Button, Chip, ComponentsOverrides, IconButton, Theme } from "@mui/material";
import { createStyles, WithStyles, withStyles } from "@mui/styles";
import clsx from "clsx";
import * as React from "react";
Expand Down Expand Up @@ -72,8 +72,6 @@ const styles = ({ palette }: Theme) => {

export interface FinalFormFileUploadProps extends FieldRenderProps<File[], HTMLInputElement> {
johnnyomair marked this conversation as resolved.
Show resolved Hide resolved
dropzoneVariant: "dropzoneOnly" | "buttonOnly" | "default";
NataliaVizintini marked this conversation as resolved.
Show resolved Hide resolved
caption: React.ReactNode;
multipleFiles: boolean;
accept: Accept;
NataliaVizintini marked this conversation as resolved.
Show resolved Hide resolved
maxSize: number;
}
Expand All @@ -82,11 +80,9 @@ const FinalFormFileUploadComponent: React.FunctionComponent<WithStyles<typeof st
classes,
disabled,
dropzoneVariant,
caption,
multipleFiles = true,
accept,
maxSize = 50,
NataliaVizintini marked this conversation as resolved.
Show resolved Hide resolved
input: { name, onChange, value: fieldValue },
input: { onChange, value: fieldValue, multiple: multipleFiles },
johnnyomair marked this conversation as resolved.
Show resolved Hide resolved
}) => {
const onDrop = React.useCallback(
(acceptedFiles: File[]) => {
Expand All @@ -103,7 +99,7 @@ const FinalFormFileUploadComponent: React.FunctionComponent<WithStyles<typeof st

const maxFileSizeInBytes = maxSize * 1024 * 1024;

const { acceptedFiles, getRootProps, getInputProps, isDragReject } = useDropzone({
const { getRootProps, getInputProps, isDragReject } = useDropzone({
onDrop,
accept,
disabled,
Expand Down Expand Up @@ -143,8 +139,7 @@ const FinalFormFileUploadComponent: React.FunctionComponent<WithStyles<typeof st
</Button>
)}
</div>
{acceptedFiles.length > 0 && <div className={classes.fileList}>{files}</div>}
{caption && <FormHelperText>{caption}</FormHelperText>}
{fieldValue.length > 0 && <div className={classes.fileList}>{files}</div>}
</div>
);
};
Expand Down