Repository navigation
fix(app): only show distribution labels the data backs #3230
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
Changes from all commits
fa728fa
d38c608
8f177d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@hyperdx/app': patch | ||
| '@hyperdx/common-utils': patch | ||
| --- | ||
|
|
||
| fix: Show distribution only labels a value "<1%" when the sample shows it is rare, not when it has no matching rows, and shows 100% when the field's filter allows only that value |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,9 @@ const INITIAL_MAX_VALUES_DISPLAYED = 10; | |
| /* The maximum number of values per filter to render at once after loading more */ | ||
| const SHOW_MORE_MAX_VALUES_DISPLAYED = 50; | ||
|
|
||
| /* The 100 most common values are enough to find any value present in at least 1% of rows */ | ||
| const DISTRIBUTION_VALUE_LIMIT = 100; | ||
|
|
||
| // This function will clean json string attributes specifically. It will turn a string like | ||
| // 'toString(ResourceAttributes.`hdx`.`sdk`.`version`)' into 'ResourceAttributes.hdx.sdk.version'. | ||
| export function cleanedFacetName(key: string): string { | ||
|
|
@@ -133,6 +136,7 @@ type FilterCheckboxProps = { | |
| className?: string; | ||
| percentage?: number; | ||
| isPercentageLoading?: boolean; | ||
| isPercentageExact?: boolean; | ||
| }; | ||
|
|
||
| const TextButton = ({ | ||
|
|
@@ -165,19 +169,24 @@ const TextButton = ({ | |
| type FilterPercentageProps = { | ||
| percentage: number; | ||
| isLoading?: boolean; | ||
| // Share is guaranteed by the filter rather than estimated from the sample. | ||
| isExact?: boolean; | ||
| 'data-testid'?: string; | ||
| }; | ||
|
|
||
| const FilterPercentage = ({ | ||
| percentage, | ||
| isLoading, | ||
| isExact, | ||
| 'data-testid': dataTestId, | ||
| }: FilterPercentageProps) => { | ||
| const formattedPercentage = | ||
| percentage < 1 | ||
| ? `<1%` | ||
| : percentage >= 99.5 | ||
| ? `>99%` | ||
| ? isExact | ||
| ? '100%' | ||
| : `>99%` | ||
| : `~${Math.round(percentage)}%`; | ||
|
|
||
| return ( | ||
|
|
@@ -205,6 +214,7 @@ const FilterCheckbox = ({ | |
| className, | ||
| percentage, | ||
| isPercentageLoading, | ||
| isPercentageExact, | ||
| }: FilterCheckboxProps) => { | ||
| const [pinMenuOpened, setPinMenuOpened] = useState(false); | ||
| const testIdPrefix = `filter-checkbox-${columnName}-${label}`; | ||
|
|
@@ -268,6 +278,7 @@ const FilterCheckbox = ({ | |
| <FilterPercentage | ||
| percentage={percentage} | ||
| isLoading={isPercentageLoading} | ||
| isExact={isPercentageExact} | ||
| data-testid={`filter-distribution-${columnName}-${label}`} | ||
| /> | ||
| )} | ||
|
|
@@ -492,7 +503,8 @@ const FilterGroupBody = ({ | |
| { | ||
| chartConfig: { ...chartConfig, dateRange }, | ||
| key: distributionKey || name, | ||
| limit: 100, // The 100 most common values are enough to find any values that are present in at least 1% of rows | ||
| // One extra row tells a capped result apart from exactly 100 values | ||
| limit: DISTRIBUTION_VALUE_LIMIT + 1, | ||
| }, | ||
| { | ||
| enabled: showDistributions, | ||
|
|
@@ -629,6 +641,22 @@ const FilterGroupBody = ({ | |
| [onChange, selectedValues], | ||
| ); | ||
|
|
||
| // The distribution query runs under this field's own filter, so a value the | ||
| // filter rules out has zero rows; showing it as "<1%" would read as rare. | ||
| const isExcludedByOwnFilter = (value: string | boolean) => | ||
| selectedValues.excluded.has(value) || | ||
| (selectedValues.included.size > 0 && !selectedValues.included.has(value)); | ||
|
|
||
| const getPercentage = (value: string | boolean) => { | ||
| if (!showDistributions || !distributionData || isExcludedByOwnFilter(value)) | ||
| return undefined; | ||
| const percentage = distributionData.get(value.toString()); | ||
| if (percentage != null) return percentage; | ||
| // Missing from a capped result means it ranks below the 100th value, so | ||
| // under 1%. Missing from an uncapped result means it wasn't seen at all. | ||
| return distributionData.size > DISTRIBUTION_VALUE_LIMIT ? 0 : undefined; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 major — Rare values that really exist lose their "<1%" label on sampled tables
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond |
||
| }; | ||
|
|
||
| const isLimitingDisplayedItems = | ||
| sortedMatchingOptions.length > displayedOptions.length; | ||
|
|
||
|
|
@@ -682,11 +710,11 @@ const FilterGroupBody = ({ | |
| onSharedPinClick ? () => onSharedPinClick(option.value) : undefined | ||
| } | ||
| isPercentageLoading={isFetchingDistribution} | ||
| percentage={ | ||
| showDistributions && distributionData | ||
| ? (distributionData.get(option.value.toString()) ?? 0) | ||
| : undefined | ||
| isPercentageExact={ | ||
| selectedValues.included.size === 1 && | ||
| selectedValues.included.has(option.value) | ||
| } | ||
| percentage={getPercentage(option.value)} | ||
| /> | ||
| ))} | ||
| {optionsLoading ? ( | ||
|
|
@@ -799,7 +827,9 @@ function FilterGroupActions({ | |
| <> | ||
| <Tooltip | ||
| label={ | ||
| showDistributions ? 'Hide Distribution' : 'Show Distribution' | ||
| showDistributions | ||
| ? 'Hide distribution' | ||
| : 'Show distribution (estimated from a sample of rows)' | ||
| } | ||
| position="top" | ||
| withArrow | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<1%label for a value that is present: an uncapped sample shows only that the value was not sampled, not that it has no matching rows.