MM-44470 Fix SVG without width not displaying (#28963)
* Fix SVG rendering issue by setting default dimensions in image preview components * destructuring attribute to prevent empty style object * only create style object when fileType is svg * fix style attribute for svg
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2593860063
Коммит
0031e77b09
@@ -7,6 +7,9 @@ import type {FileInfo} from '@mattermost/types/files';
|
|||||||
|
|
||||||
import {getFilePreviewUrl, getFileDownloadUrl} from 'mattermost-redux/utils/file_utils';
|
import {getFilePreviewUrl, getFileDownloadUrl} from 'mattermost-redux/utils/file_utils';
|
||||||
|
|
||||||
|
import {FileTypes} from 'utils/constants';
|
||||||
|
import {getFileType} from 'utils/utils';
|
||||||
|
|
||||||
import './image_preview.scss';
|
import './image_preview.scss';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -31,6 +34,14 @@ export default function ImagePreview({fileInfo, canDownloadFiles}: Props) {
|
|||||||
return <img src={previewUrl}/>;
|
return <img src={previewUrl}/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let conditionalSVGStyleAttribute;
|
||||||
|
if (getFileType(fileInfo.extension) === FileTypes.SVG) {
|
||||||
|
conditionalSVGStyleAttribute = {
|
||||||
|
width: fileInfo.width,
|
||||||
|
height: 'auto',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
className='image_preview'
|
className='image_preview'
|
||||||
@@ -42,6 +53,7 @@ export default function ImagePreview({fileInfo, canDownloadFiles}: Props) {
|
|||||||
data-testid='imagePreview'
|
data-testid='imagePreview'
|
||||||
alt={'preview url image'}
|
alt={'preview url image'}
|
||||||
src={previewUrl}
|
src={previewUrl}
|
||||||
|
style={conditionalSVGStyleAttribute}
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ import {getFileMiniPreviewUrl} from 'mattermost-redux/utils/file_utils';
|
|||||||
import LoadingImagePreview from 'components/loading_image_preview';
|
import LoadingImagePreview from 'components/loading_image_preview';
|
||||||
import WithTooltip from 'components/with_tooltip';
|
import WithTooltip from 'components/with_tooltip';
|
||||||
|
|
||||||
import {localizeMessage, copyToClipboard} from 'utils/utils';
|
import {FileTypes} from 'utils/constants';
|
||||||
|
import {localizeMessage, copyToClipboard, getFileType} from 'utils/utils';
|
||||||
|
|
||||||
const MIN_IMAGE_SIZE = 48;
|
const MIN_IMAGE_SIZE = 48;
|
||||||
const MIN_IMAGE_SIZE_FOR_INTERNAL_BUTTONS = 100;
|
const MIN_IMAGE_SIZE_FOR_INTERNAL_BUTTONS = 100;
|
||||||
@@ -194,6 +195,7 @@ export default class SizeAwareImage extends React.PureComponent<Props, State> {
|
|||||||
renderImageWithContainerIfNeeded = () => {
|
renderImageWithContainerIfNeeded = () => {
|
||||||
const {
|
const {
|
||||||
fileInfo,
|
fileInfo,
|
||||||
|
dimensions,
|
||||||
src,
|
src,
|
||||||
fileURL,
|
fileURL,
|
||||||
enablePublicLink,
|
enablePublicLink,
|
||||||
@@ -214,6 +216,16 @@ export default class SizeAwareImage extends React.PureComponent<Props, State> {
|
|||||||
ariaLabelImage += ` ${fileInfo.name}`.toLowerCase();
|
ariaLabelImage += ` ${fileInfo.name}`.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileType = getFileType(fileInfo?.extension ?? '');
|
||||||
|
|
||||||
|
let conditionalSVGStyleAttribute;
|
||||||
|
if (fileType === FileTypes.SVG) {
|
||||||
|
conditionalSVGStyleAttribute = {
|
||||||
|
width: dimensions?.width || MIN_IMAGE_SIZE,
|
||||||
|
height: 'auto',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const image = (
|
const image = (
|
||||||
<img
|
<img
|
||||||
{...props}
|
{...props}
|
||||||
@@ -228,6 +240,7 @@ export default class SizeAwareImage extends React.PureComponent<Props, State> {
|
|||||||
src={src}
|
src={src}
|
||||||
onError={this.handleError}
|
onError={this.handleError}
|
||||||
onLoad={this.handleLoad}
|
onLoad={this.handleLoad}
|
||||||
|
style={conditionalSVGStyleAttribute}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user