Refinment: truncate in middle

This commit is contained in:
Cássio Zen 2016-06-07 21:27:34 -03:00
parent d5da853db1
commit 327cb883ee
2 changed files with 8 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import React from 'react';
import { truncateMiddle } from '../../lib/textHelper';
import ImageProxy from '../../valueObjects/ImageProxy';
const MAX_DISPLAY_LENGTH = 50;
@ -71,11 +72,11 @@ export default class ImageControl extends React.Component {
renderImageName() {
if (!this.state.currentImage) return null;
if (this.state.currentImage.uri.length < MAX_DISPLAY_LENGTH) {
return this.state.currentImage.uri;
const { uri } = this.state.currentImage;
if (uri.length <= MAX_DISPLAY_LENGTH) {
return uri;
}
return this.state.currentImage.uri.substring(0, MAX_DISPLAY_LENGTH) + '\u2026';
return truncateMiddle(uri, MAX_DISPLAY_LENGTH);
}
render() {

3
src/lib/textHelper.js Normal file
View File

@ -0,0 +1,3 @@
export function truncateMiddle(string, size) {
return string.substring(0, size / 2) + '\u2026' + string.substring(string.length - size / 2 + 1, string.length);
}