From 3a349712f087d4841bd7cfde67fed8006b2499ec Mon Sep 17 00:00:00 2001 From: Dhiraj Kumar Date: Wed, 13 Sep 2023 22:24:54 +0530 Subject: [PATCH] Leaderboard show all compared values for exclude --- .../dashboards/leaderboard/Leaderboard.svelte | 22 ++++++++++++++++++- .../leaderboard/leaderboard-utils.ts | 6 +++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/web-common/src/features/dashboards/leaderboard/Leaderboard.svelte b/web-common/src/features/dashboards/leaderboard/Leaderboard.svelte index ef44df0e60d..954ff6d6535 100644 --- a/web-common/src/features/dashboards/leaderboard/Leaderboard.svelte +++ b/web-common/src/features/dashboards/leaderboard/Leaderboard.svelte @@ -138,9 +138,24 @@ })) ?? []; } + let valuesComparedInExcludeMode = []; + $: if (isBeingCompared && filterExcludeMode) { + let count = 0; + valuesComparedInExcludeMode = values + .filter((value) => { + if (!activeValues.includes(value.label) && count < 3) { + count++; + return true; + } + return false; + }) + .map((value) => value.label); + } + // get all values that are selected but not visible. // we'll put these at the bottom w/ a divider. $: selectedValuesThatAreBelowTheFold = activeValues + ?.concat(valuesComparedInExcludeMode) ?.filter((label) => { return ( // the value is visible within the fold. @@ -227,11 +242,16 @@ filterExcludeMode ); + $: defaultComparisonsPresentInAboveFold = + aboveTheFoldItems?.filter((item) => item.defaultComparedIndex >= 0) + ?.length || 0; + $: belowTheFoldItems = prepareLeaderboardItemData( selectedValuesThatAreBelowTheFold, activeValues, comparisonMap, - filterExcludeMode + filterExcludeMode, + defaultComparisonsPresentInAboveFold ); diff --git a/web-common/src/features/dashboards/leaderboard/leaderboard-utils.ts b/web-common/src/features/dashboards/leaderboard/leaderboard-utils.ts index 11b402e6a7f..bda4ca7d8de 100644 --- a/web-common/src/features/dashboards/leaderboard/leaderboard-utils.ts +++ b/web-common/src/features/dashboards/leaderboard/leaderboard-utils.ts @@ -35,9 +35,10 @@ export function prepareLeaderboardItemData( values: { value: number; label: string | number }[], selectedValues: (string | number)[], comparisonMap: Map, - excludeMode: boolean + excludeMode: boolean, + initalCount = 0 ): LeaderboardItemData[] { - let count = 0; + let count = initalCount; return values.map((v) => { const selectedIndex = selectedValues.findIndex( @@ -47,6 +48,7 @@ export function prepareLeaderboardItemData( // Tag values which will be compared by default let defaultComparedIndex = -1; + if (!excludeMode && count < 3 && !selectedValues.length) { defaultComparedIndex = count; count = count + 1;