diff --git a/src/files-and-videos/files-page/FileInfoModalSidebar.jsx b/src/files-and-videos/files-page/FileInfoModalSidebar.jsx index 842c6e568c..e2a92b40c5 100644 --- a/src/files-and-videos/files-page/FileInfoModalSidebar.jsx +++ b/src/files-and-videos/files-page/FileInfoModalSidebar.jsx @@ -18,7 +18,7 @@ import { } from '@edx/paragon'; import { ContentCopy, InfoOutline } from '@edx/paragon/icons'; -import { getFileSizeToClosestByte } from '../generic/utils'; +import { getFileSizeToClosestByte } from '../../utils'; import messages from './messages'; const FileInfoModalSidebar = ({ diff --git a/src/files-and-videos/files-page/FilesPage.jsx b/src/files-and-videos/files-page/FilesPage.jsx index 1111dbc93a..8f69d59849 100644 --- a/src/files-and-videos/files-page/FilesPage.jsx +++ b/src/files-and-videos/files-page/FilesPage.jsx @@ -28,7 +28,7 @@ import { FileTable, ThumbnailColumn, } from '../generic'; -import { getFileSizeToClosestByte } from '../generic/utils'; +import { getFileSizeToClosestByte } from '../../utils'; import FileThumbnail from './FileThumbnail'; import FileInfoModalSidebar from './FileInfoModalSidebar'; diff --git a/src/files-and-videos/generic/utils.js b/src/files-and-videos/generic/utils.js index 7cbcc07d4c..e23afc7012 100644 --- a/src/files-and-videos/generic/utils.js +++ b/src/files-and-videos/generic/utils.js @@ -1,23 +1,4 @@ -export const getFileSizeToClosestByte = (fileSize, numberOfDivides = 0) => { - if (fileSize > 1000) { - const updatedSize = fileSize / 1000; - const incrementNumberOfDivides = numberOfDivides + 1; - return getFileSizeToClosestByte(updatedSize, incrementNumberOfDivides); - } - const fileSizeFixedDecimal = Number.parseFloat(fileSize).toFixed(2); - switch (numberOfDivides) { - case 1: - return `${fileSizeFixedDecimal} KB`; - case 2: - return `${fileSizeFixedDecimal} MB`; - case 3: - return `${fileSizeFixedDecimal} GB`; - default: - return `${fileSizeFixedDecimal} B`; - } -}; - -export const sortFiles = (files, sortType) => { +export const sortFiles = (files, sortType) => { // eslint-disable-line import/prefer-default-export const [sort, direction] = sortType.split(','); let sortedFiles; if (sort === 'displayName') { diff --git a/src/files-and-videos/videos-page/info-sidebar/InfoTab.jsx b/src/files-and-videos/videos-page/info-sidebar/InfoTab.jsx index cdc5ab2bd6..cef932d573 100644 --- a/src/files-and-videos/videos-page/info-sidebar/InfoTab.jsx +++ b/src/files-and-videos/videos-page/info-sidebar/InfoTab.jsx @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Stack } from '@edx/paragon'; import { injectIntl, FormattedDate, FormattedMessage } from '@edx/frontend-platform/i18n'; -import { getFileSizeToClosestByte } from '../../generic/utils'; +import { getFileSizeToClosestByte } from '../../../utils'; import { getFormattedDuration } from '../data/utils'; import messages from './messages'; diff --git a/src/taxonomy/import-tags/ImportTagsWizard.jsx b/src/taxonomy/import-tags/ImportTagsWizard.jsx index dc0bea2b03..bff08a3c66 100644 --- a/src/taxonomy/import-tags/ImportTagsWizard.jsx +++ b/src/taxonomy/import-tags/ImportTagsWizard.jsx @@ -19,8 +19,8 @@ import { import PropTypes from 'prop-types'; import { useState } from 'react'; -import { getFileSizeToClosestByte } from '../../files-and-videos/generic/utils'; // ToDo: Check best approach import LoadingButton from '../../generic/loading-button'; +import { getFileSizeToClosestByte } from '../../utils'; import { getTaxonomyExportFile } from '../data/api'; import { planImportTags, useImportTags } from './data/api'; import messages from './messages'; diff --git a/src/utils.js b/src/utils.js index 6e5edcee71..47de7412e0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -256,3 +256,22 @@ export const isValidDate = (date) => { return Boolean(formattedValue.length <= 10); }; + +export const getFileSizeToClosestByte = (fileSize, numberOfDivides = 0) => { + if (fileSize > 1000) { + const updatedSize = fileSize / 1000; + const incrementNumberOfDivides = numberOfDivides + 1; + return getFileSizeToClosestByte(updatedSize, incrementNumberOfDivides); + } + const fileSizeFixedDecimal = Number.parseFloat(fileSize).toFixed(2); + switch (numberOfDivides) { + case 1: + return `${fileSizeFixedDecimal} KB`; + case 2: + return `${fileSizeFixedDecimal} MB`; + case 3: + return `${fileSizeFixedDecimal} GB`; + default: + return `${fileSizeFixedDecimal} B`; + } +}; diff --git a/src/files-and-videos/generic/utils.test.js b/src/utils.test.js similarity index 100% rename from src/files-and-videos/generic/utils.test.js rename to src/utils.test.js