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

PXP-4372 Fix/file size #603

Merged
merged 3 commits into from
Oct 17, 2019
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
15 changes: 11 additions & 4 deletions src/GuppyDataExplorer/ExplorerTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import ReactTable from 'react-table';
import 'react-table/react-table.css';
import { GuppyConfigType, TableConfigType } from '../configTypeDef';
import { capitalizeFirstLetter } from '../../utils';
import { capitalizeFirstLetter, humanFileSize } from '../../utils';
import './ExplorerTable.css';
import LockIcon from '../../img/icons/lock.svg';

Expand Down Expand Up @@ -71,9 +71,16 @@ class ExplorerTable extends React.Component {
accessor: field,
maxWidth: 400,
width: this.getWidthForColumn(field, name),
Cell: row => (this.props.guppyConfig.downloadAccessor === field ?
<div><span title={row.value}><a href={`/files/${row.value}`}>{row.value}</a></span></div>
: <div><span title={row.value}>{row.value}</span></div>),
Cell: (row) => {
switch (field) {
case this.props.guppyConfig.downloadAccessor:
return (<div><span title={row.value}><a href={`/files/${row.value}`}>{row.value}</a></span></div>);
case 'file_size':
return (<div><span title={row.value}>{humanFileSize(row.value)}</span></div>);
default:
return (<div><span title={row.value}>{row.value}</span></div>);
}
},
};
});
const { totalCount } = this.props;
Expand Down
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as d3 from 'd3-scale';
import { submissionApiPath } from './localconf';

export const humanFileSize = (size) => {
if (typeof size !== 'number') {
return '';
}
const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
const sizeStr = (size / (1024 ** i)).toFixed(2) * 1;
const suffix = ['B', 'KB', 'MB', 'GB', 'TB'][i];
Expand Down