diff --git a/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_datavisualizer_view.js b/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_datavisualizer_view.js index efa3bd1f83ff..36916286e682 100644 --- a/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_datavisualizer_view.js +++ b/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_datavisualizer_view.js @@ -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; diff --git a/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_error_callouts.js b/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_error_callouts.js index f45e6f12929c..63ba52ad88dd 100644 --- a/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_error_callouts.js +++ b/x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_error_callouts.js @@ -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 = ( +
+ The size of the file you selected for upload is {fileSizeFormatted} which + exceeds the maximum permitted size of {maxFileSizeFormatted} +
+ ); + } else { + const diffFormatted = numeral(fileSize - maxFileSize).format(FILE_SIZE_DISPLAY_FORMAT); + errorText = ( ++ The size of the file you selected for upload exceeds the maximum + permitted size of {maxFileSizeFormatted} by {diffFormatted} +
+ ); + } + return (- The size of the file you selected for upload is {fileSize} which exceeds the maximum permitted size of {maxFileSize} -
+ {errorText}