Skip to content

Commit 9a82110

Browse files
authored
Merge pull request #1979 from RedisInsight/fe/bugfix/RI-4416_add-size-validation
#RI-4416 - add file size validation
2 parents 8d7fa48 + cf9ac0a commit 9a82110

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

redisinsight/ui/src/pages/browser/components/bulk-actions/BulkUpload/BulkUpload.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
EuiPopover,
88
EuiSpacer,
99
EuiText,
10+
EuiTextColor,
1011
EuiToolTip,
1112
} from '@elastic/eui'
1213

@@ -33,6 +34,9 @@ export interface Props {
3334
onCancel: () => void
3435
}
3536

37+
const MAX_MB_FILE = 100
38+
const MAX_FILE_SIZE = MAX_MB_FILE * 1024 * 1024
39+
3640
const BulkUpload = (props: Props) => {
3741
const { onCancel } = props
3842
const { id: instanceId } = useSelector(connectedInstanceSelector)
@@ -41,6 +45,8 @@ const BulkUpload = (props: Props) => {
4145
const { succeed, processed, failed } = useSelector(bulkActionsUploadSummarySelector) ?? {}
4246

4347
const [files, setFiles] = useState<Nullable<FileList>>(null)
48+
const [isInvalid, setIsInvalid] = useState<boolean>(false)
49+
const [isSubmitDisabled, setIsSubmitDisabled] = useState<boolean>(true)
4450
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false)
4551

4652
const isCompleted = status && status === BulkActionsStatus.Completed
@@ -64,7 +70,11 @@ const BulkUpload = (props: Props) => {
6470
}
6571

6672
const onFileChange = (files: Nullable<FileList>) => {
73+
const isOutOfSize = (files?.[0]?.size || 0) > MAX_FILE_SIZE
74+
6775
setFiles(files)
76+
setIsInvalid(!!files?.length && isOutOfSize)
77+
setIsSubmitDisabled(!files?.length || isOutOfSize)
6878
}
6979

7080
const handleUpload = () => {
@@ -110,11 +120,17 @@ const BulkUpload = (props: Props) => {
110120
id="bulk-upload-file-input"
111121
initialPromptText="Select or drag and drop a file"
112122
className={styles.fileDrop}
123+
isInvalid={isInvalid}
113124
onChange={onFileChange}
114125
display="large"
115126
data-testid="bulk-upload-file-input"
116127
aria-label="Select or drag and drop file"
117128
/>
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+
)}
118134
<EuiSpacer size="l" />
119135
</div>
120136
) : (
@@ -156,7 +172,7 @@ const BulkUpload = (props: Props) => {
156172
fill
157173
color="secondary"
158174
onClick={handleUploadWarning}
159-
disabled={!files?.length || loading}
175+
disabled={isSubmitDisabled || loading}
160176
isLoading={loading}
161177
data-testid="bulk-action-warning-btn"
162178
>

redisinsight/ui/src/pages/browser/components/bulk-actions/BulkUpload/styles.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
}
5353
}
5454

55+
.errorFileMsg {
56+
margin-top: 10px;
57+
font-size: 12px;
58+
}
59+
5560
.footer {
5661
position: absolute;
5762
bottom: 24px;

0 commit comments

Comments
 (0)