From 6766767c8746d62ef29d02102345c3fda4454153 Mon Sep 17 00:00:00 2001 From: Evan Siroky Date: Mon, 6 Nov 2017 17:25:24 -0800 Subject: [PATCH] fix(editor): allow editing of null stop times --- .../components/timetable/TimetableGrid.js | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/editor/components/timetable/TimetableGrid.js b/lib/editor/components/timetable/TimetableGrid.js index ff0dcaf05..8d0ec2ca2 100644 --- a/lib/editor/components/timetable/TimetableGrid.js +++ b/lib/editor/components/timetable/TimetableGrid.js @@ -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]