Skip to content

Commit 9f591f3

Browse files
committed
[FIX]: Fix url validation for uploading and autouploading
1 parent 8e1e32b commit 9f591f3

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@files-ui/react",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "UI components for file uploads with React js",
55
"main": "./build/index.js",
66
"module": "./build/index.es.js",

src/Dropzone/components/dropzone/Dropzone.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
269269
// flag is already true or there isnt files
270270
//url was not provided
271271

272-
if (isUploading || localFiles.length === 0 || !url) {
272+
if (isUploading || localFiles.length === 0 || !shouldUpload) {
273273
setIsUploading(false);
274274
return;
275275
}

src/FileInputButton/FileInputButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
207207
// flag is already true or there isnt files
208208
//url was not provided
209209

210-
if (isUploading || localFiles.length === 0 || !url) {
210+
if (isUploading || localFiles.length === 0 || !shouldUpload) {
211211
setIsUploading(false);
212212
return;
213213
}

src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ export {
5858
JsonParseResponse,
5959
NAMED_COLORS,
6060
NO_XHR_PROVIDED_ERROR,
61-
NamedColor, SyntheticFile,
61+
SyntheticFile,
6262
TIMEOUT_ERROR_RESPONSE,
6363
UNEXPECTED_ERROR_RESPONSE,
64-
UploadPromiseResponse,
6564
ValidateErrorEnglish,
6665
ValidateErrorFrench,
6766
ValidateErrorItalian,
@@ -128,7 +127,7 @@ export {
128127
sleepTransition,
129128
unableToUploadResult,
130129
unexpectedErrorUploadResult,
131-
} from "@files-ui/core"
130+
} from "@files-ui/core";
132131

133132
export type {
134133
ExtFile,
@@ -145,7 +144,9 @@ export type {
145144
FileValidatorProps,
146145
FunctionLabel,
147146
LocalLabels,
148-
Method
147+
Method,
148+
NamedColor,
149+
UploadPromiseResponse
149150
} from "@files-ui/core"
150151

151152

src/utils/url.utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export const isThereValidUrl = (
55
urlFunction?: Function,
66
extFileList?: ExtFile[]
77
): boolean => {
8-
return ExtFileInstance.someValidUrl(extFileList) && url && url.length && urlFunction != undefined;
8+
return ExtFileInstance.someValidUrl(extFileList || []) || urlFunction != undefined || (url != undefined && url.length > 0);
99
}

tests/Dropzone.test.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import "@testing-library/jest-dom";
2+
import React from "react";
3+
import { Dropzone } from "../src";
4+
5+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
6+
7+
test("Validate label text must be 'Drop yor files here...'", () => {
8+
render(<Dropzone> Drop yor files here...</Dropzone>);
9+
expect(screen.getByText("Drop yor files here...")).toBeInTheDocument();
10+
});
11+
12+
describe("Dropzone actionButtons", () => {
13+
test.each([
14+
[{ uploadButton: { onClick: console.log } }, false],
15+
[{ uploadButton: { onClick: console.log, disabled: false } }, false],
16+
[{ uploadButton: { onClick: console.log, disabled: true } }, true],
17+
[{ deleteButton: { onClick: console.log } }, false],
18+
[{ deleteButton: { onClick: console.log, disabled: false } }, false],
19+
[{ deleteButton: { onClick: console.log, disabled: true } }, true],
20+
21+
// abortButton and cleanButton need more interaction
22+
])("disabled %s -> %s", (config, expected) => {
23+
const { container } = render(
24+
<Dropzone actionButtons={{ position: "after", ...config }} />,
25+
);
26+
expect(
27+
(
28+
container.querySelector(
29+
".files-ui-buttons-container button",
30+
) as HTMLInputElement
31+
).disabled,
32+
).toBe(expected);
33+
});
34+
});

0 commit comments

Comments
 (0)