1
0
mirror of https://github.com/ascribe/onion.git synced 2025-02-14 21:10:27 +01:00

Allow warnings to be set from inside properties to change appearance

This commit is contained in:
Brett Sun 2015-12-08 18:23:02 +01:00
parent 79780cfb3a
commit 5bc447ecc8
4 changed files with 40 additions and 10 deletions

View File

@ -25,6 +25,7 @@ const InputFineUploader = React.createClass({
// Props for ReactS3FineUploader // Props for ReactS3FineUploader
areAssetsDownloadable: bool, areAssetsDownloadable: bool,
setWarning: func,
showErrorPrompt: bool, showErrorPrompt: bool,
handleChangedFile: func, // TODO: rename to onChangedFile handleChangedFile: func, // TODO: rename to onChangedFile
@ -122,6 +123,7 @@ const InputFineUploader = React.createClass({
fileClassToUpload, fileClassToUpload,
uploadMethod, uploadMethod,
handleChangedFile, handleChangedFile,
setWarning,
showErrorPrompt, showErrorPrompt,
disabled } = this.props; disabled } = this.props;
let editable = isFineUploaderActive; let editable = isFineUploaderActive;
@ -144,6 +146,7 @@ const InputFineUploader = React.createClass({
isReadyForFormSubmission={isReadyForFormSubmission} isReadyForFormSubmission={isReadyForFormSubmission}
areAssetsDownloadable={areAssetsDownloadable} areAssetsDownloadable={areAssetsDownloadable}
areAssetsEditable={editable} areAssetsEditable={editable}
setWarning={setWarning}
showErrorPrompt={showErrorPrompt} showErrorPrompt={showErrorPrompt}
signature={{ signature={{
endpoint: AppConstants.serverUrl + 's3/signature/', endpoint: AppConstants.serverUrl + 's3/signature/',

View File

@ -71,7 +71,8 @@ const Property = React.createClass({
initialValue: null, initialValue: null,
value: null, value: null,
isFocused: false, isFocused: false,
errors: null errors: null,
hasWarning: false
}; };
}, },
@ -209,17 +210,20 @@ const Property = React.createClass({
this.setState({errors: null}); this.setState({errors: null});
}, },
setWarning(hasWarning) {
this.setState({ hasWarning });
},
getClassName() { getClassName() {
if(!this.state.expanded && !this.props.checkboxLabel){ if (!this.state.expanded && !this.props.checkboxLabel) {
return 'is-hidden'; return 'is-hidden';
} } else if (!this.props.editable) {
if(!this.props.editable){
return 'is-fixed'; return 'is-fixed';
} } else if (this.state.errors) {
if (this.state.errors){
return 'is-error'; return 'is-error';
} } else if (this.state.hasWarning) {
if(this.state.isFocused) { return 'is-warning';
} else if (this.state.isFocused) {
return 'is-focused'; return 'is-focused';
} else { } else {
return ''; return '';
@ -245,6 +249,7 @@ const Property = React.createClass({
onChange: this.handleChange, onChange: this.handleChange,
onFocus: this.handleFocus, onFocus: this.handleFocus,
onBlur: this.handleBlur, onBlur: this.handleBlur,
setWarning: this.setWarning,
disabled: !this.props.editable, disabled: !this.props.editable,
ref: 'input', ref: 'input',
name: this.props.name name: this.props.name

View File

@ -8,10 +8,13 @@ import S3Fetcher from '../../fetchers/s3_fetcher';
import FileDragAndDrop from './ascribe_file_drag_and_drop/file_drag_and_drop'; import FileDragAndDrop from './ascribe_file_drag_and_drop/file_drag_and_drop';
import ErrorQueueStore from '../../stores/error_queue_store';
import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions'; import GlobalNotificationActions from '../../actions/global_notification_actions';
import AppConstants from '../../constants/application_constants'; import AppConstants from '../../constants/application_constants';
import { ErrorClasses, testErrorAgainstAll } from '../../constants/error_constants';
import { displayValidFilesFilter, FileStatus, transformAllowedExtensionsToInputAcceptProp } from './react_s3_fine_uploader_utils'; import { displayValidFilesFilter, FileStatus, transformAllowedExtensionsToInputAcceptProp } from './react_s3_fine_uploader_utils';
import { computeHashOfFile } from '../../utils/file_utils'; import { computeHashOfFile } from '../../utils/file_utils';
@ -31,12 +34,16 @@ const { shape,
element, element,
arrayOf } = React.PropTypes; arrayOf } = React.PropTypes;
// After 5 manual retries, show the contact us prompt.
const RETRY_ATTEMPT_TO_SHOW_CONTACT_US = 5;
const ReactS3FineUploader = React.createClass({ const ReactS3FineUploader = React.createClass({
propTypes: { propTypes: {
areAssetsDownloadable: bool, areAssetsDownloadable: bool,
areAssetsEditable: bool, areAssetsEditable: bool,
errorNotificationMessage: string, errorNotificationMessage: string,
showErrorPrompt: bool, showErrorPrompt: bool,
setWarning: func, // for when the parent component wants to be notified of uploader warnings (ie. upload failed)
handleChangedFile: func, // for when a file is dropped or selected, TODO: rename to onChangedFile handleChangedFile: func, // for when a file is dropped or selected, TODO: rename to onChangedFile
submitFile: func, // for when a file has been successfully uploaded, TODO: rename to onSubmitFile submitFile: func, // for when a file has been successfully uploaded, TODO: rename to onSubmitFile
@ -301,6 +308,9 @@ const ReactS3FineUploader = React.createClass({
// proclaim that upload is not ready // proclaim that upload is not ready
this.props.setIsUploadReady(false); this.props.setIsUploadReady(false);
// reset any warnings propagated to parent
this.setWarning(false);
// reset internal data structures of component // reset internal data structures of component
this.setState(this.getInitialState()); this.setState(this.getInitialState());
}, },
@ -423,6 +433,12 @@ const ReactS3FineUploader = React.createClass({
} }
}, },
setWarning(hasWarning) {
if (typeof this.props.setWarning === 'function') {
this.props.setWarning(hasWarning);
}
},
checkFormSubmissionReady() { checkFormSubmissionReady() {
const { isReadyForFormSubmission, setIsUploadReady } = this.props; const { isReadyForFormSubmission, setIsUploadReady } = this.props;
@ -597,6 +613,7 @@ const ReactS3FineUploader = React.createClass({
}); });
this.setState({ errorState }); this.setState({ errorState });
this.setWarning(true);
} }
} else { } else {
notificationMessage = errorReason || errorNotificationMessage; notificationMessage = errorReason || errorNotificationMessage;
@ -766,6 +783,8 @@ const ReactS3FineUploader = React.createClass({
}, },
filesToUpload filesToUpload
}); });
this.setWarning(false);
}, },
handleUploadFile(files) { handleUploadFile(files) {

View File

@ -38,7 +38,6 @@ $ascribe-red-error: rgb(169, 68, 66);
} }
} }
> input, > input,
> textarea { > textarea {
color: #666; color: #666;
@ -50,6 +49,10 @@ $ascribe-red-error: rgb(169, 68, 66);
} }
} }
.is-warning {
border-left: 3px solid $ascribe-pink
}
.is-fixed { .is-fixed {
cursor: default; cursor: default;