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

Fixed column widths for node tables with few columns #1272

Merged
merged 1 commit into from
Apr 12, 2016
Merged
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 @@ -95,13 +95,24 @@ export default class NodeDetailsTable extends React.Component {
const headers = [{id: 'label', label: this.props.label}].concat(columns);
const defaultSortBy = this.getDefaultSortBy();

// Beauty hack: adjust first column width if there are only few columns;
// this assumes the other columns are narrow metric columns of 20% table width
if (headers.length === 2) {
headers[0].width = 66;
} else if (headers.length === 3) {
headers[0].width = 50;
} else if (headers.length >= 3) {
headers[0].width = 33;
}

return (
<tr>
{headers.map(header => {
const headerClasses = ['node-details-table-header', 'truncate'];
const onHeaderClick = ev => {
this.handleHeaderClick(ev, header.id);
};

// sort by first metric by default
const isSorted = this.state.sortBy !== null
? header.id === this.state.sortBy : header.id === defaultSortBy;
Expand All @@ -110,8 +121,16 @@ export default class NodeDetailsTable extends React.Component {
if (isSorted) {
headerClasses.push('node-details-table-header-sorted');
}

// set header width in percent
const style = {};
if (header.width) {
style.width = `${header.width}%`;
}

return (
<td className={headerClasses.join(' ')} onClick={onHeaderClick} key={header.id}>
<td className={headerClasses.join(' ')} style={style} onClick={onHeaderClick}
key={header.id}>
{isSortedAsc
&& <span className="node-details-table-header-sorter fa fa-caret-up" />}
{isSortedDesc
Expand Down