ywana-core8 0.0.30 → 0.0.35
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/dist/index.cjs +2 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +2 -6
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +2 -6
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/domain/TablePage.js +2 -12
- package/src/upload/UploadArea.js +18 -0
- package/src/upload/uploader.css +1 -0
- package/src/upload/uploader.js +68 -51
package/package.json
CHANGED
package/src/domain/TablePage.js
CHANGED
@@ -369,21 +369,13 @@ const TableAPI = (url) => {
|
|
369
369
|
all(filters) {
|
370
370
|
let queryParams = "?"
|
371
371
|
if (filters) {
|
372
|
-
|
373
|
-
console.log('filters', filters)
|
374
|
-
|
375
372
|
const filterQuery = Object.keys(filters).reduce((query, key) => {
|
376
|
-
|
377
373
|
const value = filters[key]
|
378
|
-
console.log(value)
|
379
|
-
|
380
374
|
if (typeof (value) === 'boolean') {
|
381
375
|
return query.concat(`${key}=${value}&`)
|
382
|
-
|
383
376
|
} else if (Array.isArray(value)) {
|
384
|
-
const param = value.length === 0 ? '
|
385
|
-
param.concat(`${key}=${item}&`)
|
386
|
-
console.log(item, param)
|
377
|
+
const param = value.length === 0 ? '' : value.reduce((param,item) => {
|
378
|
+
param = param.concat(`${key}=${item}&`)
|
387
379
|
return param
|
388
380
|
}, "")
|
389
381
|
console.log(param)
|
@@ -392,8 +384,6 @@ const TableAPI = (url) => {
|
|
392
384
|
return query.concat(`${key}=%${filters[key]}%&`)
|
393
385
|
}
|
394
386
|
}, "")
|
395
|
-
|
396
|
-
console.log('filterQuery')
|
397
387
|
queryParams = queryParams.concat(filterQuery)
|
398
388
|
}
|
399
389
|
return http.GET(url + queryParams)
|
package/src/upload/UploadArea.js
CHANGED
@@ -59,4 +59,22 @@ const UploadIcon = ({ resumable }) => {
|
|
59
59
|
<Icon icon="folder_open" clickable/>
|
60
60
|
</div>
|
61
61
|
)
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Upload Button
|
66
|
+
*/
|
67
|
+
export function UploadButton({ resumable, icon="file_upload", label="Upload"}) {
|
68
|
+
|
69
|
+
const buttonElement = useRef();
|
70
|
+
|
71
|
+
useEffect(() => {
|
72
|
+
if (resumable && buttonElement) resumable.assignBrowse(buttonElement.current);
|
73
|
+
}, []);
|
74
|
+
|
75
|
+
return (
|
76
|
+
<div className="upload-button" ref={buttonElement}>
|
77
|
+
<Button icon={icon} label={label} outlined/>
|
78
|
+
</div>
|
79
|
+
)
|
62
80
|
}
|
package/src/upload/uploader.css
CHANGED
package/src/upload/uploader.js
CHANGED
@@ -1,68 +1,85 @@
|
|
1
1
|
import React, { useState, useMemo } from 'react'
|
2
2
|
import ResumableJS from 'resumablejs'
|
3
|
-
import { UploadArea } from
|
3
|
+
import { UploadArea } from "./UploadArea";
|
4
|
+
import { UploadFile } from "./UploadFile";
|
4
5
|
import './uploader.css'
|
5
6
|
|
7
|
+
const STATES = {
|
8
|
+
IDLE: 0, RUNNING: 1, SUCCESS: 2, ERROR': 3, COMPLETED: 4 }
|
6
9
|
/**
|
7
10
|
* Uploader
|
8
11
|
*/
|
9
|
-
export const Uploader = ({ label, target, accept, className, onSuccess, onError, onComplete, errors = [] }) => {
|
12
|
+
export const Uploader = ({ label, target, accept, simultaneousUploads = 1, className, onSuccess, onError, onComplete, errors = [] }) => {
|
10
13
|
|
11
|
-
const STATES = { 'IDLE': 0, 'RUNNING': 1, 'SUCCESS': 2, 'ERROR': 3, 'COMPLETED': 4 }
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
const resumable = useMemo(() => {
|
16
|
+
const config = {
|
17
|
+
target: target,
|
18
|
+
chunkSize: 1 * 1024 * 1024,
|
19
|
+
simultaneousUploads,
|
20
|
+
testChunks: false,
|
21
|
+
throttleProgressCallbacks: 1,
|
22
|
+
fileType: accept
|
23
|
+
}
|
24
|
+
const resumable = new ResumableJS(config)
|
25
|
+
resumable.on('fileAdded', onFileAdded)
|
26
|
+
resumable.on('fileProgress', onFileProgress)
|
27
|
+
resumable.on('fileSuccess', onFileSuccess)
|
28
|
+
resumable.on('fileError', onFileError)
|
29
|
+
resumable.on('complete', onAllComplete)
|
30
|
+
return resumable
|
31
|
+
}, [])
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
const [progress, setProgress] = useState(0)
|
34
|
+
const [state, setState] = useState(STATES.IDLE)
|
35
|
+
const [error, setError] = useState()
|
36
|
+
const [files, setFiles] = useState([])
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
function onFileAdded(file) {
|
39
|
+
files.push(file)
|
40
|
+
setFiles(files)
|
41
|
+
setState(STATES.RUNNING)
|
42
|
+
resumable.upload()
|
43
|
+
}
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
function onFileProgress(file) {
|
46
|
+
const progress = file.progress()
|
47
|
+
setProgress(progress)
|
48
|
+
if (onProgress) onProgress(files);
|
49
|
+
}
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
function onFileSuccess(file, message) {
|
52
|
+
setState(STATES.SUCCESS)
|
53
|
+
if (onSuccess) onSuccess(file, message)
|
54
|
+
}
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
function onFileError(file, message) {
|
57
|
+
setError(message)
|
58
|
+
setState(STATES.ERROR)
|
59
|
+
if (onError) onError(file, message)
|
60
|
+
}
|
61
|
+
|
62
|
+
function onAllComplete() {
|
63
|
+
setState(STATES.IDLE)
|
64
|
+
if (onComplete) onComplete(files)
|
65
|
+
}
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
|
67
|
+
return (
|
68
|
+
<div className={`uploader ${className}`}>
|
69
|
+
{state === STATES.IDLE ? <UploadArea resumable={resumable} state={state} label={label} error={error} progress={progress} /> : null}
|
70
|
+
{state === STATES.RUNNING || STATES.SUCCESS || STATES.ERROR ? <UploadProgress files={files} errors={errors} /> : null}
|
71
|
+
</div>
|
72
|
+
)
|
61
73
|
}
|
62
74
|
|
63
|
-
|
64
|
-
|
65
|
-
<
|
66
|
-
|
67
|
-
|
68
|
-
|
75
|
+
const UploadProgress = ({ files = [], errors }) => {
|
76
|
+
return (
|
77
|
+
<div>
|
78
|
+
{files.map((file) => {
|
79
|
+
const error2 = errors.some((e) => e === file.fileName) ? "Fichero Mal Nombrado" : "";
|
80
|
+
const progress = 1
|
81
|
+
return <UploadFile file={file} state={STATES.RUNNING} progress={file.progress()} />;
|
82
|
+
})}
|
83
|
+
</div>
|
84
|
+
);
|
85
|
+
};
|