1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

Fix PR comments

This commit is contained in:
Brett Sun 2016-02-05 15:17:59 +01:00
parent 482fa51e9e
commit acd7c0f0a3
6 changed files with 43 additions and 48 deletions

View File

@ -191,9 +191,9 @@ let FileDragAndDrop = React.createClass({
const hasFiles = filesToUpload
.filter((file) => {
return file.status !== FileStatus.DELETED &&
file.status !== FileStatus.CANCELED &&
file.status !== FileStatus.UPLOAD_FAILED &&
file.size !== -1;
file.status !== FileStatus.CANCELED &&
file.status !== FileStatus.UPLOAD_FAILED &&
file.size !== -1;
})
.length > 0;
@ -201,7 +201,7 @@ let FileDragAndDrop = React.createClass({
let hasError = showError && errorClass && failedFiles.length > 0;
// if !== -2: triggers a FileDragAndDrop-global spinner
if(hashingProgress !== -2) {
if (hashingProgress !== -2) {
return (
<div className="file-drag-and-drop-hashing-dialog">
<p>{getLangText('Computing hash(es)... This may take a few minutes.')}</p>

View File

@ -37,7 +37,7 @@ let FileDragAndDropErrorDialog = React.createClass({
getContactUsDetail() {
return (
<div className='file-drag-and-drop-error'>
<h4>Let us help you</h4>
<h4>{getLangText('Let us help you')}</h4>
<p>{getLangText('Still having problems? Send us a message.')}</p>
{this.getRetryButton('Contact us', true)}
</div>

View File

@ -208,7 +208,7 @@ const ReactS3FineUploader = React.createClass({
messages: {
unsupportedBrowser: '<h3>' + getLangText('Upload is not functional in IE7 as IE7 has no support for CORS!') + '</h3>'
},
formatFileName: function(name){// fix maybe
formatFileName: function(name) { // fix maybe
if (name !== undefined && name.length > 26) {
name = name.slice(0, 15) + '...' + name.slice(-15);
}
@ -224,7 +224,7 @@ const ReactS3FineUploader = React.createClass({
csrfToken: getCookie(AppConstants.csrftoken),
errorState: {
manualRetryAttempt: 0,
errorClass: undefined
errorClass: null
},
uploadInProgress: false,
@ -472,19 +472,19 @@ const ReactS3FineUploader = React.createClass({
const { manualRetryAttempt } = this.state.errorState;
let matchedErrorClass;
// Use the contact us error class if they've retried a number of times
// and are still unsuccessful
if (manualRetryAttempt === RETRY_ATTEMPT_TO_SHOW_CONTACT_US) {
if ('onLine' in window.navigator && !window.navigator.onLine) {
// If the user's offline, this is definitely the most important error to show.
// TODO: use a better mechanism for checking network state, ie. offline.js
matchedErrorClass = ErrorClasses.upload.offline;
} else if (manualRetryAttempt === RETRY_ATTEMPT_TO_SHOW_CONTACT_US) {
// Use the contact us error class if they've retried a number of times
// and are still unsuccessful
matchedErrorClass = ErrorClasses.upload.contactUs;
} else {
matchedErrorClass = testErrorAgainstAll({ type, reason, xhr });
// If none found, check the internet connection
// TODO: use a better mechanism for checking network state, ie. offline.js
if ('onLine' in window.navigator && !window.navigator.onLine) {
matchedErrorClass = ErrorClasses.upload.offline;
} else {
// Otherwise, show the next error message in the queue
if (!matchedErrorClass) {
// If none found, show the next error message in the queue for upload errors
matchedErrorClass = ErrorQueueStore.getNextError('upload');
}
}
@ -1030,14 +1030,14 @@ const ReactS3FineUploader = React.createClass({
const filesToDisplay = filesToUpload.filter((file) => {
return file.status !== FileStatus.DELETED &&
file.status !== FileStatus.CANCELED &&
file.status !== FileStatus.UPLOAD_FAILED &&
file.size !== -1;
file.status !== FileStatus.CANCELED &&
file.status !== FileStatus.UPLOAD_FAILED &&
file.size !== -1;
});
if ((enableLocalHashing && !uploadMethod) || !areAssetsEditable ||
(showErrorPrompt && errorState.errorClass) ||
(!multiple && filesToDisplay.length > 0)) {
(showErrorPrompt && errorState.errorClass) ||
(!multiple && filesToDisplay.length > 0)) {
return true;
} else {
return false;
@ -1047,7 +1047,7 @@ const ReactS3FineUploader = React.createClass({
getAllowedExtensions() {
const { validation } = this.props;
if(validation && validation.allowedExtensions && validation.allowedExtensions.length > 0) {
if (validation && validation.allowedExtensions && validation.allowedExtensions.length > 0) {
return transformAllowedExtensionsToInputAcceptProp(validation.allowedExtensions);
} else {
return null;

View File

@ -1,9 +1,10 @@
'use strict';
import fineUploader from 'fineUploader';
// Re-export qq.status from FineUploader with an additional online
// state that we use to keep track of files from S3.
export const FileStatus = Object.assign(fineUploader.status, {
export const FileStatus = Object.assign({}, fineUploader.status, {
ONLINE: 'online'
});
@ -17,11 +18,11 @@ export const formSubmissionValidation = {
atLeastOneUploadedFile(files) {
files = files.filter((file) => {
return file.status !== FileStatus.DELETED &&
file.status !== FileStatus.CANCELED &&
file.status != FileStatus.UPLOADED_FAILED
file.status !== FileStatus.CANCELED &&
file.status != FileStatus.UPLOADED_FAILED
});
if (files.length > 0 && files[0].status === FileStatus.UPLOAD_SUCCESSFUL) {
if (files.length && files[0].status === FileStatus.UPLOAD_SUCCESSFUL) {
return true;
} else {
return false;
@ -35,13 +36,9 @@ export const formSubmissionValidation = {
* @return {boolean} [description]
*/
fileOptional(files) {
let uploadingFiles = files.filter((file) => file.status === FileStatus.SUBMITTING);
const uploadingFiles = files.filter((file) => file.status === FileStatus.SUBMITTING);
if (uploadingFiles.length === 0) {
return true;
} else {
return false;
}
return uploadFiles.length === 0;
}
};
@ -52,8 +49,8 @@ export const formSubmissionValidation = {
*/
export function displayValidFilesFilter(file) {
return file.status !== FileStatus.DELETED &&
file.status !== FileStatus.CANCELED &&
file.status !== FileStatus.UPLOAD_FAILED;
file.status !== FileStatus.CANCELED &&
file.status !== FileStatus.UPLOAD_FAILED;
}
/**
@ -63,8 +60,8 @@ export function displayValidFilesFilter(file) {
*/
export function displayRemovedFilesFilter(file) {
return file.status === FileStatus.DELETED ||
file.status === FileStatus.CANCELED ||
file.status === FileStatus.UPLOAD_FAILED;
file.status === FileStatus.CANCELED ||
file.status === FileStatus.UPLOAD_FAILED;
}
@ -75,9 +72,9 @@ export function displayRemovedFilesFilter(file) {
*/
export function displayValidProgressFilesFilter(file) {
return file.status !== FileStatus.DELETED &&
file.status !== FileStatus.CANCELED &&
file.status !== FileStatus.UPLOAD_FAILED &&
file.status !== FileStatus.ONLINE;
file.status !== FileStatus.CANCELED &&
file.status !== FileStatus.UPLOAD_FAILED &&
file.status !== FileStatus.ONLINE;
}
@ -93,7 +90,7 @@ export function displayValidProgressFilesFilter(file) {
*/
export function transformAllowedExtensionsToInputAcceptProp(allowedExtensions) {
// add a dot in front of the extension
let prefixedAllowedExtensions = allowedExtensions.map((ext) => '.' + ext);
const prefixedAllowedExtensions = allowedExtensions.map((ext) => '.' + ext);
// generate a comma separated list to add them to the DOM element
// See: http://stackoverflow.com/questions/4328947/limit-file-format-when-using-input-type-file

View File

@ -179,7 +179,7 @@ function getPrettifiedError(error, errorClass) {
* @return {(object)} Matched error class
*/
function testErrorAgainstAll(error) {
const type = error.type != null ? error.type : 'default';
const type = error.type || 'default';
const errorGroup = ErrorClasses[type];
return Object
@ -198,7 +198,8 @@ function testErrorAgainstAll(error) {
* @return {(object)} Returns the given class if the test succeeds.
*/
function testErrorAgainstClass(error, errorClass) {
// Automatically fail classes if no tests present
// Automatically fail classes if no tests present, since some of the error classes
// may not have an error to test against.
if (!errorClass.test) {
return;
}

View File

@ -223,15 +223,12 @@ export function omitFromObject(obj, filter) {
* By default, applies strict equality using ===
* @return {boolean} True if obj matches the "match" object
*/
export function deepMatchObject(obj, match, testFn) {
export function deepMatchObject(obj, match, testFn = (objProp, matchProp) => objProp === matchProp) {
if (typeof match !== 'object') {
throw new Error('Your specified match argument was not an object');
}
if (typeof testFn !== 'function') {
testFn = (objProp, matchProp) => {
return objProp === matchProp;
};
throw new Error('Your specified test function was not a function');
}
return Object
@ -239,7 +236,7 @@ export function deepMatchObject(obj, match, testFn) {
.reduce((result, matchKey) => {
if (!result) { return false; }
const objProp = obj[matchKey];
const objProp = obj && obj[matchKey];
const matchProp = match[matchKey];
if (typeof matchProp === 'object') {