Skip to content

Commit

Permalink
[Synthetics] Fix mobile synthetics image clipping (#106128) (#106284)
Browse files Browse the repository at this point in the history
* Change hardcoded image size value to prevent clipping of mobile synthetics screenshots.

* Compute max values for `ref`-style screenshots to improve display ux.

Co-authored-by: Justin Kambic <justin.kambic@elastic.co>
  • Loading branch information
kibanamachine and justinkambic authored Jul 20, 2021
1 parent a74a3a2 commit 5eb1eaa
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import styled from 'styled-components';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { useContext, useEffect, useRef, useState, FC } from 'react';
import React, { useContext, useEffect, useMemo, useRef, useState, FC } from 'react';
import useIntersection from 'react-use/lib/useIntersection';
import {
isScreenshotRef as isAScreenshotRef,
Expand All @@ -36,16 +36,13 @@ interface StepScreenshotDisplayProps {
lazyLoad?: boolean;
}

const IMAGE_WIDTH = 640;
const IMAGE_HEIGHT = 360;
const IMAGE_MAX_WIDTH = 640;

const StepImage = styled(EuiImage)`
&&& {
figcaption {
display: none;
}
width: ${IMAGE_WIDTH},
height: ${IMAGE_HEIGHT},
objectFit: 'cover',
objectPosition: 'center top',
}
Expand Down Expand Up @@ -139,11 +136,22 @@ export const StepScreenshotDisplay: FC<StepScreenshotDisplayProps> = ({
}
}, [basePath, checkGroup, stepIndex, isScreenshotRef]);

const refDimensions = useMemo(() => {
if (isAScreenshotRef(screenshotRef)) {
const { height, width } = screenshotRef.ref.screenshotRef.screenshot_ref;
return { height, width };
}
}, [screenshotRef]);

const shouldRenderImage = hasIntersected || !lazyLoad;
return (
<div
ref={containerRef}
style={{ backgroundColor: pageBackground, height: IMAGE_HEIGHT, width: IMAGE_WIDTH }}
style={{
backgroundColor: pageBackground,
maxWidth: Math.min(IMAGE_MAX_WIDTH, refDimensions?.width ?? Number.MAX_VALUE),
maxHeight: refDimensions?.height ?? undefined,
}}
>
{shouldRenderImage && isScreenshotBlob && (
<BaseStepImage stepName={stepName} stepIndex={stepIndex} url={url} />
Expand Down

0 comments on commit 5eb1eaa

Please sign in to comment.