diff --git a/src/components/Widgets/ImageControl.js b/src/components/Widgets/ImageControl.js index 8c05ce94..5ca73aa7 100644 --- a/src/components/Widgets/ImageControl.js +++ b/src/components/Widgets/ImageControl.js @@ -72,11 +72,7 @@ export default class ImageControl extends React.Component { renderImageName() { if (!this.state.currentImage) return null; - const { uri } = this.state.currentImage; - if (uri.length <= MAX_DISPLAY_LENGTH) { - return uri; - } - return truncateMiddle(uri, MAX_DISPLAY_LENGTH); + return truncateMiddle(this.state.currentImage.uri, MAX_DISPLAY_LENGTH); } render() { diff --git a/src/lib/textHelper.js b/src/lib/textHelper.js index 4fd0649a..39ffd31a 100644 --- a/src/lib/textHelper.js +++ b/src/lib/textHelper.js @@ -1,3 +1,6 @@ -export function truncateMiddle(string, size) { +export function truncateMiddle(string = '', size) { + if (string.length <= size) { + return string; + } return string.substring(0, size / 2) + '\u2026' + string.substring(string.length - size / 2 + 1, string.length); }