Skip to content
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

[Synthetics] Fix mobile synthetics image clipping #106128

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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