Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Fixes file data viz file size check and format as bytes #25295

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class FileDataVisualizerView extends Component {
};

async loadFile(file) {
if (file.size < MAX_BYTES) {
if (file.size <= MAX_BYTES) {
try {
const fileContents = await readFile(file);
const data = fileContents.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,42 @@ import {
EuiCallOut,
} from '@elastic/eui';

import numeral from '@elastic/numeral';

const FILE_SIZE_DISPLAY_FORMAT = '0,0.[0] b';

export function FileTooLarge({ fileSize, maxFileSize }) {
const fileSizeFormatted = numeral(fileSize).format(FILE_SIZE_DISPLAY_FORMAT);
const maxFileSizeFormatted = numeral(maxFileSize).format(FILE_SIZE_DISPLAY_FORMAT);

// Format the byte values, using the second format if the difference between
// the file size and the max is so small that the formatted values are identical
// e.g. 100.01 MB and 100.0 MB
let errorText;
if (fileSizeFormatted !== maxFileSizeFormatted) {
errorText = (
<p>
The size of the file you selected for upload is {fileSizeFormatted} which
exceeds the maximum permitted size of {maxFileSizeFormatted}
</p>
);
} else {
const diffFormatted = numeral(fileSize - maxFileSize).format(FILE_SIZE_DISPLAY_FORMAT);
errorText = (
<p>
The size of the file you selected for upload exceeds the maximum
permitted size of {maxFileSizeFormatted} by {diffFormatted}
</p>
);
}

return (
<EuiCallOut
title="File size is too large"
color="danger"
iconType="cross"
>
<p>
The size of the file you selected for upload is {fileSize} which exceeds the maximum permitted size of {maxFileSize}
</p>
{errorText}
</EuiCallOut>
);
}
Expand Down