Skip to content

Commit

Permalink
fix(editor): allow editing of null stop times
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Nov 7, 2017
1 parent 9cd3a24 commit 6766767
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion lib/editor/components/timetable/TimetableGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,43 @@ export default class TimetableGrid extends Component {
)
}

/**
* Handle a change in the value of a cell.
*
* This function gets called with a post-processed value from the `save`
* method of EditableCell. The value can be a time value or non-time entry
* such as Trip Id or Headsign.
*/
_onCellChange = (value, rowIndex, col, colIndex) => {
const {columns, hideDepartureTimes, updateCellValue} = this.props
const {
activePattern,
columns,
data,
hideDepartureTimes,
updateCellValue
} = this.props

// determine if the value is a time entry
if (isTimeFormat(col.type)) {
// make sure stop time isn't null
const splitColKeys = col.key.split('.')
const stopTimeIdx = splitColKeys[1]
const trip = data[rowIndex]
const stopTime = trip.stopTimes[stopTimeIdx]
if (!stopTime) {
// stop time is null. Create new stop time

// get stop id from pattern
const {stopId} = activePattern.patternStops[stopTimeIdx]

// create filler stop time object
updateCellValue(
{ stopId },
rowIndex,
`${rowIndex}.stopTimes.${stopTimeIdx}`
)
}
}
updateCellValue(value, rowIndex, `${rowIndex}.${col.key}`)
// if departure times are hidden, set departure time value equal to arrival time
const nextCol = columns[colIndex + 1]
Expand Down

0 comments on commit 6766767

Please sign in to comment.