Skip to content

Commit

Permalink
refactor: move getFileSizeToClosestByte to root utils
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Dec 8, 2023
1 parent 7a0a44c commit 6a55c6f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/files-and-videos/files-page/FileInfoModalSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down
2 changes: 1 addition & 1 deletion src/files-and-videos/files-page/FilesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
21 changes: 1 addition & 20 deletions src/files-and-videos/generic/utils.js
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion src/files-and-videos/videos-page/info-sidebar/InfoTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/taxonomy/import-tags/ImportTagsWizard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
19 changes: 19 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}
};
File renamed without changes.

0 comments on commit 6a55c6f

Please sign in to comment.