/* * Copyright 2019 balena.io * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Drive as DrivelistDrive } from 'drivelist'; import * as _ from 'lodash'; import * as React from 'react'; import { Txt } from 'rendition'; import { default as styled } from 'styled-components'; import { getDriveImageCompatibilityStatuses, Image, } from '../../../../shared/drive-constraints'; import { bytesToClosestUnit } from '../../../../shared/units'; import { getSelectedDrives } from '../../models/selection-state'; import { ChangeButton, DetailsText, StepButton, StepNameButton, } from '../../styled-components'; import { middleEllipsis } from '../../utils/middle-ellipsis'; const TargetDetail = styled(props => )` float: ${({ float }) => float}; `; interface TargetSelectorProps { targets: any[]; disabled: boolean; openDriveSelector: () => any; reselectDrive: () => any; flashing: boolean; show: boolean; tooltip: string; image: Image; } function DriveCompatibilityWarning(props: { drive: DrivelistDrive; image: Image; }) { const compatibilityWarnings = getDriveImageCompatibilityStatuses( props.drive, props.image, ); if (compatibilityWarnings.length === 0) { return null; } const messages = _.map(compatibilityWarnings, 'message'); return ( ); } export function TargetSelector(props: TargetSelectorProps) { const targets = getSelectedDrives(); if (targets.length === 1) { const target = targets[0]; return ( <> {middleEllipsis(target.description, 20)} {!props.flashing && ( Change )} {bytesToClosestUnit(target.size)} ); } if (targets.length > 1) { const targetsTemplate = []; for (const target of targets) { targetsTemplate.push( {middleEllipsis(target.description, 14)} {bytesToClosestUnit(target.size)} , ); } return ( <> {targets.length} Targets {!props.flashing && ( Change )} {targetsTemplate} ); } return ( 0 ? -1 : 2} disabled={props.disabled} onClick={props.openDriveSelector} > Select target ); }