Move inputFile ref to WriteDataForm

pull/10616/head
Andrew Watkins 2017-06-22 15:50:03 -07:00
parent 870deff124
commit 734a54708c
2 changed files with 46 additions and 46 deletions

View File

@ -10,53 +10,48 @@ const WriteDataBody = ({
uploadContent, uploadContent,
fileName, fileName,
isManual, isManual,
}) => { fileInput,
let inputRef handleFileOpen,
}) => (
return ( <div className="write-data-form--body">
<div className="write-data-form--body"> {isManual
{isManual ? <textarea
? <textarea className="form-control write-data-form--input"
className="form-control write-data-form--input" autoComplete="off"
autoComplete="off" spellCheck="false"
spellCheck="false" placeholder="<measurement>,<tag_key>=<tag_value> <field_key>=<field_value>"
placeholder="<measurement>,<tag_key>=<tag_value> <field_key>=<field_value>" onKeyUp={handleKeyUp}
onKeyUp={handleKeyUp} onChange={handleEdit}
onChange={handleEdit} autoFocus={true}
autoFocus={true} />
: <div className="write-data-form--file">
<input
type="file"
onChange={e => handleFile(e, false)}
className="write-data-form--upload"
ref={fileInput}
accept="text/*, application/gzip"
/> />
: <div className="write-data-form--file"> <button className="btn btn-sm btn-primary" onClick={handleFileOpen}>
<input {uploadContent ? 'Upload a Different File' : 'Upload a File'}
type="file" </button>
onChange={e => handleFile(e, false)} {uploadContent
className="write-data-form--upload" ? <span className="write-data-form--filepath_selected">
ref={r => (inputRef = r)} <span className="icon checkmark" />
accept="text/*, application/gzip" {fileName}
/> </span>
<button : <span className="write-data-form--filepath_empty">
className="btn btn-sm btn-primary" No file selected
onClick={() => inputRef.click()} </span>}
> </div>}
{uploadContent ? 'Upload a Different File' : 'Upload a File'} <WriteDataFooter
</button> isManual={isManual}
{uploadContent inputContent={inputContent}
? <span className="write-data-form--filepath_selected"> handleSubmit={handleSubmit}
<span className="icon checkmark" /> uploadContent={uploadContent}
{fileName} />
</span> </div>
: <span className="write-data-form--filepath_empty"> )
No file selected
</span>}
</div>}
<WriteDataFooter
isManual={isManual}
inputContent={inputContent}
handleSubmit={handleSubmit}
uploadContent={uploadContent}
/>
</div>
)
}
const {func, string, bool} = PropTypes const {func, string, bool} = PropTypes
@ -69,6 +64,8 @@ WriteDataBody.propTypes = {
uploadContent: string, uploadContent: string,
fileName: string, fileName: string,
isManual: bool, isManual: bool,
fileInput: func.isRequired,
handleFileOpen: func.isRequired,
} }
export default WriteDataBody export default WriteDataBody

View File

@ -27,6 +27,7 @@ class WriteDataForm extends Component {
this.handleEdit = ::this.handleEdit this.handleEdit = ::this.handleEdit
this.handleFile = ::this.handleFile this.handleFile = ::this.handleFile
this.toggleWriteView = ::this.toggleWriteView this.toggleWriteView = ::this.toggleWriteView
this.handleFileOpen = ::this.handleFileOpen
} }
toggleWriteView(isManual) { toggleWriteView(isManual) {
@ -139,10 +140,12 @@ class WriteDataForm extends Component {
/> />
<WriteDataBody <WriteDataBody
{...this.state} {...this.state}
fileInput={el => this.fileInput = el}
handleEdit={this.handleEdit} handleEdit={this.handleEdit}
handleFile={this.handleFile} handleFile={this.handleFile}
handleKeyUp={this.handleKeyUp} handleKeyUp={this.handleKeyUp}
handleSubmit={this.handleSubmit} handleSubmit={this.handleSubmit}
handleFileOpen={this.handleFileOpen}
/> />
</div> </div>
<div className="write-data-form--drag-here"> <div className="write-data-form--drag-here">