This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Add modal for uploading/resetting manifest in UI #36
Merged
mzazrivec
merged 10 commits into
RedHatCloudForms:master
from
mturley:manifest-upload-ui-changes
Jan 28, 2020
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3492260
Factor out manifest version display into a new component
mturley d290633
Add placeholder ManifestUpdateModal
mturley cc449a0
Add current versions to modal
mturley b594504
Add spinner for updating manifest state
mturley 24200fa
Add Dropzone for file upload
mturley c37ab33
Connect upload/reset actions to API
mturley 0f53b2a
Handle loading and error states
mturley 1863c05
Use explicit boolean on modal toggle action
mturley 3bb7436
Update snapshots
mturley 640aae8
fix missing gettext call
mturley File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
66 changes: 66 additions & 0 deletions
66
app/javascript/react/screens/App/Analytics/components/ManifestUpdateModal.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,66 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Modal, Grid, Button, noop } from 'patternfly-react'; | ||
import Dropzone from 'react-dropzone'; | ||
import { readFirstFile } from './helpers'; | ||
|
||
const ManifestUpdateModal = ({ onClose, manifestInfo, uploadManifestAction, resetManifestAction, ...otherProps }) => ( | ||
<Modal {...otherProps} onHide={onClose} backdrop="static" className="manifest-update-modal"> | ||
<Dropzone onDrop={files => readFirstFile(files, file => uploadManifestAction(file.body))}> | ||
{({ getRootProps, getInputProps, open: openFileBrowser }) => ( | ||
<div {...getRootProps()} onClick={event => event.preventDefault()}> | ||
<input {...getInputProps()} /> | ||
<Modal.Header> | ||
<Modal.CloseButton onClick={onClose} /> | ||
<Modal.Title>{__('Update Manifest')}</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<Grid.Row className="show-grid"> | ||
<Grid.Col xs={6} className="text-right"> | ||
{__('Current manifest version')}: | ||
</Grid.Col> | ||
<Grid.Col xs={6}>{manifestInfo.manifest_version}</Grid.Col> | ||
</Grid.Row> | ||
<Grid.Row className="show-grid"> | ||
<Grid.Col xs={6} className="text-right"> | ||
{__('Default manifest version')}: | ||
</Grid.Col> | ||
<Grid.Col xs={6}>{manifestInfo.default_manifest_version}</Grid.Col> | ||
</Grid.Row> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button bsStyle="default" onClick={resetManifestAction} disabled={manifestInfo.using_default_manifest}> | ||
{__('Restore default manifest')} | ||
</Button> | ||
<Button bsStyle="default" onClick={openFileBrowser}> | ||
{__('Upload new manifest')} | ||
</Button> | ||
<Button bsStyle="primary" className="btn-cancel" onClick={onClose}> | ||
{__('Close')} | ||
</Button> | ||
</Modal.Footer> | ||
</div> | ||
)} | ||
</Dropzone> | ||
</Modal> | ||
); | ||
|
||
ManifestUpdateModal.propTypes = { | ||
onClose: PropTypes.func, | ||
manifestInfo: PropTypes.shape({ | ||
manifest_version: PropTypes.string, | ||
default_manifest_version: PropTypes.string, | ||
using_default_manifest: PropTypes.bool | ||
}), | ||
uploadManifestAction: PropTypes.func, | ||
resetManifestAction: PropTypes.func | ||
}; | ||
|
||
ManifestUpdateModal.defaultProps = { | ||
onClose: noop, | ||
manifestInfo: {}, | ||
uploadManifestAction: noop, | ||
resetManifestAction: noop | ||
}; | ||
|
||
export default ManifestUpdateModal; |
73 changes: 73 additions & 0 deletions
73
app/javascript/react/screens/App/Analytics/components/ManifestVersion.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,73 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Button, Icon, Spinner, noop } from 'patternfly-react'; | ||
import ManifestUpdateModal from './ManifestUpdateModal'; | ||
|
||
const ManifestVersion = ({ | ||
manifestInfo, | ||
isLoadingManifest, | ||
manifestError, | ||
manifestUpdateModalVisible, | ||
toggleManifestUpdateModalAction, | ||
uploadManifestAction, | ||
resetManifestAction, | ||
...otherProps | ||
}) => | ||
manifestInfo && ( | ||
<React.Fragment> | ||
<h6 id="migration-analytics-manifest-version" {...otherProps}> | ||
{!isLoadingManifest ? ( | ||
<React.Fragment> | ||
{__('Manifest version:')} | ||
| ||
{manifestInfo.manifest_version} | ||
| ||
<Button bsStyle="link" bsSize="xsmall" onClick={() => toggleManifestUpdateModalAction(true)}> | ||
{__('Update')} | ||
</Button> | ||
</React.Fragment> | ||
) : ( | ||
<span className="manifest-loading-message"> | ||
{__('Loading manifest...')} | ||
<Spinner inline size="xs" loading /> | ||
</span> | ||
)} | ||
{manifestError && manifestError.message && ( | ||
<span className="manifest-error-message"> | ||
<Icon type="pf" name="error-circle-o" size="sm" /> {manifestError.message} | ||
</span> | ||
)} | ||
</h6> | ||
<ManifestUpdateModal | ||
show={manifestUpdateModalVisible} | ||
onClose={() => toggleManifestUpdateModalAction(false)} | ||
manifestInfo={manifestInfo} | ||
uploadManifestAction={uploadManifestAction} | ||
resetManifestAction={resetManifestAction} | ||
/> | ||
</React.Fragment> | ||
); | ||
|
||
ManifestVersion.propTypes = { | ||
manifestInfo: PropTypes.shape({ | ||
manifest_version: PropTypes.string | ||
}), | ||
isLoadingManifest: PropTypes.bool, | ||
manifestError: PropTypes.shape({ message: PropTypes.string }), | ||
manifestUpdateModalVisible: PropTypes.bool, | ||
toggleManifestUpdateModalAction: PropTypes.func, | ||
uploadManifestAction: PropTypes.func, | ||
resetManifestAction: PropTypes.func | ||
}; | ||
|
||
ManifestVersion.defaultProps = { | ||
manifestInfo: null, | ||
isLoadingManifest: false, | ||
manifestError: null, | ||
manifestUpdateModalVisible: false, | ||
toggleManifestUpdateModalAction: noop, | ||
uploadManifestAction: noop, | ||
resetManifestAction: noop | ||
}; | ||
|
||
export default ManifestVersion; |
7 changes: 7 additions & 0 deletions
7
app/javascript/react/screens/App/Analytics/components/helpers.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,7 @@ | ||
export const readFirstFile = (fileHandles, onLoad) => { | ||
if (fileHandles && fileHandles.length > 0) { | ||
const reader = new FileReader(); | ||
reader.onload = () => onLoad({ filename: fileHandles[0].name, body: reader.result }); | ||
reader.readAsBinaryString(fileHandles[0]); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,14 +1,31 @@ | ||
import { connect } from 'react-redux'; | ||
import Analytics from './Analytics'; | ||
import { fetchManifestInfoAction } from './redux/analyticsActions'; | ||
import { | ||
fetchManifestInfoAction, | ||
toggleManifestUpdateModalAction, | ||
uploadManifestAction, | ||
resetManifestAction | ||
} from './redux/analyticsActions'; | ||
|
||
const mapStateToProps = ({ | ||
migrationAnalytics: { | ||
analytics: { manifestInfo } | ||
analytics: { | ||
manifestInfo, | ||
manifestUpdateModalVisible, | ||
isFetchingManifestInfo, | ||
isChangingManifest, | ||
errorFetchingManifestInfo, | ||
errorChangingManifest | ||
} | ||
} | ||
}) => ({ manifestInfo }); | ||
}) => ({ | ||
manifestInfo, | ||
manifestUpdateModalVisible, | ||
isLoadingManifest: isFetchingManifestInfo || isChangingManifest, | ||
manifestError: errorFetchingManifestInfo || errorChangingManifest | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
{ fetchManifestInfoAction } | ||
{ fetchManifestInfoAction, toggleManifestUpdateModalAction, uploadManifestAction, resetManifestAction } | ||
)(Analytics); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the
Selected file is not a valid manifest
string should be enclosed in gettext as well.