Skip to content

Commit

Permalink
Bug 1808394: remove sorting from metrics table so query sort is prese…
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamilto committed Feb 28, 2020
1 parent 9aadb12 commit 88ac0e6
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions frontend/public/components/monitoring/metrics.tsx
Expand Up @@ -23,9 +23,6 @@ import {
TimesIcon,
} from '@patternfly/react-icons';
import {
IDecorator,
ISortBy,
sortable,
Table,
TableBody,
TableGridBreakpoint,
Expand Down Expand Up @@ -606,7 +603,6 @@ const QueryTable_: React.FC<QueryTableProps> = ({
const [error, setError] = React.useState();
const [page, setPage] = React.useState(1);
const [perPage, setPerPage] = React.useState(50);
const [sortBy, setSortBy] = React.useState<ISortBy>({ index: 1, direction: 'asc' });

const safeFetch = React.useCallback(useSafeFetch(), []);

Expand Down Expand Up @@ -675,7 +671,6 @@ const QueryTable_: React.FC<QueryTableProps> = ({

const cellProps = {
props: { className: 'query-browser__table-cell' },
transforms: [sortable as (v: unknown) => IDecorator],
};

// TableBody's shouldComponentUpdate seems to struggle with SeriesButton, so add a unique key to help TableBody
Expand Down Expand Up @@ -722,17 +717,7 @@ const QueryTable_: React.FC<QueryTableProps> = ({
];
}

// Sort Values column numerically and sort all the other columns alphabetically
const valuesColIndex = allLabelKeys.length + 1;
const sort =
sortBy.index === valuesColIndex
? (cells) => {
const v = Number(cells[valuesColIndex]);
return Number.isNaN(v) ? 0 : v;
}
: sortBy.index;
const unsortedRows = _.map(result, rowMapper);
rows = _.orderBy(unsortedRows, [sort], [sortBy.direction]) as string[][];
rows = _.map(result, rowMapper) as string[][];
}

// Set the result table's break point based on the number of columns
Expand All @@ -749,8 +734,6 @@ const QueryTable_: React.FC<QueryTableProps> = ({
breakPoint = 'grid2xl';
}

const onSort = (e, i, direction) => setSortBy({ index: i, direction });

const tableRows = rows.slice((page - 1) * perPage, page * perPage).map((cells) => ({ cells }));

return (
Expand All @@ -759,9 +742,7 @@ const QueryTable_: React.FC<QueryTableProps> = ({
aria-label="query results table"
cells={columns}
gridBreakPoint={TableGridBreakpoint[breakPoint]}
onSort={onSort}
rows={tableRows}
sortBy={sortBy}
variant={TableVariant.compact}
>
<TableHeader />
Expand Down

0 comments on commit 88ac0e6

Please sign in to comment.