Refactor Warning modal in image selection

This commit is contained in:
Lucian 2019-12-03 17:35:33 +00:00 committed by Alexis Svinartchouk
parent 641dde81e5
commit 00536cba3a
3 changed files with 55 additions and 28 deletions

View File

@ -44,8 +44,23 @@ const {
ChangeButton, ChangeButton,
ThemedProvider ThemedProvider
} = require('../../styled-components') } = require('../../styled-components')
const {
Modal
} = require('rendition')
const middleEllipsis = require('../../utils/middle-ellipsis') const middleEllipsis = require('../../utils/middle-ellipsis')
const SVGIcon = require('../svg-icon/svg-icon.jsx') const SVGIcon = require('../svg-icon/svg-icon.jsx')
const { default: styled } = require('styled-components')
// TODO move these styles to rendition
const ModalText = styled.p `
a {
color: rgb(0, 174, 239);
&:hover {
color: rgb(0, 139, 191);
}
}
`
/** /**
* @summary Main supported extensions * @summary Main supported extensions
@ -82,7 +97,10 @@ class ImageSelector extends React.Component {
constructor (props) { constructor (props) {
super(props) super(props)
this.state = getState() this.state = {
...getState(),
warning: null
}
this.openImageSelector = this.openImageSelector.bind(this) this.openImageSelector = this.openImageSelector.bind(this)
this.reselectImage = this.reselectImage.bind(this) this.reselectImage = this.reselectImage.bind(this)
@ -110,10 +128,6 @@ class ImageSelector extends React.Component {
} }
selectImage (image) { selectImage (image) {
const {
WarningModalService
} = this.props
if (!supportedFormats.isSupportedImage(image.path)) { if (!supportedFormats.isSupportedImage(image.path)) {
const invalidImageError = errors.createUserError({ const invalidImageError = errors.createUserError({
title: 'Invalid image', title: 'Invalid image',
@ -130,6 +144,7 @@ class ImageSelector extends React.Component {
Bluebird.try(() => { Bluebird.try(() => {
let message = null let message = null
let title = null
if (supportedFormats.looksLikeWindowsImage(image.path)) { if (supportedFormats.looksLikeWindowsImage(image.path)) {
analytics.logEvent('Possibly Windows image', { analytics.logEvent('Possibly Windows image', {
@ -138,31 +153,30 @@ class ImageSelector extends React.Component {
flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid
}) })
message = messages.warning.looksLikeWindowsImage() message = messages.warning.looksLikeWindowsImage()
title = 'Possible Windows image detected'
} else if (!image.hasMBR) { } else if (!image.hasMBR) {
analytics.logEvent('Missing partition table', { analytics.logEvent('Missing partition table', {
image, image,
applicationSessionUuid: store.getState().toJS().applicationSessionUuid, applicationSessionUuid: store.getState().toJS().applicationSessionUuid,
flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid
}) })
title = 'Missing partition table'
message = messages.warning.missingPartitionTable() message = messages.warning.missingPartitionTable()
} }
if (message) { if (message) {
// TODO: `Continue` should be on a red background (dangerous action) instead of `Change`. this.setState({
// We want `X` to act as `Continue`, that's why `Continue` is the `rejectionLabel` warning: {
return WarningModalService.display({ message,
confirmationLabel: 'Change', title
rejectionLabel: 'Continue', }
description: message
}) })
return
} }
return false return false
}).then((shouldChange) => { }).then(() => {
if (shouldChange) {
return this.reselectImage()
}
selectionState.selectImage(image) selectionState.selectImage(image)
// An easy way so we can quickly identify if we're making use of // An easy way so we can quickly identify if we're making use of
@ -338,6 +352,29 @@ class ImageSelector extends React.Component {
</div> </div>
)} )}
</Dropzone> </Dropzone>
{Boolean(this.state.warning) && (
<Modal
title={(
<span>
<span style={{ color: '#d9534f' }} className="glyphicon glyphicon-exclamation-sign"></span>
{' '}
<span>{this.state.warning.title}</span>
</span>
)}
action='Continue'
cancel={() => {
this.setState({ warning: null })
this.reselectImage()
}}
done={() => {
this.setState({ warning: null })
}}
primaryButtonProps={{ warning: true, primary: false }}
>
<ModalText dangerouslySetInnerHTML={{ __html: this.state.warning.message }} />
</Modal>
)}
</ThemedProvider> </ThemedProvider>
) )
} }

View File

@ -227,11 +227,6 @@ img[disabled] {
position: relative; position: relative;
} }
body.rendition-modal-open > div:last-child > div > div > div:last-child {
top: unset;
bottom: -200px;
}
#app-logo { #app-logo {
position: fixed; position: fixed;
left: 0; left: 0;

View File

@ -6368,9 +6368,8 @@ svg-icon {
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
img[disabled] { img[disabled] {
opacity: 0.2; opacity: 0.2; }
}
.page-main { .page-main {
flex: 1; flex: 1;
@ -6537,10 +6536,6 @@ svg-icon {
.space-vertical-large { .space-vertical-large {
position: relative; } position: relative; }
body.rendition-modal-open > div:last-child > div > div > div:last-child {
top: unset;
bottom: -200px; }
#app-logo { #app-logo {
position: fixed; position: fixed;
left: 0; left: 0;