[PLT-2407] Improve ordering of uploaded attachments (#7022)
* improve ordering of uploaded attachments * use LocalizationStore.getLocale() when comparing file names
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
c973608ccb
Коммит
2c8a5ffd97
@@ -61,14 +61,16 @@ export default class FileAttachmentList extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const postFiles = [];
|
const postFiles = [];
|
||||||
|
let fileInfos = [];
|
||||||
if (this.props.fileInfos && this.props.fileInfos.length > 0) {
|
if (this.props.fileInfos && this.props.fileInfos.length > 0) {
|
||||||
for (let i = 0; i < Math.min(this.props.fileInfos.length, Constants.MAX_DISPLAY_FILES); i++) {
|
fileInfos = this.props.fileInfos.sort((a, b) => a.create_at - b.create_at);
|
||||||
const fileInfo = this.props.fileInfos[i];
|
for (let i = 0; i < Math.min(fileInfos.length, Constants.MAX_DISPLAY_FILES); i++) {
|
||||||
|
const fileInfo = fileInfos[i];
|
||||||
|
|
||||||
postFiles.push(
|
postFiles.push(
|
||||||
<FileAttachment
|
<FileAttachment
|
||||||
key={fileInfo.id}
|
key={fileInfo.id}
|
||||||
fileInfo={this.props.fileInfos[i]}
|
fileInfo={fileInfos[i]}
|
||||||
index={i}
|
index={i}
|
||||||
handleImageClick={this.handleImageClick}
|
handleImageClick={this.handleImageClick}
|
||||||
compactDisplay={this.props.compactDisplay}
|
compactDisplay={this.props.compactDisplay}
|
||||||
@@ -96,7 +98,7 @@ export default class FileAttachmentList extends React.Component {
|
|||||||
show={this.state.showPreviewModal}
|
show={this.state.showPreviewModal}
|
||||||
onModalDismissed={() => this.setState({showPreviewModal: false})}
|
onModalDismissed={() => this.setState({showPreviewModal: false})}
|
||||||
startId={this.state.startImgIndex}
|
startId={this.state.startImgIndex}
|
||||||
fileInfos={this.props.fileInfos}
|
fileInfos={fileInfos}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ export default class FilePreview extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
var previews = [];
|
var previews = [];
|
||||||
this.props.fileInfos.forEach((info) => {
|
const fileInfos = this.props.fileInfos.sort((a, b) => a.create_at - b.create_at);
|
||||||
|
fileInfos.forEach((info) => {
|
||||||
const type = Utils.getFileType(info.extension);
|
const type = Utils.getFileType(info.extension);
|
||||||
|
|
||||||
let className = 'file-preview';
|
let className = 'file-preview';
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ class FileUpload extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadFiles(files) {
|
uploadFiles(files) {
|
||||||
|
const sortedFiles = Utils.sortFilesByName(files);
|
||||||
|
|
||||||
// clear any existing errors
|
// clear any existing errors
|
||||||
this.props.onUploadError(null);
|
this.props.onUploadError(null);
|
||||||
|
|
||||||
@@ -83,9 +85,9 @@ class FileUpload extends React.Component {
|
|||||||
// keep track of how many files have been too large
|
// keep track of how many files have been too large
|
||||||
const tooLargeFiles = [];
|
const tooLargeFiles = [];
|
||||||
|
|
||||||
for (let i = 0; i < files.length && numUploads < uploadsRemaining; i++) {
|
for (let i = 0; i < sortedFiles.length && numUploads < uploadsRemaining; i++) {
|
||||||
if (files[i].size > global.mm_config.MaxFileSize) {
|
if (sortedFiles[i].size > global.mm_config.MaxFileSize) {
|
||||||
tooLargeFiles.push(files[i]);
|
tooLargeFiles.push(sortedFiles[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +95,8 @@ class FileUpload extends React.Component {
|
|||||||
const clientId = Utils.generateId();
|
const clientId = Utils.generateId();
|
||||||
|
|
||||||
const request = uploadFile(
|
const request = uploadFile(
|
||||||
files[i],
|
sortedFiles[i],
|
||||||
files[i].name,
|
sortedFiles[i].name,
|
||||||
channelId,
|
channelId,
|
||||||
clientId,
|
clientId,
|
||||||
this.fileUploadSuccess.bind(this, channelId),
|
this.fileUploadSuccess.bind(this, channelId),
|
||||||
@@ -111,7 +113,7 @@ class FileUpload extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {formatMessage} = this.props.intl;
|
const {formatMessage} = this.props.intl;
|
||||||
if (files.length > uploadsRemaining) {
|
if (sortedFiles.length > uploadsRemaining) {
|
||||||
this.props.onUploadError(formatMessage(holders.limited, {count: Constants.MAX_UPLOAD_FILES}));
|
this.props.onUploadError(formatMessage(holders.limited, {count: Constants.MAX_UPLOAD_FILES}));
|
||||||
} else if (tooLargeFiles.length > 1) {
|
} else if (tooLargeFiles.length > 1) {
|
||||||
var tooLargeFilenames = tooLargeFiles.map((file) => file.name).join(', ');
|
var tooLargeFilenames = tooLargeFiles.map((file) => file.name).join(', ');
|
||||||
|
|||||||
@@ -475,6 +475,11 @@ export function splitFileLocation(fileLocation) {
|
|||||||
return {ext, name: filename, path: filePath};
|
return {ext, name: filename, path: filePath};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sortFilesByName(files) {
|
||||||
|
const locale = LocalizationStore.getLocale();
|
||||||
|
return Array.from(files).sort((a, b) => a.name.localeCompare(b.name, locale, {numeric: true}));
|
||||||
|
}
|
||||||
|
|
||||||
export function toTitleCase(str) {
|
export function toTitleCase(str) {
|
||||||
function doTitleCase(txt) {
|
function doTitleCase(txt) {
|
||||||
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user