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

Bug 1808394: remove default sorting from metrics table so query sort is prese… #4559

Merged
merged 1 commit into from Mar 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 15 additions & 12 deletions frontend/public/components/monitoring/metrics.tsx
Expand Up @@ -606,7 +606,7 @@ 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 [sortBy, setSortBy] = React.useState<ISortBy>();

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

Expand All @@ -632,6 +632,7 @@ const QueryTable_: React.FC<QueryTableProps> = ({
setData(undefined);
setError(undefined);
setPage(1);
setSortBy(undefined);
}, [namespace, query]);

if (!isEnabled || !isExpanded || !query) {
Expand Down Expand Up @@ -722,17 +723,19 @@ 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);
if (sortBy) {
// 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}`;
rows = _.orderBy(rows, [sort], [sortBy.direction]);
}
}

// Set the result table's break point based on the number of columns
Expand Down