@jobber/components 2.83.1 → 2.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/InputFile/InputFile.d.ts +13 -1
- package/dist/InputFile/index.js +44 -20
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,17 @@ menu: Changelog
|
|
|
8
8
|
All notable changes to this project will be documented in this file.
|
|
9
9
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
10
10
|
|
|
11
|
+
# [2.84.0](https://github.com/GetJobber/atlantis/compare/@jobber/components@2.83.1...@jobber/components@2.84.0) (2022-06-07)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **components:** JOB-40406 Allow PUT requests in InputFile component ([#895](https://github.com/GetJobber/atlantis/issues/895)) ([4101f44](https://github.com/GetJobber/atlantis/commit/4101f441327ecfebb55ce868dbd9bf7d3d9ec837))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
11
22
|
## [2.83.1](https://github.com/GetJobber/atlantis/compare/@jobber/components@2.83.0...@jobber/components@2.83.1) (2022-06-03)
|
|
12
23
|
|
|
13
24
|
|
|
@@ -37,12 +37,24 @@ export interface UploadParams {
|
|
|
37
37
|
*/
|
|
38
38
|
readonly key?: string;
|
|
39
39
|
/**
|
|
40
|
-
* Any extra fields to send with the upload
|
|
40
|
+
* Any extra fields or headers to send with the upload.
|
|
41
41
|
* If unspecified only the file will be included.
|
|
42
42
|
*/
|
|
43
43
|
readonly fields?: {
|
|
44
44
|
[field: string]: string;
|
|
45
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* The HTTP method which we wish to use for the upload
|
|
48
|
+
*
|
|
49
|
+
* When the HTTP method is `"PUT"`, the `fields` will
|
|
50
|
+
* be used as headers for the request
|
|
51
|
+
*
|
|
52
|
+
* When the HTTP method is `"POST"` the `fields` are
|
|
53
|
+
* form fields
|
|
54
|
+
*
|
|
55
|
+
* @default "POST"
|
|
56
|
+
*/
|
|
57
|
+
readonly httpMethod?: "POST" | "PUT";
|
|
46
58
|
}
|
|
47
59
|
interface InputFileProps {
|
|
48
60
|
/**
|
package/dist/InputFile/index.js
CHANGED
|
@@ -55,37 +55,61 @@ function InputFile(_a) {
|
|
|
55
55
|
}
|
|
56
56
|
function uploadFile(file) {
|
|
57
57
|
return __chunk_1.__awaiter(this, void 0, void 0, function () {
|
|
58
|
-
var _a, url, _b, key, _c, fields, fileUpload,
|
|
59
|
-
return __chunk_1.__generator(this, function (
|
|
60
|
-
switch (
|
|
58
|
+
var _a, url, _b, key, _c, fields, _d, httpMethod, fileUpload, handleUploadProgress, handleUploadComplete, axiosConfig;
|
|
59
|
+
return __chunk_1.__generator(this, function (_e) {
|
|
60
|
+
switch (_e.label) {
|
|
61
61
|
case 0: return [4 /*yield*/, getUploadParams(file)];
|
|
62
62
|
case 1:
|
|
63
|
-
_a =
|
|
63
|
+
_a = _e.sent(), url = _a.url, _b = _a.key, key = _b === void 0 ? uuid.v1() : _b, _c = _a.fields, fields = _c === void 0 ? {} : _c, _d = _a.httpMethod, httpMethod = _d === void 0 ? "POST" : _d;
|
|
64
64
|
fileUpload = getFileUpload(file, key);
|
|
65
65
|
onUploadStart && onUploadStart(__chunk_1.__assign({}, fileUpload));
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})
|
|
80
|
-
.then(function () {
|
|
81
|
-
onUploadComplete && onUploadComplete(__chunk_1.__assign(__chunk_1.__assign({}, fileUpload), { progress: 1 }));
|
|
66
|
+
handleUploadProgress = function (progressEvent) {
|
|
67
|
+
onUploadProgress &&
|
|
68
|
+
onUploadProgress(__chunk_1.__assign(__chunk_1.__assign({}, fileUpload), { progress: progressEvent.loaded / progressEvent.total }));
|
|
69
|
+
};
|
|
70
|
+
handleUploadComplete = function () {
|
|
71
|
+
onUploadComplete === null || onUploadComplete === void 0 ? void 0 : onUploadComplete(__chunk_1.__assign(__chunk_1.__assign({}, fileUpload), { progress: 1 }));
|
|
72
|
+
};
|
|
73
|
+
axiosConfig = createAxiosConfig({
|
|
74
|
+
url: url,
|
|
75
|
+
httpMethod: httpMethod,
|
|
76
|
+
fields: fields,
|
|
77
|
+
file: file,
|
|
78
|
+
handleUploadProgress: handleUploadProgress,
|
|
82
79
|
});
|
|
80
|
+
axios.request(axiosConfig).then(handleUploadComplete);
|
|
83
81
|
return [2 /*return*/];
|
|
84
82
|
}
|
|
85
83
|
});
|
|
86
84
|
});
|
|
87
85
|
}
|
|
88
86
|
}
|
|
87
|
+
function createAxiosConfig(_a) {
|
|
88
|
+
var url = _a.url, _b = _a.httpMethod, httpMethod = _b === void 0 ? "POST" : _b, _c = _a.fields, fields = _c === void 0 ? {} : _c, file = _a.file, handleUploadProgress = _a.handleUploadProgress;
|
|
89
|
+
var data;
|
|
90
|
+
var headers;
|
|
91
|
+
if (httpMethod === "POST") {
|
|
92
|
+
var formData_1 = new FormData();
|
|
93
|
+
Object.entries(fields).forEach(function (_a) {
|
|
94
|
+
var _b = __chunk_1.__read(_a, 2), field = _b[0], value = _b[1];
|
|
95
|
+
return formData_1.append(field, value);
|
|
96
|
+
});
|
|
97
|
+
formData_1.append("file", file);
|
|
98
|
+
data = formData_1;
|
|
99
|
+
headers = { "X-Requested-With": "XMLHttpRequest" };
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
data = file;
|
|
103
|
+
headers = fields;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
method: httpMethod,
|
|
107
|
+
url: url,
|
|
108
|
+
headers: headers,
|
|
109
|
+
data: data,
|
|
110
|
+
onUploadProgress: handleUploadProgress,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
89
113
|
function getLabels(providedButtonLabel, multiple, allowedTypes) {
|
|
90
114
|
var buttonLabel = multiple ? "Upload Files" : "Upload File";
|
|
91
115
|
var hintText = multiple
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.84.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"> 1%",
|
|
86
86
|
"IE 10"
|
|
87
87
|
],
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "6fe2d488b07f4404331479c697cf67c955e6365f"
|
|
89
89
|
}
|