From d319d22f91c13a7071abba9db68fc95a20e3ccfc Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Fri, 6 Jul 2018 14:15:59 +0200 Subject: [PATCH] Fixes #1518 --- .../lib/src/components/ImgPreview/index.js | 12 ++++++++---- .../lib/src/components/PageFooter/index.js | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/strapi-helper-plugin/lib/src/components/ImgPreview/index.js b/packages/strapi-helper-plugin/lib/src/components/ImgPreview/index.js index 8162593d31..197af53f44 100644 --- a/packages/strapi-helper-plugin/lib/src/components/ImgPreview/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/ImgPreview/index.js @@ -8,7 +8,7 @@ /* eslint-disable no-console */ import React from 'react'; import PropTypes from 'prop-types'; -import { get, has, isArray, isEmpty, size } from 'lodash'; +import { get, has, isArray, isEmpty, startsWith, size } from 'lodash'; import cn from 'classnames'; import BkgImg from 'assets/icons/icon_upload.svg'; @@ -31,9 +31,10 @@ class ImgPreview extends React.Component { componentDidMount() { // We don't need the generateImgURL function here since the compo will // always have an init value here + const file = this.props.multiple ? get(this.props.files, ['0', 'name'], '') : get(this.props.files, 'name'); this.setState({ imgURL: get(this.props.files, ['0', 'url'], '') || get(this.props.files, 'url', ''), - isImg: this.isPictureType(get(this.props.files, ['0', 'name'], '')), + isImg: this.isPictureType(file), }); } @@ -142,10 +143,12 @@ class ImgPreview extends React.Component { renderContent = () => { const fileType = this.getFileType(this.state.imgURL); - + if (this.state.isImg) { + const imgURL = startsWith(this.state.imgURL, '/') ? `${strapi.backendURL}${this.state.imgURL}` : this.state.imgURL; + return ( - + ); } @@ -159,6 +162,7 @@ class ImgPreview extends React.Component { render() { const { files, onBrowseClick } = this.props; const { imgURL } = this.state; + const containerStyle = isEmpty(imgURL) ? { backgroundImage: `url(${BkgImg})`, diff --git a/packages/strapi-helper-plugin/lib/src/components/PageFooter/index.js b/packages/strapi-helper-plugin/lib/src/components/PageFooter/index.js index 898adbf6de..56053b72a4 100644 --- a/packages/strapi-helper-plugin/lib/src/components/PageFooter/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/PageFooter/index.js @@ -14,6 +14,7 @@ import GlobalPagination from 'components/GlobalPagination'; import styles from './styles.scss'; +/* eslint-disable jsx-a11y/label-has-for */ function PageFooter(props) { return (