Skip to content

Commit

Permalink
match server data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed May 15, 2024
1 parent aabc35b commit fc342df
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 129 deletions.
2 changes: 1 addition & 1 deletion lib/editor/actions/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function getCloneProps (entityId: number, component: string, state: AppState) {
patternId: newPatternId,
shapeId: newShapeId,
shapePoints: pattern.shapePoints.map(sp => ({...sp, shapeId: newShapeId})),
patternLocationGroups: pattern.patternLocationGroups && pattern.patternLocationGroups.map(plg => ({...plg, patternId: newPatternId})),
patternLocationGroupStops: pattern.patternLocationGroupStops && pattern.patternLocationGroupStops.map(plg => ({...plg, patternId: newPatternId})),
patternLocations: pattern.patternLocations.map(pl => ({...pl, patternId: newPatternId})),
patternStops: pattern.patternStops.map(ps => ({...ps, patternId: newPatternId}))
}
Expand Down
12 changes: 6 additions & 6 deletions lib/editor/actions/map/stopStrategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,17 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop | GtfsLocatio
const {data, editSettings} = getState().editor
const {avoidMotorways, followStreets} = editSettings.present
const {
patternLocationGroups: currentPatternLocationGroups,
patternLocationGroupStops: currentpatternLocationGroupStops,
patternLocations: currentPatternLocations,
patternStops: currentPatternStops,
shapePoints
} = pattern
const patternLocations = clone(currentPatternLocations)
const patternLocationGroups = clone(currentPatternLocationGroups)
const patternLocationGroupStops = clone(currentpatternLocationGroupStops)
const patternStops = clone(currentPatternStops)
const {controlPoints, patternSegments} = getControlPoints(getState())
const hasShapePoints = shapePoints && shapePoints.length > 1
let patternHalts = mergePatternHalts(patternStops, patternLocations, patternLocationGroups)
let patternHalts = mergePatternHalts(patternStops, patternLocations, patternLocationGroupStops)
const newStop = stopToPatternStop(
stop,
(typeof index === 'undefined' || index === null)
Expand All @@ -259,15 +259,15 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop | GtfsLocatio
patternStops.push(patternHaltIsStop(newStop))
pattern.shapeId = generateUID()
}
if (patternHaltIsLocationGroup(newStop)) patternLocationGroups.push(patternHaltIsLocationGroup(newStop))
if (patternHaltIsLocationGroup(newStop)) patternLocationGroupStops.push(patternHaltIsLocationGroup(newStop))
if (patternHaltIsLocation(newStop)) patternLocations.push(patternHaltIsLocation(newStop))

if (typeof index === 'undefined' || index === null || index === patternHalts.length) {
// Checking for stop_lat and stop_lon is how we check if we are dealing with
// a stop or a location
if (hasShapePoints && !!stop.stop_lat && !!stop.stop_lon) {
// Push pattern stop to cloned list.
patternHalts = mergePatternHalts(patternStops, patternLocations, patternLocationGroups)
patternHalts = mergePatternHalts(patternStops, patternLocations, patternLocationGroupStops)

// console.log('extending pattern to new stop', stop)
// If a pattern shape already exists, extend it from the current end
Expand All @@ -289,7 +289,7 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop | GtfsLocatio
})
} else {
// Push pattern location to cloned list.
patternHalts = mergePatternHalts(patternStops, patternLocations, patternLocationGroups)
patternHalts = mergePatternHalts(patternStops, patternLocations, patternLocationGroupStops)

dispatch(updatePatternStops(pattern, patternHalts))
// Only a stop should be checked, not a location
Expand Down
4 changes: 2 additions & 2 deletions lib/editor/actions/tripPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function updatePatternStops (
{
component: 'trippattern',
entity: pattern,
props: { patternStops: stops, patternLocations: locations, patternLocationGroups: locationGroups }
props: { patternStops: stops, patternLocations: locations, patternLocationGroupStops: locationGroups }
}
)
)
Expand Down Expand Up @@ -216,7 +216,7 @@ export function saveTripPattern (feedId: ?string, tripPattern: Pattern) {
// $FlowFixMe FLEX TODO: this type check looks good, but flow is complaining? why?
tripPattern.patternLocations = patternHalts.filter(patternHaltIsLocation)
// $FlowFixMe FLEX TODO: this type check looks good, but flow is complaining? why?
tripPattern.patternLocationGroups = patternHalts.filter(patternHaltIsLocationGroup)
tripPattern.patternLocationGroupStops = patternHalts.filter(patternHaltIsLocationGroup)
if (!tripPattern.shapeId && tripPattern.shapePoints && tripPattern.shapePoints.length > 0) {
// If trip pattern has no shape ID (e.g., if the pattern was imported
// without shapes) but it does have shape points, generate a new shape ID
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/components/GtfsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ type Props = ContainerProps & {
activeEntity: Entity,
activeEntityId: number,
activePattern: Pattern,
activePatternLocationGroups: Array<GtfsLocation>,
activePatternLocations: Array<GtfsLocation>,
activePatternStops: Array<GtfsStop>,
activeSubSubEntity: string,
activepatternLocationGroupStops: Array<GtfsLocation>,
addStopAtIntersection: typeof stopStrategiesActions.addStopAtIntersection,
addStopAtInterval: typeof stopStrategiesActions.addStopAtIntersection,
addStopAtPoint: typeof stopStrategiesActions.addStopAtPoint,
Expand Down
4 changes: 2 additions & 2 deletions lib/editor/components/map/EditorMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type Props = {
activeEntity: Entity,
activeEntityId: number,
activePattern: Pattern,
activePatternLocationGroups: Array<GtfsLocation>,
activePatternLocations: Array<GtfsLocation>,
activePatternStops: Array<GtfsStop>,
activepatternLocationGroupStops: Array<GtfsLocation>,
addStopAtIntersection: typeof stopStrategiesActions.addStopAtIntersection,
addStopAtInterval: typeof stopStrategiesActions.addStopAtInterval,
addStopAtPoint: typeof stopStrategiesActions.addStopAtPoint,
Expand Down Expand Up @@ -336,7 +336,7 @@ export default class EditorMap extends Component<Props, State> {
/>
<PatternStopsLayer
activePattern={activePattern}
activePatternLocationGroups={this.props.activePatternLocationGroups}
activepatternLocationGroupStops={this.props.activepatternLocationGroupStops}
activePatternLocations={this.props.activePatternLocations}
activePatternStops={this.props.activePatternStops}
addStopToPattern={addStopToPattern}
Expand Down
22 changes: 11 additions & 11 deletions lib/editor/components/map/PatternStopsLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import PatternLocationMarker from './PatternLocationMarker'

type Props = {
activePattern: Pattern,
activePatternLocationGroups: Array<GtfsLocation>,
activePatternLocations: Array<GtfsLocation>,
activePatternStops: Array<GtfsStop>,
activepatternLocationGroupStops: Array<GtfsLocation>,
addStopToPattern: typeof stopStrategiesActions.addStopToPattern,
controlPoints: Array<ControlPoint>,
editSettings: EditSettingsState,
Expand All @@ -41,7 +41,7 @@ export default class PatternStopsLayer extends Component<Props> {
render () {
const {
activePattern,
activePatternLocationGroups,
activepatternLocationGroupStops,
activePatternLocations,
activePatternStops,
addStopToPattern,
Expand All @@ -60,12 +60,12 @@ export default class PatternStopsLayer extends Component<Props> {
if (!activePatternStops || !activePattern || !editSettings.showStops) {
return null
}
const {patternLocations, patternLocationGroups, patternStops} = activePattern
const {patternLocations, patternLocationGroupStops, patternStops} = activePattern

const activeStopNotFound = activePatternStop &&
patternStops.findIndex(ps => ps.id === activePatternStop.id) === -1 &&
patternLocations.findIndex(pl => pl.id === activePatternStop.id) === -1 &&
patternLocationGroups.findIndex(plg => plg.id === activePatternStop.id) === -1
patternLocationGroupStops.findIndex(plg => plg.id === activePatternStop.id) === -1
let cpIndex = 0
let psIndex = 0
const patternStopsWithControlPointIndexes = []
Expand All @@ -85,10 +85,10 @@ export default class PatternStopsLayer extends Component<Props> {
if (cpIndex < patternStops.length) {
console.warn(`Fewer control points (${controlPoints.length}) than pattern stops (${patternStops.length})!`, controlPoints, patternStops)
}
const patternHalts = mergePatternHalts(patternStopsWithControlPointIndexes, patternLocations, patternLocationGroups)
const patternHalts = mergePatternHalts(patternStopsWithControlPointIndexes, patternLocations, patternLocationGroupStops)
return (
<div id='PatternStops'>
{activePatternLocationGroups.map((locationGroup, index) => {
{activepatternLocationGroupStops.map((locationGroup, index) => {
if (!locationGroup.location_id || locationGroup.location_id.length === 0) return null
const halts = typeof locationGroup.location_id === 'string' ? locationGroup.location_id.split(',') : locationGroup.location_id
const activeHalts = halts.reduce((acc, halt) => {
Expand All @@ -103,7 +103,7 @@ export default class PatternStopsLayer extends Component<Props> {
}

return acc
}, {stops: [], locations: [], id: patternLocationGroups[index].id})
}, {stops: [], locations: [], id: patternLocationGroupStops[index].id})
// Render stops and locations separately, but fix the index and patternStop
// to be a location group so that when you click it it opens the location group
// also, disable the buttons in the popup
Expand All @@ -114,9 +114,9 @@ export default class PatternStopsLayer extends Component<Props> {
{...otherProps}
active={activePatternStop.id === activeHalts.id || (activeStopNotFound && activePatternStop.index === index)}
addStopToPattern={addStopToPattern}
index={patternLocationGroups[index].stopSequence}
index={patternLocationGroupStops[index].stopSequence}
key={stop.id} // fallback to index if/when id changes
patternStop={patternLocationGroups[index]}
patternStop={patternLocationGroupStops[index]}
removeStopFromPattern={removeStopFromPattern}
setActiveStop={setActiveStop}
stop={stop}
Expand All @@ -129,10 +129,10 @@ export default class PatternStopsLayer extends Component<Props> {
{...otherProps}
active={activePatternStop.id === activeHalts.id || (activeStopNotFound && activePatternStop.index === index)}
addStopToPattern={addStopToPattern}
index={patternLocationGroups[index].stopSequence}
index={patternLocationGroupStops[index].stopSequence}
key={location.id} // fallback to index if/when id changes
location={location}
patternLocation={patternLocationGroups[index]}
patternLocation={patternLocationGroupStops[index]}
removeStopFromPattern={removeStopFromPattern}
setActiveStop={setActiveStop}
/>
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/components/pattern/CalculateDefaultTimesForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class CalculateDefaultTimesForm extends Component<Props, State> {
}
}
}
updatePatternStops(activePattern, [...activePattern.patternLocations, ...activePattern.patternLocationGroups, ...patternStops])
updatePatternStops(activePattern, [...activePattern.patternLocations, ...activePattern.patternLocationGroupStops, ...patternStops])
saveActiveGtfsEntity('trippattern')
}

Expand Down
60 changes: 0 additions & 60 deletions lib/editor/components/pattern/PatternStopCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ type State = {
flexDefaultZoneTime: number,
initialDwellTime: number,
initialTravelTime: number,
meanDurationFactor: number,
meanDurationOffset: number,
safeDurationFactor: number,
safeDurationOffset: number,
update: boolean
}

Expand Down Expand Up @@ -320,14 +316,6 @@ class PatternStopContents extends Component<Props, State> {
flexDefaultZoneTime: patternStop.flexDefaultZoneTime,
// $FlowFixMe flow doesn't like our "type check"
flexDefaultTravelTime: patternStop.flexDefaultTravelTime,
// $FlowFixMe flow doesn't like our "type check"
meanDurationFactor: patternStop.meanDurationFactor,
// $FlowFixMe flow doesn't like our "type check"
meanDurationOffset: patternStop.meanDurationOffset,
// $FlowFixMe flow doesn't like our "type check"
safeDurationFactor: patternStop.safeDurationFactor,
// $FlowFixMe flow doesn't like our "type check"
safeDurationOffset: patternStop.safeDurationOffset,
update: false
})
}
Expand Down Expand Up @@ -662,54 +650,6 @@ class PatternStopContents extends Component<Props, State> {
</Col>
</Row>
{this._renderPickupDropOffTypes(true)}
<Row>
<Col xs={6}>
<FormGroup controlId='meanDurationFactor'>
<ControlLabel className='small'>{patternStopCardMessages('PatternStopContents.meanDurationFactor')}</ControlLabel>
<FormControl
onChange={this._onNumberFieldChange}
type='number'
// $FlowFixMe: Flow doesn't recognize type checks
value={patternStop.meanDurationFactor}
/>
</FormGroup>
</Col>
<Col xs={6}>
<FormGroup controlId='meanDurationOffset'>
<ControlLabel className='small'>{patternStopCardMessages('PatternStopContents.meanDurationOffset')}</ControlLabel>
<FormControl
onChange={this._onNumberFieldChange}
type='number'
// $FlowFixMe: Flow doesn't recognize type checks
value={patternStop.meanDurationOffset}
/>
</FormGroup>
</Col>
</Row>
<Row>
<Col xs={6}>
<FormGroup controlId='safeDurationFactor'>
<ControlLabel className='small'>{patternStopCardMessages('PatternStopCardMessages.safeDurationFactor')}</ControlLabel>
<FormControl
onChange={this._onNumberFieldChange}
type='number'
// $FlowFixMe: Flow doesn't recognize type checks
value={patternStop.safeDurationFactor}
/>
</FormGroup>
</Col>
<Col xs={6}>
<FormGroup controlId='safeDurationOffset'>
<ControlLabel className='small'>{patternStopCardMessages('PatternStopCardMessages.safeDurationOffset')}</ControlLabel>
<FormControl
onChange={this._onNumberFieldChange}
type='number'
// $FlowFixMe: Flow doesn't recognize type checks
value={patternStop.safeDurationOffset}
/>
</FormGroup>
</Col>
</Row>
{bookingRuleRow}
</div>
)
Expand Down
6 changes: 3 additions & 3 deletions lib/editor/components/pattern/PatternStopsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ export default class PatternStopsPanel extends Component<Props, State> {
const {patternStopCandidate} = this.state
const patternHasStops = (activePattern.patternStops &&
activePattern.patternStops.length > 0) || (activePattern.patternLocations &&
activePattern.patternLocations.length > 0) || (activePattern.patternLocationGroups &&
activePattern.patternLocationGroups.length > 0)
activePattern.patternLocations.length > 0) || (activePattern.patternLocationGroupStops &&
activePattern.patternLocationGroupStops.length > 0)

const patternHaltCount = (activePattern.patternStops.length || 0) + (activePattern.patternLocations.length || 0) + (activePattern.patternLocationGroups.length || 0)
const patternHaltCount = (activePattern.patternStops.length || 0) + (activePattern.patternLocations.length || 0) + (activePattern.patternLocationGroupStops.length || 0)
return (
<div>
<NormalizeStopTimesModal
Expand Down
6 changes: 3 additions & 3 deletions lib/editor/components/pattern/TripPatternList.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class PatternRow extends Component<RowProps> {

render () {
const {active, pattern} = this.props
const {name, patternLocations, patternLocationGroups, patternStops} = pattern
const {name, patternLocations, patternLocationGroupStops, patternStops} = pattern
const rowStyle = {
paddingTop: 5,
paddingBottom: 5
Expand All @@ -161,11 +161,11 @@ class PatternRow extends Component<RowProps> {
}
let patternName = '[Unnamed]'
if (name) {
const showStopCount = patternStops || patternLocations || patternLocationGroups
const showStopCount = patternStops || patternLocations || patternLocationGroupStops
const stopCount = showStopCount ? (
(patternStops ? patternStops.length : 0) +
(patternLocations ? patternLocations.length : 0) +
(patternLocationGroups ? patternLocationGroups.length : 0)
(patternLocationGroupStops ? patternLocationGroupStops.length : 0)
) : 0
patternName = `${`${name.length > 29
? name.substr(0, 29) + '…'
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/components/pattern/TripPatternListControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class TripPatternListControls extends Component<Props> {
directionId: null,
patternStops: [],
patternLocations: [],
patternLocationGroups: [],
patternLocationGroupStops: [],
name: 'New Pattern',
// FIXME should we be using some other method to generate ID?
patternId: generateUID(),
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/components/pattern/TripPatternViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class TripPatternViewer extends Component<Props> {
if (!activePattern) return null

activePattern.patternLocations = activePattern.patternLocations.map(pl => { return {...pl, id: `${pl.locationId}${pl.stopSequence}`} })
activePattern.patternLocationGroups = activePattern.patternLocationGroups.map(plg => { return {...plg, id: `${plg.locationGroupId}${plg.stopSequence}`} })
activePattern.patternLocationGroupStops = activePattern.patternLocationGroupStops.map(plg => { return {...plg, id: `${plg.locationGroupId}${plg.stopSequence}`} })
activePattern.patternStops = activePattern.patternStops.map(ps => { return {...ps, id: `${ps.stopId}${ps.stopSequence}`} })
return (
<div>
Expand Down
5 changes: 0 additions & 5 deletions lib/editor/components/timetable/TimetableEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,6 @@ export default class TimetableEditor extends Component<Props, State> {
objectPath.set(newRow, `stopTimes.${i}.timepoint`, halt.timepoint || 0)
objectPath.set(newRow, `stopTimes.${i}.stopHeadsign`, halt.stopHeadsign)
objectPath.set(newRow, `stopTimes.${i}.shapeDistTraveled`, halt.shapeDistTraveled)
// set some new flex fields (null for traditional stops)
objectPath.set(newRow, `stopTimes.${i}.meanDurationFactor`, halt.meanDurationFactor || null)
objectPath.set(newRow, `stopTimes.${i}.meanDurationOffset`, halt.meanDurationOffset || null)
objectPath.set(newRow, `stopTimes.${i}.safeDurationFactor`, halt.safeDurationFactor || null)
objectPath.set(newRow, `stopTimes.${i}.safeDurationOffset`, halt.safeDurationOffset || null)
// Use pattern stop index to set stop sequence. Stop sequences should all
// be zero-based and incrementing in the editor, but in the case that
// they're not (e.g., due to a bad import) simply default to the index.
Expand Down
Loading

0 comments on commit fc342df

Please sign in to comment.