From 00536cba3aea1a59c2ce595d9b1fabaade0ecff9 Mon Sep 17 00:00:00 2001 From: Lucian Date: Tue, 3 Dec 2019 17:35:33 +0000 Subject: [PATCH] Refactor Warning modal in image selection --- .../image-selector/image-selector.jsx | 69 ++++++++++++++----- lib/gui/app/pages/main/styles/_main.scss | 5 -- lib/gui/css/main.css | 9 +-- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/lib/gui/app/components/image-selector/image-selector.jsx b/lib/gui/app/components/image-selector/image-selector.jsx index aac1ee6c..2f29ec2f 100644 --- a/lib/gui/app/components/image-selector/image-selector.jsx +++ b/lib/gui/app/components/image-selector/image-selector.jsx @@ -44,8 +44,23 @@ const { ChangeButton, ThemedProvider } = require('../../styled-components') +const { + Modal +} = require('rendition') const middleEllipsis = require('../../utils/middle-ellipsis') 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 @@ -82,7 +97,10 @@ class ImageSelector extends React.Component { constructor (props) { super(props) - this.state = getState() + this.state = { + ...getState(), + warning: null + } this.openImageSelector = this.openImageSelector.bind(this) this.reselectImage = this.reselectImage.bind(this) @@ -110,10 +128,6 @@ class ImageSelector extends React.Component { } selectImage (image) { - const { - WarningModalService - } = this.props - if (!supportedFormats.isSupportedImage(image.path)) { const invalidImageError = errors.createUserError({ title: 'Invalid image', @@ -130,6 +144,7 @@ class ImageSelector extends React.Component { Bluebird.try(() => { let message = null + let title = null if (supportedFormats.looksLikeWindowsImage(image.path)) { analytics.logEvent('Possibly Windows image', { @@ -138,31 +153,30 @@ class ImageSelector extends React.Component { flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid }) message = messages.warning.looksLikeWindowsImage() + title = 'Possible Windows image detected' } else if (!image.hasMBR) { analytics.logEvent('Missing partition table', { image, applicationSessionUuid: store.getState().toJS().applicationSessionUuid, flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid }) + title = 'Missing partition table' message = messages.warning.missingPartitionTable() } if (message) { - // TODO: `Continue` should be on a red background (dangerous action) instead of `Change`. - // We want `X` to act as `Continue`, that's why `Continue` is the `rejectionLabel` - return WarningModalService.display({ - confirmationLabel: 'Change', - rejectionLabel: 'Continue', - description: message + this.setState({ + warning: { + message, + title + } }) + + return } return false - }).then((shouldChange) => { - if (shouldChange) { - return this.reselectImage() - } - + }).then(() => { selectionState.selectImage(image) // An easy way so we can quickly identify if we're making use of @@ -338,6 +352,29 @@ class ImageSelector extends React.Component { )} + + {Boolean(this.state.warning) && ( + + + {' '} + {this.state.warning.title} + + )} + action='Continue' + cancel={() => { + this.setState({ warning: null }) + this.reselectImage() + }} + done={() => { + this.setState({ warning: null }) + }} + primaryButtonProps={{ warning: true, primary: false }} + > + + + )} ) } diff --git a/lib/gui/app/pages/main/styles/_main.scss b/lib/gui/app/pages/main/styles/_main.scss index 6f078b59..6f1d4c27 100644 --- a/lib/gui/app/pages/main/styles/_main.scss +++ b/lib/gui/app/pages/main/styles/_main.scss @@ -227,11 +227,6 @@ img[disabled] { position: relative; } -body.rendition-modal-open > div:last-child > div > div > div:last-child { - top: unset; - bottom: -200px; -} - #app-logo { position: fixed; left: 0; diff --git a/lib/gui/css/main.css b/lib/gui/css/main.css index 64af877f..716eeda4 100644 --- a/lib/gui/css/main.css +++ b/lib/gui/css/main.css @@ -6368,9 +6368,8 @@ svg-icon { * See the License for the specific language governing permissions and * limitations under the License. */ - img[disabled] { - opacity: 0.2; -} +img[disabled] { + opacity: 0.2; } .page-main { flex: 1; @@ -6537,10 +6536,6 @@ svg-icon { .space-vertical-large { position: relative; } -body.rendition-modal-open > div:last-child > div > div > div:last-child { - top: unset; - bottom: -200px; } - #app-logo { position: fixed; left: 0;