mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
FileDropzone: Revert introducing a new prop (#62324)
This commit is contained in:
parent
317ef1de86
commit
9453bec819
@ -112,12 +112,6 @@ describe('The FileDropzone component', () => {
|
||||
expect(onDrop).toBeCalledWith([fileToUpload], [], expect.anything());
|
||||
});
|
||||
|
||||
it('should display the text generated by a custom primaryTextSupplier', async () => {
|
||||
const customText = 'custom text from primaryTextSuplier';
|
||||
render(<FileDropzone primaryTextSupplier={() => customText} />);
|
||||
expect(await screen.findByText(customText)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show children inside the dropzone', () => {
|
||||
const component = (
|
||||
<FileDropzone>
|
||||
|
@ -46,7 +46,6 @@ export interface FileDropzoneProps {
|
||||
*/
|
||||
fileListRenderer?: (file: DropzoneFile, removeFile: (file: DropzoneFile) => void) => ReactNode;
|
||||
onFileRemove?: (file: DropzoneFile) => void;
|
||||
primaryTextSupplier?: (files: DropzoneFile[], options?: BackwardsCompatibleDropzoneOptions) => string;
|
||||
}
|
||||
|
||||
export interface DropzoneFile {
|
||||
@ -58,15 +57,7 @@ export interface DropzoneFile {
|
||||
retryUpload?: () => void;
|
||||
}
|
||||
|
||||
export function FileDropzone({
|
||||
options,
|
||||
primaryTextSupplier = getPrimaryText,
|
||||
children,
|
||||
readAs,
|
||||
onLoad,
|
||||
fileListRenderer,
|
||||
onFileRemove,
|
||||
}: FileDropzoneProps) {
|
||||
export function FileDropzone({ options, children, readAs, onLoad, fileListRenderer, onFileRemove }: FileDropzoneProps) {
|
||||
const [files, setFiles] = useState<DropzoneFile[]>([]);
|
||||
const [fileErrors, setErrorMessages] = useState<FileError[]>([]);
|
||||
|
||||
@ -221,7 +212,7 @@ export function FileDropzone({
|
||||
<div className={styles.container}>
|
||||
<div data-testid="dropzone" {...getRootProps({ className: styles.dropzone })}>
|
||||
<input {...getInputProps()} />
|
||||
{children ?? <FileDropzoneDefaultChildren primaryText={primaryTextSupplier(files, options)} />}
|
||||
{children ?? <FileDropzoneDefaultChildren primaryText={getPrimaryText(files, options)} />}
|
||||
</div>
|
||||
{fileErrors.length > 0 && renderErrorMessages(fileErrors)}
|
||||
{options?.accept && (
|
||||
|
@ -24,6 +24,7 @@ import {
|
||||
InlineFieldRow,
|
||||
InlineLabel,
|
||||
FileDropzone,
|
||||
FileDropzoneDefaultChildren,
|
||||
DropzoneFile,
|
||||
Themeable2,
|
||||
withTheme2,
|
||||
@ -68,10 +69,6 @@ export class UnthemedQueryEditor extends PureComponent<Props, State> {
|
||||
},
|
||||
];
|
||||
|
||||
dropzoneTextSupplier = () => {
|
||||
return this.props?.query?.file ? 'Replace file' : 'Upload file';
|
||||
};
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
|
||||
@ -403,8 +400,9 @@ export class UnthemedQueryEditor extends PureComponent<Props, State> {
|
||||
fileListRenderer={this.fileListRenderer}
|
||||
options={{ onDropAccepted: this.onDropAccepted, maxSize: 200000, multiple: false }}
|
||||
onLoad={this.onFileDrop}
|
||||
primaryTextSupplier={this.dropzoneTextSupplier}
|
||||
></FileDropzone>
|
||||
>
|
||||
<FileDropzoneDefaultChildren primaryText={this.props?.query?.file ? 'Replace file' : 'Upload file'} />
|
||||
</FileDropzone>
|
||||
{file && (
|
||||
<div className={styles.file}>
|
||||
<span>{file?.name}</span>
|
||||
|
Loading…
Reference in New Issue
Block a user