7
7
EuiPopover ,
8
8
EuiSpacer ,
9
9
EuiText ,
10
+ EuiTextColor ,
10
11
EuiToolTip ,
11
12
} from '@elastic/eui'
12
13
@@ -33,6 +34,9 @@ export interface Props {
33
34
onCancel : ( ) => void
34
35
}
35
36
37
+ const MAX_MB_FILE = 100
38
+ const MAX_FILE_SIZE = MAX_MB_FILE * 1024 * 1024
39
+
36
40
const BulkUpload = ( props : Props ) => {
37
41
const { onCancel } = props
38
42
const { id : instanceId } = useSelector ( connectedInstanceSelector )
@@ -41,6 +45,8 @@ const BulkUpload = (props: Props) => {
41
45
const { succeed, processed, failed } = useSelector ( bulkActionsUploadSummarySelector ) ?? { }
42
46
43
47
const [ files , setFiles ] = useState < Nullable < FileList > > ( null )
48
+ const [ isInvalid , setIsInvalid ] = useState < boolean > ( false )
49
+ const [ isSubmitDisabled , setIsSubmitDisabled ] = useState < boolean > ( true )
44
50
const [ isPopoverOpen , setIsPopoverOpen ] = useState < boolean > ( false )
45
51
46
52
const isCompleted = status && status === BulkActionsStatus . Completed
@@ -64,7 +70,11 @@ const BulkUpload = (props: Props) => {
64
70
}
65
71
66
72
const onFileChange = ( files : Nullable < FileList > ) => {
73
+ const isOutOfSize = ( files ?. [ 0 ] ?. size || 0 ) > MAX_FILE_SIZE
74
+
67
75
setFiles ( files )
76
+ setIsInvalid ( ! ! files ?. length && isOutOfSize )
77
+ setIsSubmitDisabled ( ! files ?. length || isOutOfSize )
68
78
}
69
79
70
80
const handleUpload = ( ) => {
@@ -110,11 +120,17 @@ const BulkUpload = (props: Props) => {
110
120
id = "bulk-upload-file-input"
111
121
initialPromptText = "Select or drag and drop a file"
112
122
className = { styles . fileDrop }
123
+ isInvalid = { isInvalid }
113
124
onChange = { onFileChange }
114
125
display = "large"
115
126
data-testid = "bulk-upload-file-input"
116
127
aria-label = "Select or drag and drop file"
117
128
/>
129
+ { isInvalid && (
130
+ < EuiTextColor color = "danger" className = { styles . errorFileMsg } data-testid = "input-file-error-msg" >
131
+ File should not exceed { MAX_MB_FILE } MB
132
+ </ EuiTextColor >
133
+ ) }
118
134
< EuiSpacer size = "l" />
119
135
</ div >
120
136
) : (
@@ -156,7 +172,7 @@ const BulkUpload = (props: Props) => {
156
172
fill
157
173
color = "secondary"
158
174
onClick = { handleUploadWarning }
159
- disabled = { ! files ?. length || loading }
175
+ disabled = { isSubmitDisabled || loading }
160
176
isLoading = { loading }
161
177
data-testid = "bulk-action-warning-btn"
162
178
>
0 commit comments