-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mask upload to download interface
- Loading branch information
1 parent
6ef2640
commit 4802468
Showing
9 changed files
with
233 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
isimip_data/download/assets/js/components/form/widgets/Mask.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React, { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { useDropzone } from 'react-dropzone' | ||
import { isEmpty, isNil, uniqueId } from 'lodash' | ||
|
||
const Mask = ({ values, errors, onChange }) => { | ||
const fileId = uniqueId('download-form-input-file-') | ||
const maskId = uniqueId('download-form-input-mask-') | ||
const varId = uniqueId('download-form-input-var-') | ||
|
||
const [dropzoneError, setDropzoneError] = useState('') | ||
|
||
const { getRootProps, getInputProps, isDragActive } = useDropzone({ | ||
accept: { | ||
'application/x-hdf': ['.nc', '.nc4'] | ||
}, | ||
onDropAccepted: acceptedFiles => { | ||
if (acceptedFiles.length > 0) { | ||
onChange({ file: acceptedFiles[0] }) | ||
setDropzoneError('') | ||
} | ||
}, | ||
onDropRejected: rejectedFiles => { | ||
setDropzoneError(rejectedFiles.map(file => file.errors.map(error => error.message).join()).join()) | ||
} | ||
}) | ||
|
||
return ( | ||
<div> | ||
<div className="form-row"> | ||
<div className="col-lg-8"> | ||
<label className="mb-0" htmlFor={fileId}>Mask file</label> | ||
<div className={'form-control file-control mb-2 ' + ((!isEmpty(errors) || !isEmpty(dropzoneError)) && 'is-invalid')}> | ||
<div {...getRootProps({className: 'dropzone'})}> | ||
<input id={fileId} {...getInputProps()} /> | ||
<div className="file-control-inner"> | ||
{ | ||
isDragActive ? ( | ||
<p>Drop the file here ...</p> | ||
) : ( | ||
<p>Drag and drop a NetCDF mask file here, or click to select.</p> | ||
) | ||
} | ||
{ | ||
!isNil(values.file) && !isNil(values.file.name) && ( | ||
<p>Currently selected: <code>{values.file.name}</code></p> | ||
) | ||
} | ||
</div> | ||
</div> | ||
</div> | ||
{ | ||
dropzoneError && ( | ||
<div class="invalid-feedback">{dropzoneError}</div> | ||
) | ||
} | ||
</div> | ||
</div> | ||
<div className="form-row"> | ||
<div className="col-lg-4"> | ||
<label className="mb-0" htmlFor={maskId}>Mask name</label> | ||
<input className={'form-control mb-2 ' + (!isEmpty(errors) && 'is-invalid')} | ||
type="text" id={maskId} placeholder="Mask name" | ||
value={values.mask} onChange={event => onChange({ mask: event.target.value })} /> | ||
</div> | ||
<div className="col-lg-4"> | ||
<label className="mb-0" htmlFor={varId}>Mask variable</label> | ||
<input className={'form-control mb-2 ' + (!isEmpty(errors) && 'is-invalid')} | ||
type="text" id={varId} placeholder="Mask variable" | ||
value={values.var} onChange={event => onChange({ var: event.target.value })} /> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
Mask.propTypes = { | ||
values: PropTypes.object, | ||
errors: PropTypes.array, | ||
onChange: PropTypes.func.isRequired | ||
} | ||
|
||
export default Mask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.