Refactor UI grid to use rendition

Change-type: patch
Changelog-entry: Refactor UI grid to use rendition
Signed-off-by: Lorenzo Alberto Maria Ambrosi <lorenzothunder.ambrosi@gmail.com>
This commit is contained in:
Lorenzo Alberto Maria Ambrosi 2020-06-12 13:14:16 +02:00
parent 72e5631167
commit 9b71772e35
7 changed files with 195 additions and 221 deletions

View File

@ -84,7 +84,9 @@ export class ProgressButton extends React.PureComponent<ProgressButtonProps> {
return ( return (
<> <>
<Flex <Flex
alignItems="baseline"
justifyContent="space-between" justifyContent="space-between"
width="100%"
style={{ style={{
marginTop: 42, marginTop: 42,
marginBottom: '6px', marginBottom: '6px',

View File

@ -22,7 +22,14 @@ import * as _ from 'lodash';
import { GPTPartition, MBRPartition } from 'partitioninfo'; import { GPTPartition, MBRPartition } from 'partitioninfo';
import * as path from 'path'; import * as path from 'path';
import * as React from 'react'; import * as React from 'react';
import { ButtonProps, Card as BaseCard, Input, Modal, Txt } from 'rendition'; import {
ButtonProps,
Card as BaseCard,
Input,
Modal,
Txt,
Flex,
} from 'rendition';
import styled from 'styled-components'; import styled from 'styled-components';
import * as errors from '../../../../shared/errors'; import * as errors from '../../../../shared/errors';
@ -464,25 +471,22 @@ export class SourceSelector extends React.Component<
return ( return (
<> <>
<div <Flex
className="box text-center relative" flexDirection="column"
alignItems="center"
onDrop={this.onDrop} onDrop={this.onDrop}
onDragEnter={this.onDragEnter} onDragEnter={this.onDragEnter}
onDragOver={this.onDragOver} onDragOver={this.onDragOver}
> >
<div className="center-block">
<SVGIcon <SVGIcon
contents={imageLogo} contents={imageLogo}
fallback={<ImageSvg width="40px" height="40px" />} fallback={<ImageSvg width="40px" />}
/> />
</div>
<div className="space-vertical-large">
{hasImage ? ( {hasImage ? (
<> <>
<StepNameButton <StepNameButton
plain plain
fontSize={16}
onClick={this.showSelectedImageDetails} onClick={this.showSelectedImageDetails}
tooltip={imageName || imageBasename} tooltip={imageName || imageBasename}
> >
@ -493,9 +497,7 @@ export class SourceSelector extends React.Component<
Remove Remove
</ChangeButton> </ChangeButton>
)} )}
<DetailsText> <DetailsText>{shared.bytesToClosestUnit(imageSize)}</DetailsText>
{shared.bytesToClosestUnit(imageSize)}
</DetailsText>
</> </>
) : ( ) : (
<> <>
@ -517,8 +519,7 @@ export class SourceSelector extends React.Component<
/> />
</> </>
)} )}
</div> </Flex>
</div>
{this.state.warning != null && ( {this.state.warning != null && (
<Modal <Modal

View File

@ -118,7 +118,7 @@ export function TargetSelector(props: TargetSelectorProps) {
} }
return ( return (
<> <>
<StepNameButton plain tooltip={props.tooltip} fontSize={16}> <StepNameButton plain tooltip={props.tooltip}>
{targets.length} Targets {targets.length} Targets
</StepNameButton> </StepNameButton>
{!props.flashing && ( {!props.flashing && (

View File

@ -16,8 +16,7 @@
import { scanner } from 'etcher-sdk'; import { scanner } from 'etcher-sdk';
import * as React from 'react'; import * as React from 'react';
import styled from 'styled-components'; import { Flex } from 'rendition';
import { TargetSelector } from '../../components/target-selector/target-selector-button'; import { TargetSelector } from '../../components/target-selector/target-selector-button';
import { TargetSelectorModal } from '../../components/target-selector/target-selector-modal'; import { TargetSelectorModal } from '../../components/target-selector/target-selector-modal';
import { import {
@ -30,27 +29,8 @@ import {
import * as settings from '../../models/settings'; import * as settings from '../../models/settings';
import { observe } from '../../models/store'; import { observe } from '../../models/store';
import * as analytics from '../../modules/analytics'; import * as analytics from '../../modules/analytics';
import DriveSvg from '../../../assets/drive.svg'; import DriveSvg from '../../../assets/drive.svg';
const StepBorder = styled.div<{
disabled: boolean;
left?: boolean;
right?: boolean;
}>`
height: 2px;
background-color: ${(props) =>
props.disabled
? props.theme.colors.dark.disabled.foreground
: props.theme.colors.dark.foreground};
position: absolute;
width: 124px;
top: 19px;
left: ${(props) => (props.left ? '-67px' : undefined)};
right: ${(props) => (props.right ? '-67px' : undefined)};
`;
const getDriveListLabel = () => { const getDriveListLabel = () => {
return getSelectedDrives() return getSelectedDrives()
.map((drive: any) => { .map((drive: any) => {
@ -100,17 +80,13 @@ export const selectAllTargets = (
}; };
interface DriveSelectorProps { interface DriveSelectorProps {
webviewShowing: boolean;
disabled: boolean; disabled: boolean;
nextStepDisabled: boolean;
hasDrive: boolean; hasDrive: boolean;
flashing: boolean; flashing: boolean;
} }
export const DriveSelector = ({ export const DriveSelector = ({
webviewShowing,
disabled, disabled,
nextStepDisabled,
hasDrive, hasDrive,
flashing, flashing,
}: DriveSelectorProps) => { }: DriveSelectorProps) => {
@ -129,22 +105,10 @@ export const DriveSelector = ({
}); });
}, []); }, []);
const showStepConnectingLines = !webviewShowing || !flashing;
return ( return (
<div className="box text-center relative"> <Flex flexDirection="column" alignItems="center">
{showStepConnectingLines && (
<>
<StepBorder disabled={disabled} left />
<StepBorder disabled={nextStepDisabled} right />
</>
)}
<div className="center-block">
<DriveSvg className={disabled ? 'disabled' : ''} width="40px" /> <DriveSvg className={disabled ? 'disabled' : ''} width="40px" />
</div>
<div className="space-vertical-large">
<TargetSelector <TargetSelector
disabled={disabled} disabled={disabled}
show={!hasDrive && showDrivesButton} show={!hasDrive && showDrivesButton}
@ -160,7 +124,6 @@ export const DriveSelector = ({
targets={targets} targets={targets}
image={image} image={image}
/> />
</div>
{showTargetSelectorModal && ( {showTargetSelectorModal && (
<TargetSelectorModal <TargetSelectorModal
@ -171,6 +134,6 @@ export const DriveSelector = ({
}} }}
></TargetSelectorModal> ></TargetSelectorModal>
)} )}
</div> </Flex>
); );
}; };

View File

@ -234,15 +234,12 @@ export class FlashStep extends React.PureComponent<
public render() { public render() {
return ( return (
<> <>
<div className="box text-center"> <Flex flexDirection="column" alignItems="center">
<div className="center-block">
<FlashSvg <FlashSvg
width="40px" width="40px"
className={this.props.shouldFlashStepBeDisabled ? 'disabled' : ''} className={this.props.shouldFlashStepBeDisabled ? 'disabled' : ''}
/> />
</div>
<div className="space-vertical-large">
<ProgressButton <ProgressButton
type={this.props.step} type={this.props.step}
active={this.props.isFlashing} active={this.props.isFlashing}
@ -265,6 +262,7 @@ export class FlashStep extends React.PureComponent<
justifyContent="space-between" justifyContent="space-between"
fontSize="14px" fontSize="14px"
color="#7e8085" color="#7e8085"
width="100%"
> >
{!_.isNil(this.props.speed) && ( {!_.isNil(this.props.speed) && (
<Txt>{this.props.speed.toFixed(SPEED_PRECISION)} MB/s</Txt> <Txt>{this.props.speed.toFixed(SPEED_PRECISION)} MB/s</Txt>
@ -288,8 +286,7 @@ export class FlashStep extends React.PureComponent<
</div> </div>
</div> </div>
)} )}
</div> </Flex>
</div>
{this.state.warningMessages.length > 0 && ( {this.state.warningMessages.length > 0 && (
<Modal <Modal

View File

@ -78,6 +78,26 @@ function getImageBasename() {
return selectionImageName || imageBasename; return selectionImageName || imageBasename;
} }
const StepBorder = styled.div<{
disabled: boolean;
left?: boolean;
right?: boolean;
}>`
position: relative;
height: 2px;
background-color: ${(props) =>
props.disabled
? props.theme.colors.dark.disabled.foreground
: props.theme.colors.dark.foreground};
width: 120px;
top: 19px;
left: ${(props) => (props.left ? '-67px' : undefined)};
margin-right: ${(props) => (props.left ? '-120px' : undefined)};
right: ${(props) => (props.right ? '-67px' : undefined)};
margin-left: ${(props) => (props.right ? '-120px' : undefined)};
`;
interface MainPageStateFromStore { interface MainPageStateFromStore {
isFlashing: boolean; isFlashing: boolean;
hasImage: boolean; hasImage: boolean;
@ -193,46 +213,37 @@ export class MainPage extends React.Component<
/> />
)} )}
<Flex <Flex m="110px 55px" justifyContent="space-between">
className="page-main row around-xs"
style={{ margin: '110px 50px' }}
>
<div className="col-xs">
<SourceSelector <SourceSelector
flashing={this.state.isFlashing} flashing={this.state.isFlashing}
afterSelected={(source: SourceOptions) => afterSelected={(source: SourceOptions) => this.setState({ source })}
this.setState({ source })
}
/> />
</div>
<div className="col-xs"> {(!this.state.isWebviewShowing || !this.state.isFlashing) && (
<Flex>
<StepBorder disabled={shouldDriveStepBeDisabled} left />
</Flex>
)}
<DriveSelector <DriveSelector
webviewShowing={this.state.isWebviewShowing}
disabled={shouldDriveStepBeDisabled} disabled={shouldDriveStepBeDisabled}
nextStepDisabled={shouldFlashStepBeDisabled}
hasDrive={this.state.hasDrive} hasDrive={this.state.hasDrive}
flashing={this.state.isFlashing} flashing={this.state.isFlashing}
/> />
</div>
{this.state.isFlashing && ( {(!this.state.isWebviewShowing || !this.state.isFlashing) && (
<div <Flex>
className={`featured-project ${ <StepBorder disabled={shouldFlashStepBeDisabled} right />
this.state.isFlashing && this.state.isWebviewShowing </Flex>
? 'fp-visible' )}
: ''
}`} {this.state.isFlashing && this.state.isWebviewShowing && (
> <>
<FeaturedProject <FeaturedProject
onWebviewShow={(isWebviewShowing: boolean) => { onWebviewShow={(isWebviewShowing: boolean) => {
this.setState({ isWebviewShowing }); this.setState({ isWebviewShowing });
}} }}
/> />
</div>
)}
<div>
<ReducedFlashingInfos <ReducedFlashingInfos
imageLogo={this.state.imageLogo} imageLogo={this.state.imageLogo}
imageName={middleEllipsis(this.state.imageName, 16)} imageName={middleEllipsis(this.state.imageName, 16)}
@ -242,11 +253,13 @@ export class MainPage extends React.Component<
: '' : ''
} }
driveTitle={middleEllipsis(this.state.driveTitle, 16)} driveTitle={middleEllipsis(this.state.driveTitle, 16)}
shouldShow={this.state.isFlashing && this.state.isWebviewShowing} shouldShow={
this.state.isFlashing && this.state.isWebviewShowing
}
/> />
</div> </>
)}
<div className="col-xs">
<FlashStep <FlashStep
goToSuccess={() => this.setState({ current: 'success' })} goToSuccess={() => this.setState({ current: 'success' })}
shouldFlashStepBeDisabled={shouldFlashStepBeDisabled} shouldFlashStepBeDisabled={shouldFlashStepBeDisabled}
@ -259,7 +272,6 @@ export class MainPage extends React.Component<
speed={state.speed} speed={state.speed}
eta={state.eta} eta={state.eta}
/> />
</div>
</Flex> </Flex>
</> </>
); );

View File

@ -54,7 +54,6 @@ export const StepButton = styled((props: ButtonProps) => (
<BaseButton {...props}></BaseButton> <BaseButton {...props}></BaseButton>
))` ))`
color: #ffffff; color: #ffffff;
margin: auto;
`; `;
export const ChangeButton = styled(Button)` export const ChangeButton = styled(Button)`