From 28b93f7654b7af0ea7680bba5331715ab23b8478 Mon Sep 17 00:00:00 2001 From: brendan colloran Date: Tue, 12 Sep 2023 18:08:43 -0700 Subject: [PATCH] fix sorting when changing context column --- .../src/features/dashboards/dashboard-stores.ts | 13 +++++++------ .../src/features/dashboards/humanize-numbers.ts | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/web-common/src/features/dashboards/dashboard-stores.ts b/web-common/src/features/dashboards/dashboard-stores.ts index 35c13d1be4e..f5c00b481ee 100644 --- a/web-common/src/features/dashboards/dashboard-stores.ts +++ b/web-common/src/features/dashboards/dashboard-stores.ts @@ -506,6 +506,9 @@ const metricViewReducers = { setContextColumn(name: string, contextColumn: LeaderboardContextColumn) { updateMetricsExplorerByName(name, (metricsExplorer) => { + const initialSort = sortTypeForContextColumnType( + metricsExplorer.leaderboardContextColumn + ); switch (contextColumn) { case LeaderboardContextColumn.DELTA_ABSOLUTE: case LeaderboardContextColumn.DELTA_PERCENT: { @@ -517,13 +520,11 @@ const metricViewReducers = { metricsExplorer.leaderboardContextColumn = contextColumn; } - // if we have changed the context column, and the leaderboard is currently - // sorted by the active context column, then we also need to change + // if we have changed the context column, and the leaderboard is + // sorted by the context column from before we made the change, + // then we also need to change // the sort type to match the new context column - if ( - metricsExplorer.dashboardSortType === - sortTypeForContextColumnType(metricsExplorer.leaderboardContextColumn) - ) { + if (metricsExplorer.dashboardSortType === initialSort) { metricsExplorer.dashboardSortType = sortTypeForContextColumnType(contextColumn); } diff --git a/web-common/src/features/dashboards/humanize-numbers.ts b/web-common/src/features/dashboards/humanize-numbers.ts index 75e69555f16..89d0e3d8f74 100644 --- a/web-common/src/features/dashboards/humanize-numbers.ts +++ b/web-common/src/features/dashboards/humanize-numbers.ts @@ -240,7 +240,7 @@ export function formatProperFractionAsPercent(value): NumberParts { return formatMeasurePercentageDifference(value); } - if (value < 0.005 && value !== 0) { + if (value < 0.01 && value !== 0) { return { percent: "%", int: "<1", dot: "", frac: "", suffix: "" }; } else if (value === 0) { return { percent: "%", int: "0", dot: "", frac: "", suffix: "" };