Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | 2x 2x 2x 2x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x | /* * Copyright 2019 Red Hat, Inc. and/or its affiliates. * * 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 { Button, ButtonVariant, Grid, GridItem, GutterSize, InputGroup, InputGroupText, Level, LevelItem, Split, SplitItem, Text, TextContent, TextVariants, } from '@patternfly/react-core'; import { MinusIcon, PlusIcon } from '@patternfly/react-icons'; import * as React from 'react'; import { connect } from 'react-redux'; import { clientOperations } from 'store/client'; import { UserViewport } from 'store/client/types'; import { demoOperations } from 'store/demo'; import { routeOperations } from 'store/route'; import { LatLng, Location, RouteWithTrack } from 'store/route/types'; import { AppState } from 'store/types'; import { DemoDropdown } from 'ui/components/DemoDropdown'; import LocationList from 'ui/components/LocationList'; import RouteMap from 'ui/components/RouteMap'; import SearchBox, { Result } from 'ui/components/SearchBox'; export const ID_CLEAR_BUTTON = 'clear-button'; export const ID_EXPORT_BUTTON = 'export-button'; export interface StateProps { distance: string; depot: Location | null; vehicleCount: number; visits: Location[]; routes: RouteWithTrack[]; isDemoLoading: boolean; boundingBox: [LatLng, LatLng] | null; userViewport: UserViewport; countryCodeSearchFilter: string[]; demoNames: string[]; } export interface DispatchProps { loadHandler: typeof demoOperations.requestDemo; clearHandler: typeof routeOperations.clearRoute; addLocationHandler: typeof routeOperations.addLocation; removeLocationHandler: typeof routeOperations.deleteLocation; addVehicleHandler: typeof routeOperations.addVehicle; removeVehicleHandler: typeof routeOperations.deleteAnyVehicle; updateViewport: typeof clientOperations.updateViewport; } const mapStateToProps = ({ plan, demo, serverInfo, userViewport }: AppState): StateProps => ({ distance: plan.distance, vehicleCount: plan.vehicles.length, depot: plan.depot, visits: plan.visits, routes: plan.routes, isDemoLoading: demo.isLoading, boundingBox: serverInfo.boundingBox, userViewport, countryCodeSearchFilter: serverInfo.countryCodes, // TODO use selector // TODO sort demos alphabetically? demoNames: (serverInfo.demos && serverInfo.demos.map(value => value.name)) || [], }); const mapDispatchToProps: DispatchProps = { loadHandler: demoOperations.requestDemo, clearHandler: routeOperations.clearRoute, addLocationHandler: routeOperations.addLocation, removeLocationHandler: routeOperations.deleteLocation, addVehicleHandler: routeOperations.addVehicle, removeVehicleHandler: routeOperations.deleteAnyVehicle, updateViewport: clientOperations.updateViewport, }; export type DemoProps = DispatchProps & StateProps; export interface DemoState { selectedId: number; } export class Demo extends React.Component<DemoProps, DemoState> { constructor(props: DemoProps) { super(props); this.state = { selectedId: NaN, }; this.handleDemoLoadClick = this.handleDemoLoadClick.bind(this); this.handleMapClick = this.handleMapClick.bind(this); this.handleSearchResultClick = this.handleSearchResultClick.bind(this); this.onSelectLocation = this.onSelectLocation.bind(this); } handleMapClick(e: any) { this.props.addLocationHandler({ ...e.latlng, description: '' }); // TODO use reverse geocoding to find address } handleSearchResultClick(result: Result) { this.props.addLocationHandler({ ...result.latLng, description: result.address }); } handleDemoLoadClick(demoName: string) { this.props.loadHandler(demoName); } onSelectLocation(id: number) { this.setState({ selectedId: id }); } render() { const { selectedId } = this.state; const { distance, depot, vehicleCount, visits, routes, demoNames, isDemoLoading, boundingBox, userViewport, countryCodeSearchFilter, addVehicleHandler, removeVehicleHandler, removeLocationHandler, clearHandler, updateViewport, } = this.props; const exportDataSet = () => { window.open(`${process.env.REACT_APP_BACKEND_URL}/dataset/export`); }; return ( // FIXME find a way to avoid these style customizations <Split gutter={GutterSize.md} style={{ overflowY: 'auto' }}> <SplitItem isFilled={false} style={{ display: 'flex', flexDirection: 'column' }} > <TextContent> <Text component={TextVariants.h1}>Demo</Text> </TextContent> <SearchBox boundingBox={boundingBox} countryCodeSearchFilter={countryCodeSearchFilter} addHandler={this.handleSearchResultClick} /> <LocationList depot={depot} visits={visits} removeHandler={removeLocationHandler} selectHandler={this.onSelectLocation} /> </SplitItem> <SplitItem isFilled={true} style={{ display: 'flex', flexDirection: 'column' }} > <Split gutter={GutterSize.md}> <SplitItem isFilled={true}> <Grid> <GridItem span={8}> <Level gutter="sm"> <LevelItem style={{ display: 'flex' }}> <Level gutter="sm"> <LevelItem> <InputGroup> <Button variant={ButtonVariant.primary} isDisabled={vehicleCount === 0} onClick={removeVehicleHandler} > <MinusIcon /> </Button> <InputGroupText readOnly> {vehicleCount} </InputGroupText> <Button variant={ButtonVariant.primary} onClick={addVehicleHandler} data-cy="demo-add-vehicle" > <PlusIcon /> </Button> </InputGroup> </LevelItem> <LevelItem>vehicles</LevelItem> </Level> </LevelItem> <LevelItem>{`${visits.length} visits`}</LevelItem> <LevelItem>{`Total travel time: ${distance}`}</LevelItem> </Level> </GridItem> <GridItem span={4} /> </Grid> </SplitItem> <SplitItem isFilled={false}> <Button id={ID_EXPORT_BUTTON} isDisabled={!depot || isDemoLoading} style={{ marginBottom: 16, marginLeft: 16 }} onClick={exportDataSet} > Export </Button> {(depot === null && ( <DemoDropdown demos={demoNames} onSelect={this.handleDemoLoadClick} /> )) || ( <Button id={ID_CLEAR_BUTTON} isDisabled={isDemoLoading} style={{ marginBottom: 16, marginLeft: 16 }} onClick={clearHandler} data-cy="demo-clear-button" > Clear </Button> )} </SplitItem> </Split> <RouteMap boundingBox={boundingBox} userViewport={userViewport} updateViewport={updateViewport} selectedId={selectedId} clickHandler={this.handleMapClick} removeHandler={removeLocationHandler} depot={depot} routes={routes} visits={visits} /> </SplitItem> </Split> ); } } export default connect( mapStateToProps, mapDispatchToProps, )(Demo); |