[Logs UI] Fix alert previews for thresholds of 0 (#111150)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Alejandro Fernández Gómez 2021-09-08 11:33:00 +02:00 committed by GitHub
parent 094f2c9b81
commit 77e25bedfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View file

@ -197,14 +197,11 @@ const CriterionPreviewChart: React.FC<ChartProps> = ({
const hasData = series.length > 0; const hasData = series.length > 0;
const { yMin, yMax, xMin, xMax } = getDomain(filteredSeries, isStacked); const { yMin, yMax, xMin, xMax } = getDomain(filteredSeries, isStacked);
const chartDomain = { const chartDomain = {
max: max: showThreshold && threshold ? Math.max(yMax, threshold.value) * 1.1 : yMax * 1.1, // Add 10% headroom.
showThreshold && threshold && threshold.value min: showThreshold && threshold ? Math.min(yMin, threshold.value) : yMin,
? Math.max(yMax, threshold.value) * 1.1
: yMax * 1.1, // Add 10% headroom.
min: showThreshold && threshold && threshold.value ? Math.min(yMin, threshold.value) : yMin,
}; };
if (showThreshold && threshold && threshold.value && chartDomain.min === threshold.value) { if (showThreshold && threshold && chartDomain.min === threshold.value) {
chartDomain.min = chartDomain.min * 0.9; // Allow some padding so the threshold annotation has better visibility chartDomain.min = chartDomain.min * 0.9; // Allow some padding so the threshold annotation has better visibility
} }
@ -246,7 +243,7 @@ const CriterionPreviewChart: React.FC<ChartProps> = ({
}} }}
color={!isGrouped ? colorTransformer(Color.color0) : undefined} color={!isGrouped ? colorTransformer(Color.color0) : undefined}
/> />
{showThreshold && threshold && threshold.value ? ( {showThreshold && threshold ? (
<LineAnnotation <LineAnnotation
id={`threshold-line`} id={`threshold-line`}
domainType={AnnotationDomainType.YDomain} domainType={AnnotationDomainType.YDomain}
@ -260,7 +257,7 @@ const CriterionPreviewChart: React.FC<ChartProps> = ({
}} }}
/> />
) : null} ) : null}
{showThreshold && threshold && threshold.value && isBelow ? ( {showThreshold && threshold && isBelow ? (
<RectAnnotation <RectAnnotation
id="below-threshold" id="below-threshold"
style={{ style={{
@ -279,7 +276,7 @@ const CriterionPreviewChart: React.FC<ChartProps> = ({
]} ]}
/> />
) : null} ) : null}
{showThreshold && threshold && threshold.value && isAbove ? ( {showThreshold && threshold && isAbove ? (
<RectAnnotation <RectAnnotation
id="above-threshold" id="above-threshold"
style={{ style={{

View file

@ -65,7 +65,9 @@ export const Threshold: React.FC<Props> = ({ comparator, value, updateThreshold,
<EuiExpression <EuiExpression
description={thresholdPrefix} description={thresholdPrefix}
uppercase={true} uppercase={true}
value={`${comparator ? ComparatorToi18nMap[comparator] : ''} ${value ? value : ''}`} value={`${comparator ? ComparatorToi18nMap[comparator] : ''} ${
typeof value === 'number' ? value : ''
}`}
isActive={isThresholdPopoverOpen} isActive={isThresholdPopoverOpen}
onClick={() => setThresholdPopoverOpenState(!isThresholdPopoverOpen)} onClick={() => setThresholdPopoverOpenState(!isThresholdPopoverOpen)}
/> />