mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Use js-utility-belt's truncateText
This commit is contained in:
parent
ec78ecb8ab
commit
de571c7fab
@ -20,8 +20,8 @@ import withContext from '../context/with_context';
|
||||
import { currentUserShape, whitelabelShape } from '../prop_types';
|
||||
|
||||
import { setDocumentTitle } from '../../utils/dom';
|
||||
import { truncateTextAtCharIndex } from '../../utils/general';
|
||||
import { getLangText } from '../../utils/lang';
|
||||
import { truncateText } from '../../utils/text';
|
||||
|
||||
|
||||
let ContractSettings = React.createClass({
|
||||
@ -105,7 +105,7 @@ let ContractSettings = React.createClass({
|
||||
<ActionPanel
|
||||
key={contract.id}
|
||||
title={contract.name}
|
||||
content={truncateTextAtCharIndex(contract.name, 120, '(...).pdf')}
|
||||
content={truncateText(contract.name, 120, '(...).pdf')}
|
||||
buttons={
|
||||
<div className="pull-right">
|
||||
<AclProxy
|
||||
@ -147,7 +147,7 @@ let ContractSettings = React.createClass({
|
||||
<ActionPanel
|
||||
key={contract.id}
|
||||
title={contract.name}
|
||||
content={truncateTextAtCharIndex(contract.name, 120, '(...).pdf')}
|
||||
content={truncateText(contract.name, 120, '(...).pdf')}
|
||||
buttons={
|
||||
<div className="pull-right">
|
||||
<AclProxy
|
||||
|
@ -6,9 +6,9 @@ import FileDragAndDropPreviewImage from './file_drag_and_drop_preview_image';
|
||||
import FileDragAndDropPreviewOther from './file_drag_and_drop_preview_other';
|
||||
|
||||
import { FileStatus } from '../react_s3_fine_uploader_utils';
|
||||
import { getLangText } from '../../../utils/lang';
|
||||
import { truncateTextAtCharIndex } from '../../../utils/general';
|
||||
import { extractFileExtensionFromString } from '../../../utils/file';
|
||||
import { getLangText } from '../../../utils/lang';
|
||||
import { truncateText } from '../../../utils/text';
|
||||
|
||||
|
||||
const { shape, string, number, func, bool } = React.PropTypes;
|
||||
@ -76,7 +76,7 @@ const FileDragAndDropPreview = React.createClass({
|
||||
if (numberOfDisplayedFiles === 1) {
|
||||
return (
|
||||
<span className="file-name">
|
||||
{truncateTextAtCharIndex(file.name, 30, '(...).' + extractFileExtensionFromString(file.name))}
|
||||
{truncateText(file.name, 30, '(...).' + extractFileExtensionFromString(file.name))}
|
||||
</span>
|
||||
);
|
||||
} else {
|
||||
|
@ -4,8 +4,8 @@ import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { displayValidProgressFilesFilter, FileStatus } from '../react_s3_fine_uploader_utils';
|
||||
import { truncateTextAtCharIndex } from '../../../utils/general';
|
||||
import { getLangText } from '../../../utils/lang';
|
||||
import { truncateText } from '../../../utils/text';
|
||||
|
||||
const { func, array, bool, shape, string } = React.PropTypes;
|
||||
|
||||
@ -127,7 +127,7 @@ export default function UploadButton({ className = 'btn btn-default btn-sm', sho
|
||||
if (uploadingFiles.length) {
|
||||
return (
|
||||
<span>
|
||||
{' ' + truncateTextAtCharIndex(uploadingFiles[0].name, 40) + ' '}
|
||||
{' ' + truncateText(uploadingFiles[0].name, 40) + ' '}
|
||||
[<a onClick={this.onClickRemove}>{getLangText('cancel upload')}</a>]
|
||||
</span>
|
||||
);
|
||||
@ -135,7 +135,7 @@ export default function UploadButton({ className = 'btn btn-default btn-sm', sho
|
||||
return (
|
||||
<span>
|
||||
<span className='ascribe-icon icon-ascribe-ok'/>
|
||||
{' ' + truncateTextAtCharIndex(uploadedFile.name, 40) + ' '}
|
||||
{' ' + truncateText(uploadedFile.name, 40) + ' '}
|
||||
[<a onClick={this.onClickRemove}>{getLangText('remove')}</a>]
|
||||
</span>
|
||||
);
|
||||
|
@ -27,23 +27,6 @@ export function escapeHTML(s) {
|
||||
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a string and breaks it at the supplied index and replaces it
|
||||
* with a (potentially) short string that also has been provided
|
||||
* @param {string} text The string to truncate
|
||||
* @param {number} charIndex The char number at which the text should be truncated
|
||||
* @param {String} replacement All text after charIndex will be replaced with this string
|
||||
* @return {string} The truncated text
|
||||
*/
|
||||
export function truncateTextAtCharIndex(text, charIndex, replacement = '...') {
|
||||
let truncatedText = '';
|
||||
|
||||
truncatedText = text.slice(0, charIndex);
|
||||
truncatedText += text.length > charIndex ? replacement : '';
|
||||
|
||||
return truncatedText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index, int, the starting index of the substring to be replaced
|
||||
* @param character, substring to be replaced
|
||||
|
@ -1,2 +1,2 @@
|
||||
// Re-export related utilities from js-utility-belt for easier access
|
||||
export { formatText, sprintf } from 'js-utility-belt/es6/text';
|
||||
export { formatText, sprintf, truncateText } from 'js-utility-belt/es6/text';
|
||||
|
Loading…
Reference in New Issue
Block a user