cloudmr-ux 0.0.3 → 1.0.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.
Files changed (67) hide show
  1. package/README.md +24 -16
  2. package/dist/index.975ef6c8.js +75418 -0
  3. package/dist/index.975ef6c8.js.map +1 -0
  4. package/dist/index.css +140 -14
  5. package/dist/index.d.ts +58 -0
  6. package/dist/index.db9ed22c.css +171 -0
  7. package/dist/index.db9ed22c.css.map +1 -0
  8. package/dist/index.html +13 -0
  9. package/dist/index.js +170 -141
  10. package/dist/index.mjs +157 -0
  11. package/package.json +39 -99
  12. package/dist/index.js.map +0 -1
  13. package/dist/index.modern.js +0 -147
  14. package/dist/index.modern.js.map +0 -1
  15. package/src/.eslintrc +0 -5
  16. package/src/common/components/Cmr-components/avatar/Avatar.scss +0 -0
  17. package/src/common/components/Cmr-components/avatar/Avatar.tsx +0 -25
  18. package/src/common/components/Cmr-components/button/Button.scss +0 -0
  19. package/src/common/components/Cmr-components/button/Button.tsx +0 -14
  20. package/src/common/components/Cmr-components/checkbox/Checkbox.scss +0 -11
  21. package/src/common/components/Cmr-components/checkbox/Checkbox.tsx +0 -29
  22. package/src/common/components/Cmr-components/collapse/Collapse.scss +0 -3
  23. package/src/common/components/Cmr-components/collapse/Collapse.tsx +0 -75
  24. package/src/common/components/Cmr-components/dialogue/Confirmation.tsx +0 -48
  25. package/src/common/components/Cmr-components/dialogue/DeletionDialog.tsx +0 -61
  26. package/src/common/components/Cmr-components/dialogue/EditConfirmation.tsx +0 -72
  27. package/src/common/components/Cmr-components/double-slider/DualSlider.tsx +0 -198
  28. package/src/common/components/Cmr-components/double-slider/InvertibleDualSlider.tsx +0 -224
  29. package/src/common/components/Cmr-components/dropdown/Dropdown.scss +0 -36
  30. package/src/common/components/Cmr-components/dropdown/Dropdown.tsx +0 -83
  31. package/src/common/components/Cmr-components/gui-slider/ControlledSlider.tsx +0 -139
  32. package/src/common/components/Cmr-components/gui-slider/Slider.tsx +0 -170
  33. package/src/common/components/Cmr-components/header/Header.scss +0 -20
  34. package/src/common/components/Cmr-components/header/Header.tsx +0 -101
  35. package/src/common/components/Cmr-components/input/Input.scss +0 -0
  36. package/src/common/components/Cmr-components/input/Input.tsx +0 -39
  37. package/src/common/components/Cmr-components/input-number/InputNumber.scss +0 -0
  38. package/src/common/components/Cmr-components/input-number/InputNumber.tsx +0 -29
  39. package/src/common/components/Cmr-components/label/Label.scss +0 -13
  40. package/src/common/components/Cmr-components/label/Label.tsx +0 -20
  41. package/src/common/components/Cmr-components/option/Option.scss +0 -0
  42. package/src/common/components/Cmr-components/option/Option.tsx +0 -24
  43. package/src/common/components/Cmr-components/panel/Panel.scss +0 -0
  44. package/src/common/components/Cmr-components/panel/Panel.tsx +0 -54
  45. package/src/common/components/Cmr-components/progress/Progress.scss +0 -0
  46. package/src/common/components/Cmr-components/progress/Progress.tsx +0 -38
  47. package/src/common/components/Cmr-components/radio/Radio.scss +0 -0
  48. package/src/common/components/Cmr-components/radio/Radio.tsx +0 -23
  49. package/src/common/components/Cmr-components/radio-group/RadioGroup.scss +0 -0
  50. package/src/common/components/Cmr-components/radio-group/RadioGroup.tsx +0 -32
  51. package/src/common/components/Cmr-components/rename/edit.tsx +0 -94
  52. package/src/common/components/Cmr-components/select/Select.scss +0 -3
  53. package/src/common/components/Cmr-components/select/Select.tsx +0 -33
  54. package/src/common/components/Cmr-components/select-upload/SelectUpload.scss +0 -0
  55. package/src/common/components/Cmr-components/select-upload/SelectUpload.tsx +0 -133
  56. package/src/common/components/Cmr-components/slider/Slider.scss +0 -0
  57. package/src/common/components/Cmr-components/slider/Slider.tsx +0 -66
  58. package/src/common/components/Cmr-components/spin/Spin.scss +0 -0
  59. package/src/common/components/Cmr-components/spin/Spin.tsx +0 -31
  60. package/src/common/components/Cmr-components/tooltip/Tooltip.scss +0 -0
  61. package/src/common/components/Cmr-components/tooltip/Tooltip.tsx +0 -50
  62. package/src/common/components/Cmr-components/upload/Upload.scss +0 -5
  63. package/src/common/components/Cmr-components/upload/Upload.tsx +0 -188
  64. package/src/common/components/Cmr-components/upload/UploadWindow.tsx +0 -355
  65. package/src/index.js +0 -8
  66. package/src/index.test.js +0 -7
  67. package/src/styles.module.css +0 -9
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import './Radio.scss';
3
- import { Radio } from 'antd';
4
-
5
- interface CmrRadioProps {
6
- checked?: boolean;
7
- defaultChecked?: boolean;
8
- disabled?: boolean;
9
- value?: any;
10
- children?: any;
11
- }
12
-
13
- const CmrRadio = (props: CmrRadioProps) => {
14
- const { checked, defaultChecked, disabled, value, children, ...rest } = props;
15
-
16
- return (
17
- <Radio checked={checked} defaultChecked={defaultChecked} disabled={disabled} value={value} {...rest}>
18
- {children}
19
- </Radio>
20
- );
21
- };
22
-
23
- export default CmrRadio;
@@ -1,32 +0,0 @@
1
- import React from 'react';
2
- import './RadioGroup.scss';
3
- import { Radio } from 'antd';
4
- import { RadioChangeEvent } from 'antd/lib/radio/interface';
5
-
6
- interface CmrRadioGroupProps {
7
- defaultValue?: any;
8
- disabled?: boolean;
9
- name?: string;
10
- value?: any;
11
- onChange?: (e: RadioChangeEvent) => void;
12
- children?: React.ReactNode;
13
- }
14
-
15
- const CmrRadioGroup = (props: CmrRadioGroupProps) => {
16
- const { defaultValue, disabled, name, value, onChange, children, ...rest } = props;
17
-
18
- return (
19
- <Radio.Group
20
- defaultValue={defaultValue}
21
- disabled={disabled}
22
- name={name}
23
- value={value}
24
- onChange={onChange}
25
- {...rest}
26
- >
27
- {children}
28
- </Radio.Group>
29
- );
30
- };
31
-
32
- export default CmrRadioGroup;
@@ -1,94 +0,0 @@
1
- import * as React from 'react';
2
- import Button from '@mui/material/Button';
3
- import TextField from '@mui/material/TextField';
4
- import Dialog from '@mui/material/Dialog';
5
- import DialogActions from '@mui/material/DialogActions';
6
- import DialogContent from '@mui/material/DialogContent';
7
- import DialogContentText from '@mui/material/DialogContentText';
8
- import DialogTitle from '@mui/material/DialogTitle';
9
- import CmrButton from "../button/Button";
10
- import {useEffect} from "react";
11
-
12
- export default function CmrNameDialog(props: {originalName: string; renamingCallback:(alias:string)=>Promise<boolean>, open:boolean, setOpen:(open:boolean)=>void}) {
13
- let {originalName,open, setOpen} = props;
14
- const [helperText, setHelperText] = React.useState('');
15
- const [text, setText] = React.useState(originalName);
16
- const [error, setError] = React.useState(false);
17
-
18
- const renamingCallback = props.renamingCallback;
19
-
20
- const handleClose = () => {
21
- setOpen(false);
22
- };
23
-
24
- useEffect(() => {
25
- checkError(originalName);
26
- }, [originalName]);
27
-
28
- const handleConfirm = async () => {
29
- // if(!error)
30
- if(await renamingCallback(text))
31
- handleClose();
32
- };
33
-
34
- const handleTextFieldChange=(e: { target: { value: string; }; })=>{
35
- setText( e.target.value);
36
- checkError(e.target.value);
37
- }
38
- const checkError=(text: string)=>{
39
- const fileNameRegex = /^[a-zA-Z0-9_\-]+\.[a-zA-Z]{1,5}$/;
40
- let newExtension = text.split('.').pop();
41
- let orgExtension = (originalName.indexOf('.')>=0)? originalName.split('.').pop(): '?';
42
- if(!fileNameRegex.test(text)){
43
- setError(true);
44
- if(text.indexOf('.')<0){
45
- setHelperText('Invalid file name, needs a valid extension.');
46
- }else{
47
- setHelperText('Invalid file name, please check.');
48
- }
49
- }else if(newExtension!==orgExtension){
50
- setHelperText(`You are modifying your file extension from .${orgExtension} to .${newExtension}.`);
51
- setError(false);
52
- }else{
53
- setError(false);
54
- setHelperText('');
55
- }
56
- }
57
-
58
- return (
59
- <div>
60
- <Dialog open={open} onClose={handleClose} fullWidth
61
- maxWidth="xs">
62
- <DialogTitle>
63
- Renaming file {originalName} to:
64
- </DialogTitle>
65
- <DialogContent>
66
- {/*<DialogContentText>*/}
67
- {/* Renaming file {originalName} to:*/}
68
- {/*</DialogContentText>*/}
69
-
70
- <TextField
71
- autoFocus
72
- margin="dense"
73
- id="name"
74
- // type="file"
75
- defaultValue = {originalName}
76
- onFocus={event => {
77
- event.target.select();
78
- }}
79
- fullWidth
80
- inputProps={{style: {fontSize: "16pt"}}}
81
- variant="standard"
82
- onChange={handleTextFieldChange}
83
- error={error}
84
- helperText={helperText}
85
- />
86
- </DialogContent>
87
- <DialogActions>
88
- <CmrButton variant={"outlined"} color={'inherit'} sx={{color:'#333'}} onClick={handleClose}>Cancel</CmrButton>
89
- <CmrButton variant={"contained"} color={'primary'} onClick={handleConfirm}>Confirm</CmrButton>
90
- </DialogActions>
91
- </Dialog>
92
- </div>
93
- );
94
- }
@@ -1,3 +0,0 @@
1
- .ant-select {
2
- width: 120px;
3
- }
@@ -1,33 +0,0 @@
1
- import React from 'react';
2
- import './Select.scss';
3
- import { Select } from 'antd';
4
-
5
- interface CmrSelectProps {
6
- id?: string;
7
- className?: string;
8
- value?: Array<string | number> | string | number;
9
- defaultValue?: Array<string | number> | string | number;
10
- disabled?: boolean;
11
- onChange?: (value: any) => void;
12
- children?: any;
13
- }
14
-
15
- const CmrSelect = (props: CmrSelectProps) => {
16
- const { id, className, value, defaultValue, disabled, onChange, children, ...rest } = props;
17
-
18
- return (
19
- <Select
20
- id={id}
21
- className={className}
22
- value={value}
23
- defaultValue={defaultValue}
24
- disabled={disabled}
25
- onChange={onChange}
26
- {...rest}
27
- >
28
- {children}
29
- </Select>
30
- );
31
- };
32
-
33
- export default CmrSelect;
@@ -1,133 +0,0 @@
1
- import React, {Fragment, useState} from "react";
2
- import CMRUpload, {CMRUploadProps, LambdaFile} from '../upload/Upload';
3
- import {Alert, AlertTitle, Button, Collapse, InputLabel, MenuItem} from "@mui/material";
4
- import Select, {SelectChangeEvent} from "@mui/material/Select";
5
- import Dialog from "@mui/material/Dialog";
6
- import DialogTitle from "@mui/material/DialogTitle";
7
- import DialogContent from "@mui/material/DialogContent";
8
- import DialogContentText from "@mui/material/DialogContentText";
9
- import DialogActions from "@mui/material/DialogActions";
10
- import CmrTooltip from "../tooltip/Tooltip";
11
- import Box from "@mui/material/Box";
12
- import {uploadData} from "../../../../features/data/dataActionCreation";
13
- import {useAppDispatch, useAppSelector} from "../../../../features/hooks";
14
- import {AxiosResponse} from "axios";
15
-
16
- interface CMRSelectUploadProps extends CMRUploadProps{
17
- /**
18
- * A selection of currently uploaded files
19
- */
20
- fileSelection: UploadedFile[];
21
- onSelected: (file?: UploadedFile)=>void;
22
- chosenFile?: string;
23
- buttonText?: string;
24
- /**
25
- * Enforces the extension of selected files
26
- */
27
- fileExtension?:string;
28
- }
29
-
30
- interface UploadedFile {
31
- id: number;
32
- fileName: string;
33
- link: string;
34
- md5?: string;
35
- size: string;
36
- status: string;
37
- createdAt: string;
38
- updatedAt: string;
39
- database: string;
40
- location: string;
41
- }
42
-
43
- /**
44
- * Select from a set of uploaded files or upload new
45
- */
46
- const CMRSelectUpload = (props: CMRSelectUploadProps) => {
47
-
48
- let [open, setOpen] = React.useState(false);
49
- let [fileIndex, selectFileIndex] = React.useState(-1);
50
- let [uploading, setUploading] = React.useState(false);
51
- const [progress, setProgress] = React.useState(0);
52
- const handleClickOpen = () => {
53
- selectFileIndex(-1);
54
- setOpen(true);
55
- };
56
-
57
- const handleClose = () => {
58
- setOpen(false);
59
- };
60
-
61
- const handleChange = (event: SelectChangeEvent<number>) => {
62
- //@ts-ignore
63
- selectFileIndex(event.target.value);
64
- };
65
-
66
- const onSet = ()=>{
67
- props.onSelected(props.fileSelection[fileIndex]);
68
- setOpen(false);
69
- }
70
- const selectionDialog = <Dialog open={open} onClose={handleClose}>
71
- <DialogTitle>Upload or select</DialogTitle>
72
- <DialogContent sx={{width: 520}}>
73
- <DialogContentText sx={{pl:1, pr:1, pb:0}}>
74
- {(uploading)?"Please wait for the upload to finish.":"Upload a new file or select from previously uploaded files:"}
75
- </DialogContentText>
76
- <DialogContent sx={{p:1}}>
77
- <Select
78
- value={fileIndex}
79
- onChange={handleChange}
80
- disabled={uploading}
81
- inputProps={{ 'aria-label': 'Without label' }}
82
- sx={{width: '100%'}}
83
- >
84
- <MenuItem value={-1}>
85
- <em>Select or upload a new file to proceed</em>
86
- </MenuItem>
87
- {((props.fileSelection!=undefined? props.fileSelection: [])).map((option,index) => (
88
- <MenuItem key={index} value={index}>
89
- {option.fileName}
90
- </MenuItem>
91
- ))}
92
- </Select>
93
- </DialogContent>
94
- <Box sx={{pt:2, justifyContent:'center',display:'flex', padding:'8px'}}>
95
- {(!uploading)&&<Button fullWidth sx={{marginRight:'8px'}} variant="contained" color="success" onClick={onSet}>
96
- Select
97
- </Button>}
98
- {fileIndex==-1&& <CMRUpload {...props} color="info" fullWidth onUploaded={(res, file)=>{
99
- console.log("calling Setup level on uploaded");
100
- console.log(props.onUploaded);
101
- selectFileIndex(props.fileSelection.length);
102
- props.onUploaded(res, file);
103
- setOpen(false);
104
- }} fileExtension = {props.fileExtension}
105
- uploadHandler={props.uploadHandler}
106
- uploadStarted={()=>{
107
- setUploading(true);
108
- props.onSelected(undefined);
109
- }}
110
- uploadProgressed={(progress)=>{
111
- setOpen(false);
112
- setProgress(progress);
113
- }}
114
- uploadEnded={()=>setUploading(false)}
115
- ></CMRUpload>}
116
- <Button fullWidth variant="outlined" color="inherit" sx={{color:'#333', marginLeft:'8px'}} onClick={handleClose}> Cancel</Button>
117
- </Box>
118
- </DialogContent>
119
- </Dialog>;
120
- return <Fragment>
121
- {uploading?<Button variant={"contained"} style={{...props.style, textTransform:'none'}} sx={{overflowWrap:'inherit'}} color={'primary'} disabled={uploading}>
122
- Uploading {progress}%
123
- </Button>:<Button variant={(props.chosenFile==undefined)?"contained":"outlined"} color="info" onClick={handleClickOpen} sx={{marginRight:'10pt'}}
124
- style={{...props.style, textTransform:'none'}}>
125
- {(props.chosenFile==undefined)?
126
- (props.buttonText?props.buttonText:"Choose")
127
- :props.chosenFile}
128
- </Button>}
129
- {selectionDialog}
130
- </Fragment>;
131
- };
132
-
133
- export default CMRSelectUpload;
@@ -1,66 +0,0 @@
1
- import React from 'react';
2
- import './Slider.scss';
3
- import { Slider } from 'antd';
4
- import { SliderMarks } from 'antd/lib/slider';
5
-
6
- interface CmrSliderProps {
7
- reverse?: boolean;
8
- defaultValue?: number;
9
- disabled?: boolean;
10
- dots?: boolean;
11
- included?: boolean;
12
- max?: number;
13
- min?: number;
14
- range?: false;
15
- step?: null | number;
16
- marks?: SliderMarks;
17
- vertical?: boolean;
18
- tipFormatter?: null | ((value?: number) => React.ReactNode);
19
- value?: number;
20
- onChange?: (value: number) => void;
21
- onAfterChange?: (value: number) => void;
22
- }
23
-
24
- const CmrSlider = (props: CmrSliderProps) => {
25
- const {
26
- reverse,
27
- defaultValue,
28
- disabled,
29
- dots,
30
- included,
31
- max,
32
- min,
33
- range,
34
- step,
35
- marks,
36
- vertical,
37
- tipFormatter,
38
- value,
39
- onChange,
40
- onAfterChange,
41
- ...rest
42
- } = props;
43
-
44
- return (
45
- <Slider
46
- reverse={reverse}
47
- defaultValue={defaultValue}
48
- disabled={disabled}
49
- dots={dots}
50
- included={included}
51
- max={max}
52
- min={min}
53
- range={range}
54
- step={step}
55
- marks={marks}
56
- vertical={vertical}
57
- tipFormatter={tipFormatter}
58
- value={value}
59
- onChange={onChange}
60
- onAfterChange={onAfterChange}
61
- {...rest}
62
- />
63
- );
64
- };
65
-
66
- export default CmrSlider;
@@ -1,31 +0,0 @@
1
- import React from 'react';
2
- import './Spin.scss';
3
- import { Spin } from 'antd';
4
- import { SpinIndicator, SpinSize } from 'antd/lib/spin';
5
-
6
- interface CmrSpinProps {
7
- delay?: number;
8
- indicator?: SpinIndicator;
9
- size?: SpinSize;
10
- spinning?: boolean;
11
- tip?: string;
12
- wrapperClassName?: string;
13
- }
14
-
15
- const CmrSpin = (props: CmrSpinProps) => {
16
- const { delay, indicator, size, spinning, tip, wrapperClassName, ...rest } = props;
17
-
18
- return (
19
- <Spin
20
- delay={delay}
21
- indicator={indicator}
22
- size={size}
23
- spinning={spinning}
24
- tip={tip}
25
- wrapperClassName={wrapperClassName}
26
- {...rest}
27
- />
28
- );
29
- };
30
-
31
- export default CmrSpin;
@@ -1,50 +0,0 @@
1
- import React from 'react';
2
- import './Tooltip.scss';
3
- import { Tooltip } from 'antd';
4
- import { TooltipPlacement } from 'antd/lib/tooltip';
5
-
6
- interface CmrTooltipProps {
7
- arrowPointAtCenter?: boolean;
8
- autoAdjustOverflow?: boolean;
9
- color?: string;
10
- defaultVisible?: boolean;
11
- mouseEnterDelay?: number;
12
- mouseLeaveDelay?: number;
13
- overlayClassName?: string;
14
- placement?: TooltipPlacement;
15
- visible?: boolean;
16
- title: React.ReactNode;
17
- overlay?: React.ReactNode;
18
- }
19
-
20
- const CmrTooltip = (props: CmrTooltipProps) => {
21
- const {
22
- arrowPointAtCenter,
23
- autoAdjustOverflow,
24
- color,
25
- defaultVisible,
26
- mouseEnterDelay,
27
- mouseLeaveDelay,
28
- overlayClassName,
29
- placement,
30
- visible,
31
- ...rest
32
- } = props;
33
-
34
- return (
35
- <Tooltip
36
- arrowPointAtCenter={arrowPointAtCenter}
37
- autoAdjustOverflow={autoAdjustOverflow}
38
- color={color}
39
- defaultVisible={defaultVisible}
40
- mouseEnterDelay={mouseEnterDelay}
41
- mouseLeaveDelay={mouseLeaveDelay}
42
- overlayClassName={overlayClassName}
43
- placement={placement}
44
- visible={visible}
45
- {...rest}
46
- />
47
- );
48
- };
49
-
50
- export default CmrTooltip;
@@ -1,5 +0,0 @@
1
- .btn-info {
2
- color: #ffffff; /* Change it to your preferred color */
3
- --bs-btn-hover-color: #ffffff;
4
- --bs-btn-color: #ffffff;
5
- }
@@ -1,188 +0,0 @@
1
- import React, {useState} from 'react';
2
- import './Upload.scss';
3
- import {Box, Button, SxProps, Theme} from '@mui/material';
4
- import UploadWindow from "./UploadWindow";
5
- import axios, {AxiosRequestConfig, AxiosResponse} from "axios";
6
-
7
- export interface LambdaFile {
8
- "filename": string;
9
- "filetype": string;
10
- "filesize": string;
11
- "filemd5": string;
12
- "file": File;
13
- }
14
- /**
15
- * Consists of general settings for upload component
16
- * functionalities and call back methods evoked
17
- * for specific interactions
18
- */
19
- interface CMRUploadProps extends React.HTMLAttributes<HTMLDivElement>{
20
- //Determines if the upload buttons should retain the uploaded
21
- //file after upload, or if it should refresh for a new session
22
- retains?:boolean;
23
- maxCount: number;
24
- onRemove?:(removedFile: File)=>void;
25
- /**
26
- * Allows access to file content prior to uploading.
27
- * If returned value from the method is false,
28
- * prevents the file upload process. Called before
29
- * create payload.
30
- * @param file
31
- */
32
- beforeUpload?: (file:File)=>Promise<boolean>;
33
- /**
34
- * This or uploadHandler must be specified
35
- * @param file
36
- * @param fileAlias
37
- * @param fileDatabase
38
- */
39
- createPayload?: (file: File,fileAlias:string, fileDatabase: string)=>
40
- (Promise<{destination: string, lambdaFile:LambdaFile, file:File, config: AxiosRequestConfig}|undefined>);
41
- onUploadProgressUpdate?:(loaded: number, total: number)=>void|undefined;
42
- onUploaded: (res: AxiosResponse, file: File)=>Promise<void>|void;
43
- sx?: SxProps<Theme>|undefined;
44
- rest?: any;
45
- fileExtension?: string;
46
- uploadStarted?:()=>void;
47
- uploadEnded?:()=>void;
48
- uploadFailed?:()=>void;
49
- uploadProgressed?:(progress:number)=>void;
50
- /**
51
- * Override this to replace the default behavior of uploading
52
- * @param file
53
- * @param fileAlias
54
- * @param fileDatabase
55
- * @param onProgress
56
- * @param onUploaded
57
- */
58
- uploadHandler?:(file:File, fileAlias:string, fileDatabase:string,
59
- onProgress?:(progress:number)=>void,
60
- onUploaded?:(res:AxiosResponse,file:File)=>void)=>Promise<number>;
61
- fullWidth?: boolean;
62
- style?: any;
63
- /**
64
- * Displays upload button instead of uploaded file after upload
65
- * if set to reusable
66
- */
67
- reusable?: boolean;
68
- uploadButtonName?:string;
69
- /**
70
- * Processes the uploaded file before performing the upload;
71
- * @return file/undefined/statuscode undefined to fail the upload, return File
72
- * to pass the processed file, return number to indicate error code
73
- * and return to upload window.
74
- * @param file
75
- */
76
- preprocess?:(file:File)=>Promise<File|undefined|number>;
77
- }
78
-
79
-
80
- const CmrUpload = (props: CMRUploadProps) => {
81
-
82
- let [open, setOpen] = useState(false);
83
- /**
84
- * Life cycle representing the current status of the upload
85
- * process.
86
- */
87
- let [uploading, setUploading] = useState(false);
88
- let [progress, setProgress] = useState(0);
89
- let [uploadedFile, setUploadedFile] = useState<string|undefined>(undefined);
90
-
91
- const upload = async (file: File, fileAlias:string, fileDatabase: string)=>{
92
- setUploading(true);
93
- const onProgress = (progress:number)=>{
94
- let percentage = (progress* 99);
95
- props.uploadProgressed&&props.uploadProgressed(+percentage.toFixed(2));
96
- setProgress(+percentage.toFixed(2));
97
- }
98
- if(props.uploadStarted)
99
- props.uploadStarted();
100
- let status:any = 0;
101
- // try {
102
- if(props.beforeUpload!=undefined&&!await props.beforeUpload(file)){
103
- if(props.uploadEnded)
104
- props.uploadEnded();
105
- setUploading(false);
106
- return 200;
107
- }
108
- if(props.preprocess){
109
- let processed = await props.preprocess(file);
110
- if(processed==undefined)
111
- return failUpload();
112
- if(typeof processed =='number'){
113
- setUploading(false);
114
- return processed;
115
- }
116
- file = processed as File;
117
- }
118
- if(props.uploadHandler!=undefined){
119
- status = await props.uploadHandler(file,fileAlias,fileDatabase,onProgress,props.onUploaded);
120
- setUploadedFile(props.reusable?undefined:file.name);
121
- }else if(props.createPayload){
122
- let payload = await props.createPayload(file, fileAlias, fileDatabase);
123
- if(payload==undefined){
124
- return failUpload();
125
- }
126
- payload.config.onUploadProgress = (progressEvent) => {
127
- if(progressEvent.total==undefined)
128
- return;
129
- onProgress(progressEvent.loaded/progressEvent.total);
130
- };
131
- // console.log(payload.formData)
132
- const res = await axios.post(payload.destination, payload.lambdaFile, payload.config);
133
- status = res.status;
134
- if(status===200){
135
- // file.name = res.data.response.
136
- // await axios.post(res.data.upload_url, file)
137
- console.log(res.data);
138
- await axios.put(res.data.upload_url, payload.file, {
139
- headers: {
140
- 'Content-Type': payload.file.type
141
- }
142
- })
143
- await props.onUploaded(res,payload.file);
144
- setUploadedFile(props.reusable?undefined:payload.file.name);
145
- }
146
- }else{
147
- return failUpload();
148
- }
149
- if(props.uploadEnded)
150
- props.uploadEnded();
151
- setUploading(false);
152
- setProgress(0);
153
- // }
154
- return status;
155
- };
156
-
157
- function failUpload(){
158
- setUploading(false);
159
- setProgress(0);
160
- if(props.uploadFailed)
161
- return props.uploadFailed();
162
- return 0;
163
- }
164
-
165
- return (
166
- <React.Fragment>
167
- {(!uploading)?
168
-
169
- <Button fullWidth={props.fullWidth} style={props.style} variant={(uploadedFile==undefined)?"contained":"outlined"}
170
- onClick={()=>{
171
- setOpen(true);
172
- }}
173
- sx={props.sx}
174
- >
175
- {(uploadedFile==undefined)?(props.uploadButtonName?props.uploadButtonName:"Upload"):uploadedFile}
176
- </Button>
177
- :
178
- <Button fullWidth={props.fullWidth} style={props.style} variant={"contained"} sx={{overflowWrap:'inherit'}} color={'primary'} disabled>
179
- Uploading {progress}%
180
- </Button>}
181
- <UploadWindow open={open} setOpen={setOpen} upload={upload} fileExtension={props.fileExtension}
182
- template={{showFileName:true,showFileSize:true}}/>
183
- </React.Fragment>
184
- );
185
- };
186
-
187
- export type {CMRUploadProps};
188
- export default CmrUpload;