@balena/ui-shared-components 14.1.0-build-secure-boot-backup-d2d812bb2ed113d3a916cd9b05a3177eaa736d7d-1 → 14.1.0-build-secure-boot-backup-e7a2ae3ae27da0dd2adfb143b8f73aced69adf58-1
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.
|
@@ -2,7 +2,7 @@ import { createElement as _createElement } from "react";
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useDropzone } from 'react-dropzone';
|
|
4
4
|
import { Typography, InputLabel, Stack, Link, LinearProgress, Box, useMediaQuery, useTheme, } from '@mui/material';
|
|
5
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
5
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
6
|
import { IconButtonWithTracking, Tooltip } from '../../..';
|
|
7
7
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
8
8
|
import { faCircleExclamation, faFile, faFileImage, faTrash, faUpload, } from '@fortawesome/free-solid-svg-icons';
|
|
@@ -64,6 +64,7 @@ const getErrorMessage = (code, message, maxSize) => {
|
|
|
64
64
|
};
|
|
65
65
|
export const FileWidget = ({ onChange, multiple, schema, uiSchema, }) => {
|
|
66
66
|
const [files, setFiles] = useState([]);
|
|
67
|
+
const [filesWithDataUrl, setFilesWithDataUrl] = useState([]);
|
|
67
68
|
const [errorFiles, setErrorFiles] = useState([]);
|
|
68
69
|
const theme = useTheme();
|
|
69
70
|
const mobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
@@ -102,16 +103,13 @@ export const FileWidget = ({ onChange, multiple, schema, uiSchema, }) => {
|
|
|
102
103
|
const base64Data = reader.result.split(',')[1];
|
|
103
104
|
file.base64Data = base64Data;
|
|
104
105
|
const dataUrl = `data:${file.type};name=${file.name};base64,${base64Data}`;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
dataUrl,
|
|
113
|
-
uploadedFile: file,
|
|
114
|
-
});
|
|
106
|
+
setFilesWithDataUrl((prev) => [
|
|
107
|
+
...prev,
|
|
108
|
+
{
|
|
109
|
+
dataUrl,
|
|
110
|
+
uploadedFile: file,
|
|
111
|
+
},
|
|
112
|
+
]);
|
|
115
113
|
};
|
|
116
114
|
reader.readAsDataURL(file);
|
|
117
115
|
});
|
|
@@ -122,7 +120,21 @@ export const FileWidget = ({ onChange, multiple, schema, uiSchema, }) => {
|
|
|
122
120
|
setFiles(acceptedFiles.length ? [acceptedFiles[0]] : []);
|
|
123
121
|
}
|
|
124
122
|
setErrorFiles(rejectedFiles);
|
|
125
|
-
}, [
|
|
123
|
+
}, [setFiles, files, multiple]);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (filesWithDataUrl.length && filesWithDataUrl.length === files.length) {
|
|
126
|
+
// NOTE: JSONSchema array data-url does not expect objects but only strings[]
|
|
127
|
+
// see: https://github.com/rjsf-team/react-jsonschema-form/blob/297dac059fdf64fd1453bebb8366f0602c722f90/packages/utils/src/schema/isFilesArray.ts#L24
|
|
128
|
+
// Check if possibile to always pass only strings (dataUrls) and not objects when not multiple.
|
|
129
|
+
if (multiple) {
|
|
130
|
+
onChange(filesWithDataUrl.map((fileWithDataUrl) => fileWithDataUrl.dataUrl));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// If not multiple, the schema accept an object and we can pass it directly
|
|
134
|
+
// if not necessary, in a major release we can change it to pass only the dataUrl string and unify the behaviour
|
|
135
|
+
onChange(filesWithDataUrl[0]);
|
|
136
|
+
}
|
|
137
|
+
}, [files, filesWithDataUrl, multiple, onChange]);
|
|
126
138
|
const removeFile = useCallback((index) => {
|
|
127
139
|
const newFiles = [...files];
|
|
128
140
|
newFiles.splice(index, 1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/ui-shared-components",
|
|
3
|
-
"version": "14.1.0-build-secure-boot-backup-
|
|
3
|
+
"version": "14.1.0-build-secure-boot-backup-e7a2ae3ae27da0dd2adfb143b8f73aced69adf58-1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
},
|
|
134
134
|
"homepage": "https://github.com/balena-io/ui-shared-components#readme",
|
|
135
135
|
"versionist": {
|
|
136
|
-
"publishedAt": "2025-10-
|
|
136
|
+
"publishedAt": "2025-10-06T15:03:01.816Z"
|
|
137
137
|
},
|
|
138
138
|
"overrides": {
|
|
139
139
|
"storybook": "$storybook"
|