Skip to content

Commit

Permalink
Merge branch 'dev' into fix-routelayout-pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-cline committed Oct 25, 2023
2 parents 6ae88c5 + 5ef96bd commit 9401ba4
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 17 deletions.
1 change: 1 addition & 0 deletions __tests__/test-utils/mock-data/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const mockProject = {
updaters: null,
walkSpeed: null
},
sharedStopsConfig: null,
useCustomOsmBounds: false,
user: null
}
Expand Down
5 changes: 5 additions & 0 deletions i18n/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ components:
title: Create a new snapshot
CustomCSVForm:
numLines: "%numLines% lines."
csvInvalid: CSV invalid!
uploading: Uploading...
DatatoolsNavbar:
account: My Account
alerts: Alerts
Expand Down Expand Up @@ -972,6 +974,9 @@ components:
defaultLocation: 'Default location (lat, lng)'
defaultTimeZone: Default time zone
title: Location
sharedStops:
title: Shared Stops
placeholder: Shared stops config CSV
name: Project name
title: General
updates:
Expand Down
5 changes: 5 additions & 0 deletions i18n/german.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,9 @@ components:
localPlacesIndex:
title: Adress-Index
webhookUrl: Webhook URL
sharedStops:
title: Shared Stops
placeholder: Shared stops config CSV
location:
boundingBox: Gebiets-Grenzen (W,S,E,N)
boundingBoxPlaceHolder: min_lon, min_lat, max_lon, max_lat
Expand Down Expand Up @@ -1524,6 +1527,8 @@ components:
verfügen jedoch nicht über die erforderlichen Rechte.
CustomCSVForm:
numLines: "%numLines% lines."
csvInvalid: CSV ungültig!
uploading: Uploading...
FeedTransformationErrors:
csvMissingName: Custom CSV must have a name.
csvNameContainsTxt: Custom CSV name cannot contain .txt
Expand Down
5 changes: 5 additions & 0 deletions i18n/polish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ components:
title: Create User
CustomCSVForm:
numLines: "%numLines% lines."
csvInvalid: CSV ungültig!
uploading: Uploading...
DatatoolsNavbar:
account: Moje konto
alerts: Alerty
Expand Down Expand Up @@ -1038,6 +1040,9 @@ components:
localPlacesIndex:
title: Local Places Index
webhookUrl: Webhook URL
sharedStops:
title: Shared Stops
placeholder: Shared stops config CSV
location:
boundingBox: Bounding box (W,S,E,N)
boundingBoxPlaceHolder: min_lon, min_lat, max_lon, max_lat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Object {
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
},
Expand Down
33 changes: 31 additions & 2 deletions lib/manager/components/ProjectSettingsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { parseBounds, validationState } from '../util'
import type { Bounds, Project } from '../../types'
import type { ManagerUserState } from '../../types/reducers'

import CustomCSVForm from './transform/CustomCSVForm'

type ProjectModel = {
autoFetchFeeds?: boolean,
autoFetchHour?: number,
Expand All @@ -39,7 +41,8 @@ type ProjectModel = {
defaultTimeZone?: string,
id?: string,
name?: string,
peliasWebhookUrl?: string
peliasWebhookUrl?: string,
sharedStopsConfig?: string
}

type Props = {
Expand Down Expand Up @@ -182,8 +185,12 @@ export default class ProjectSettingsForm extends Component<Props, State> {
this.setState(update(this.state, {model: {$merge: {defaultTimeZone}}}))
}

_onChangeTextInput = ({target}: {target: HTMLInputElement}) => {
// TODO: shared type
// https://github.com/ibi-group/datatools-ui/pull/986#discussion_r1362271761
_onChangeTextInput = ({target}: {target: {name?: string, value: string}}) => {
const {name, value} = target
if (!name) return

this.setState(
update(
this.state,
Expand Down Expand Up @@ -223,6 +230,7 @@ export default class ProjectSettingsForm extends Component<Props, State> {
return Object.keys(validation).every(k => validation[k])
}

// eslint-disable-next-line complexity
render () {
const {editDisabled, showDangerZone} = this.props
const {model, validation} = this.state
Expand Down Expand Up @@ -324,6 +332,27 @@ export default class ProjectSettingsForm extends Component<Props, State> {
</ListGroupItem>
</ListGroup>
</Panel>
<Panel>
<Panel.Heading><Panel.Title componentClass='h4'>{this.messages('fields.sharedStops.title')}</Panel.Title></Panel.Heading>
<ListGroup>
<ListGroupItem>
<FormGroup>
{/* TODO: on enter, textarea should NOT submit. This causes strange behavior when
editing in the textarea
see: https://github.com/ibi-group/datatools-ui/pull/977#discussion_r1288916749 */}
<CustomCSVForm
csvData={model.sharedStopsConfig || ''}
hideSaveButton
name={'sharedStopsConfig'}
onChangeCsvData={this._onChangeTextInput}
onSaveCsvData={() => {}}
placeholder={`stop_group_id,feed_id,stop_id,is_primary\n1,1,29240,1\n1,3,4705,0`}
/>
</FormGroup>
</ListGroupItem>
</ListGroup>
</Panel>
<Panel>
<Panel.Heading><Panel.Title componentClass='h4'>{this.messages('fields.localPlacesIndex.title')}</Panel.Title></Panel.Heading>
<ListGroup>
Expand Down
3 changes: 2 additions & 1 deletion lib/manager/components/transform/AddCustomFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class AddCustomFile extends Component<TransformProps<AddCustomFil
this.props.onSave({csvData, table}, this.props.index)
}

_onChangeCsvData = (evt: SyntheticInputEvent<HTMLInputElement>) => {
_onChangeCsvData = (evt: {target: {name?: string, value: string}}) => {
const newState = {...this.state, csvData: evt.target.value}
this.setState(newState)
}
Expand Down Expand Up @@ -94,6 +94,7 @@ export default class AddCustomFile extends Component<TransformProps<AddCustomFil
inputIsSame={inputIsSame}
onChangeCsvData={this._onChangeCsvData}
onSaveCsvData={this._onSaveCsvData}
placeholder={''}
/>
</div>
)
Expand Down
70 changes: 57 additions & 13 deletions lib/manager/components/transform/CustomCSVForm.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
// @flow

import React from 'react'
// $FlowFixMe Flow is outdated
import React, { useEffect, useState } from 'react'
import { Button } from 'react-bootstrap'
import { parseString } from '@fast-csv/parse'

import { getComponentMessages } from '../../../common/util/config'

type Props = {
buttonText: string,
csvData: ?string,
headerText: string,
inputIsSame: boolean,
onChangeCsvData: (SyntheticInputEvent<HTMLInputElement>) => void,
buttonText?: string,
csvData?: ?string,
headerText?: string,
hideSaveButton?: boolean,
inputIsSame?: boolean,
name?: string,
onChangeCsvData: ({target: {name?: string, value: string}}) => void,
onSaveCsvData: () => void,
placeholder?: string,
}
const CustomCSVForm = (props: Props) => {
const { buttonText, csvData, headerText, inputIsSame, onChangeCsvData, onSaveCsvData } = props
const [errorCount, setErrorCount] = useState(0)

const {
buttonText,
csvData,
headerText,
hideSaveButton,
inputIsSame,
name,
onChangeCsvData,
onSaveCsvData,
placeholder
} = props

useEffect(() => {
setErrorCount(0)

parseString(csvData, { headers: true })
.on('error', _ => setErrorCount(errorCount + 1))
}, [csvData])

const numLines = !csvData ? 0 : csvData.split(/\r*\n/).length
const messages = getComponentMessages('CustomCSVForm')

const csvIsValid = errorCount === 0

return (
<div>
<label
Expand All @@ -30,11 +56,12 @@ const CustomCSVForm = (props: Props) => {
}}
>
{headerText}
<textarea
{numLines < 600000 && <textarea
id='csvData'
name={name}
onChange={onChangeCsvData}
placeholder={
`stop_id,stop_code,stop_name,stop_lat,stop_lon\n1234567,188390987,Broad Ave,33.98768,-87.72686`
placeholder || `stop_id,stop_code,stop_name,stop_lat,stop_lon\n1234567,188390987,Broad Ave,33.98768,-87.72686`
}
style={{
fontFamily: 'monospace',
Expand All @@ -44,18 +71,35 @@ const CustomCSVForm = (props: Props) => {
whiteSpace: 'pre',
width: '400px'
}}
value={csvData} />
value={csvData} />}
</label>
<div style={{marginBottom: '10px'}}>
<Button
<input
name='file'
type='file'
onChange={(e) => {
// TODO: use useCallback
// https://github.com/ibi-group/datatools-ui/pull/986#discussion_r1362276889
if (e.target && e.target.files.length > 0) {
onChangeCsvData({target: {name, value: messages('uploading')}})
const reader = new FileReader()
reader.onload = fileContents => {
onChangeCsvData({target: {name, value: fileContents.target.result}})
}
reader.readAsText(e.target.files[0])
}
}}
/>
{!hideSaveButton && <Button
bsSize='xsmall'
disabled={inputIsSame}
disabled={!csvIsValid || inputIsSame}
onClick={onSaveCsvData}
style={{marginRight: '5px'}}
>
{buttonText}
</Button>
</Button>}
<small>{messages('numLines').replace('%numLines%', numLines.toString())}</small>
{!csvIsValid && <small style={{paddingLeft: '1ch', color: 'red'}}>{messages('csvInvalid')}</small>}
</div>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/components/transform/ReplaceFileFromString.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class ReplaceFileFromString extends Component<TransformProps<Repl
this._updateErrors()
}

_onChangeCsvData = (evt: SyntheticInputEvent<HTMLInputElement>) => {
_onChangeCsvData = (evt: {target: {name?: string, value: string}}) => {
const newState = {csvData: evt.target.value}
this.setState(newState)
this._updateErrors(newState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -2035,6 +2036,7 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -2084,6 +2086,7 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -2223,6 +2226,7 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -2294,6 +2298,7 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -4224,6 +4229,7 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -4350,6 +4356,7 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -4435,6 +4442,7 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ exports[`lib > manager > DeploymentsPanel should render with the list of deploym
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -484,6 +485,7 @@ exports[`lib > manager > DeploymentsPanel should render with the list of deploym
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -946,6 +948,7 @@ exports[`lib > manager > DeploymentsPanel should render with the list of deploym
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -1431,6 +1434,7 @@ exports[`lib > manager > DeploymentsPanel should render with the list of deploym
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down Expand Up @@ -1843,6 +1847,7 @@ exports[`lib > manager > DeploymentsPanel should render with the list of deploym
"updaters": null,
"walkSpeed": null,
},
"sharedStopsConfig": null,
"useCustomOsmBounds": false,
"user": null,
}
Expand Down
Loading

0 comments on commit 9401ba4

Please sign in to comment.