@@ -271,8 +271,43 @@ export default class TimetableGrid extends Component {
271271 )
272272 }
273273
274+ /**
275+ * Handle a change in the value of a cell.
276+ *
277+ * This function gets called with a post-processed value from the `save`
278+ * method of EditableCell. The value can be a time value or non-time entry
279+ * such as Trip Id or Headsign.
280+ */
274281 _onCellChange = ( value , rowIndex , col , colIndex ) => {
275- const { columns, hideDepartureTimes, updateCellValue} = this . props
282+ const {
283+ activePattern,
284+ columns,
285+ data,
286+ hideDepartureTimes,
287+ updateCellValue
288+ } = this . props
289+
290+ // determine if the value is a time entry
291+ if ( isTimeFormat ( col . type ) ) {
292+ // make sure stop time isn't null
293+ const splitColKeys = col . key . split ( '.' )
294+ const stopTimeIdx = splitColKeys [ 1 ]
295+ const trip = data [ rowIndex ]
296+ const stopTime = trip . stopTimes [ stopTimeIdx ]
297+ if ( ! stopTime ) {
298+ // stop time is null. Create new stop time
299+
300+ // get stop id from pattern
301+ const { stopId} = activePattern . patternStops [ stopTimeIdx ]
302+
303+ // create filler stop time object
304+ updateCellValue (
305+ { stopId } ,
306+ rowIndex ,
307+ `${ rowIndex } .stopTimes.${ stopTimeIdx } `
308+ )
309+ }
310+ }
276311 updateCellValue ( value , rowIndex , `${ rowIndex } .${ col . key } ` )
277312 // if departure times are hidden, set departure time value equal to arrival time
278313 const nextCol = columns [ colIndex + 1 ]
0 commit comments