Skip to content

Commit

Permalink
remove toggle sorting functionality from TableComponent (linkerd#630)
Browse files Browse the repository at this point in the history
remove toggle sorting functionality from TableComponent:
- tables displaying metrics allowed to toggle between being sorted and unsorted when clicking the same button. This was confusing behavior for the user.
- this PR removes the toggle functionality and introduces a BaseTable Component that extends antd's component without the capability to toggle
- Fixes: linkerd#566

Signed-off-by: Franziska von der Goltz <franziska@vdgoltz.eu>
  • Loading branch information
franziskagoltz authored Mar 29, 2018
1 parent c688cf6 commit 67fac9d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
31 changes: 31 additions & 0 deletions web/app/js/components/BaseTable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Table } from 'antd';

// BaseTable extends ant-design's table, but overwrites the `toggleSortOrder`
// method, in order to remove the default behavior of unsorting a column when
// the same sorting arrow is pressed twice:
// https://github.com/ant-design/ant-design/blob/master/components/table/Table.tsx#L348
export default class BaseTable extends Table {
constructor(props) {
super(props);
Table.prototype.toggleSortOrder = this.toggleSortOrder;
}

toggleSortOrder(order, column) {
const newState = {
sortOrder: order,
sortColumn: column,
};

if (this.getSortOrderColumns().length === 0) {
this.setState(newState);
}

const onChange = this.props.onChange;
if (onChange) {
onChange.apply(null, this.prepareParamsArguments({
...this.state,
...newState,
}));
}
}
}
7 changes: 4 additions & 3 deletions web/app/js/components/MetricsTable.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import _ from 'lodash';
import BaseTable from './BaseTable.jsx';
import { metricToFormatter } from './util/Utils.js';
import React from 'react';
import { Table, Tooltip } from 'antd';
import { Tooltip } from 'antd';

/*
Table to display Success Rate, Requests and Latency in tabs.
Expand Down Expand Up @@ -82,7 +83,7 @@ const columnDefinitions = (sortable = true, resource, ConduitLink) => {

const numericSort = (a, b) => (_.isNil(a) ? -1 : a) - (_.isNil(b) ? -1 : b);

export default class MetricsTable extends React.Component {
export default class MetricsTable extends BaseTable {
constructor(props) {
super(props);
this.api = this.props.api;
Expand All @@ -105,7 +106,7 @@ export default class MetricsTable extends React.Component {
let tableData = this.preprocessMetrics();
let columns = _.compact(columnDefinitions(this.props.sortable, resource, this.api.ConduitLink));

return (<Table
return (<BaseTable
dataSource={tableData}
columns={columns}
pagination={false}
Expand Down

0 comments on commit 67fac9d

Please sign in to comment.