Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing GTFS Extended Route Types #656

Merged
merged 20 commits into from
Feb 25, 2022

Conversation

robertgregg3
Copy link
Contributor

@robertgregg3 robertgregg3 commented Apr 8, 2021

  • Added the route types to the gtfs.yml file
  • and then added logic to display the route_type field as an optgroup
  • Create a new selector for GTFS route types, with extended route types organized as a tree hierarchy (bus, metro, etc) that is not expanded by default to reduce screen clutter while searching for extended route types.

Fix #645

Added the route types to the GTFS.yml file and then added logic to display the route_type field in
an optgroup

#645
@@ -300,6 +300,8 @@ export default class EditorInput extends Component<Props> {
</span>
)
case 'DROPDOWN':
const standard = 'Standard'
const extended = 'Extended'
return (
Copy link
Contributor

@landonreed landonreed Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix the flow type issues and simplify things, I would add something like the following:

if (!field.options) {
  console.warn(`Field `field.name` does not have options configured, but is marked as inputType=DROPDOWN`)
  return null
}

Then, you should be able to remove the field.options && ... checks on lines 315 and 330.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you see the flow issues? When I load the project (before typing any code, I get these kind of squigglies from the beginning of the render method:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run flow status I get an error:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow errors are showing up in the GitHub builds: https://github.com/ibi-group/datatools-ui/pull/656/checks?check_run_id=2298915284

Locally, you should run yarn flow.

@@ -290,6 +290,156 @@
text: Gondola
- value: 7
text: Funicular
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add options 11 and 12 (they were recently added to the standard set)? See the spec for routes.txt: https://developers.google.com/transit/gtfs/reference#routestxt for more info

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

@landonreed landonreed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few changes, but this is looking good!

@landonreed landonreed assigned robertgregg3 and unassigned landonreed Apr 8, 2021
gtfs.yml Outdated
Comment on lines 293 to 294
- value: 100
text: Railway Service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this value duplicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot. And there was a word missing. Going to check the rest now.

{field.options && field.options.map(o => (<option value={o.value} key={o.value}>{o.text || o.value}</option>))}
{field.name === 'route_type' &&
<optgroup label={standard}>
{field.options.slice(0, 7).map(o => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because o shows up so many times, I would write .map(({ text, value }) => { ..., and maybe also extract the <optgroup> rendering to its own method because of repetition.

Added a group option to the gtfs route types options. Added method to render the route type options.

#656
@robertgregg3
Copy link
Contributor Author

I have added:

  • a group option in the gtfs file
  • added a _renderRouteTypeOptions method to dynamically render the opt groups depending on the group value (Standard or Extended)

Copy link
Contributor

@landonreed landonreed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robertgregg3, what prompted the addition of the group field in gtfs.yml? I'm not sure it's needed, given that we effectively know that types 0-12 are standard and those after are extended. I liked the way you had handled it previously.

Also, Trolleybus (11) and Monorail (12) should probably be in standard and moved up in the list. These are currently shown as extended (800 and 405), but I think that's probably just because the extended list has not been updated. We could keep them both, but that might be confusing.

Copy link
Contributor

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, see how the simplification suggestion would work with @landonreed's question regarding the groups of route types.

Comment on lines 126 to 132
for (const option in fieldOptions) {
if (fieldOptions[option].group === 'Standard') {
standardTypes.push(fieldOptions[option])
} else {
extendedTypes.push(fieldOptions[option])
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified:

const standardTypes = Object.values(fieldOptions).filter(fieldOption => fieldOption.group === 'Standard')
// same for extendedTypes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better, in the return statement, try this:

return routeTypes
.map(type => Object.values(fieldOptions).filter(/*see above*/))
.map(routeTypes => {
  <optgroup>
    {routeTypes.map(routeType => /*what you already have for each std/extended types*/)}
  </optgroup>
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like it! Thanks Binh

@binh-dam-ibigroup binh-dam-ibigroup removed their assignment Apr 20, 2021
@landonreed
Copy link
Contributor

Commentary is a little muddy here, so I'm going to add a PR and share my recs there.

@mvanlaar
Copy link
Contributor

@robertgregg3, what prompted the addition of the group field in gtfs.yml? I'm not sure it's needed, given that we effectively know that types 0-12 are standard and those after are extended. I liked the way you had handled it previously.

Also, Trolleybus (11) and Monorail (12) should probably be in standard and moved up in the list. These are currently shown as extended (800 and 405), but I think that's probably just because the extended list has not been updated. We could keep them both, but that might be confusing.

My opinion on this would be there will no code changes needed in the future if somethings changes to the spec. Only a edit to the gtfs.yml file. Also some companies can changes which items are for them standard and what are extended without changing code but only the gtfs.yml file.

@landonreed
Copy link
Contributor

@robertgregg3, take a look at my changes in #659. Feel free to review and merge here if they look OK to you. And let me know if you have any questions!

@landonreed landonreed added the BLOCKED Blocked (waiting on another PR to be merged) label Apr 20, 2021
@robertgregg3
Copy link
Contributor Author

@robertgregg3, what prompted the addition of the group field in gtfs.yml? I'm not sure it's needed, given that we effectively know that types 0-12 are standard and those after are extended. I liked the way you had handled it previously.

@landonreed I had an interesting time trying to create an drop down with multiple optgroups (in React). The form control in the DROPDOWN case appears to be looking for one nested div of options. When I tried to render 2 opt groups within one drop down I was getting the JSX error about it needing a surrounding div tag or React.Fragment.

When researching I cam across others with similar issues in React. I found a solution that used grouping via the options data so that is why I added the "group" to the gtfs.yml route_type options.

I did kind of prefer the other option and there was most likely a simple face palm solution.

@robertgregg3
Copy link
Contributor Author

@landonreed Thanks for sharing your solution. Looks great

@robertgregg3
Copy link
Contributor Author

@landonreed I suppose just one question regarding Evans point about updating JUST the gtfs.yml file rather than having to go into any code and updating the slice index. I prefer the code solution, but from a client usability/updating perspective perhaps the other way is more optimal?

@landonreed
Copy link
Contributor

Re: @mvanlaar's point about avoiding a code change, yes, there may be some value in that. But these route_type values and their classification as Standard vs. Extended are intended to accurately represent the GTFS specification, rather than a third party's interpretation of what is "standard." I think we should stick with the slice method for now. Since both of these files (gtfs.yml and EditorInput.js) are committed to the repo (and there's no way to substitute alternative files for them), I don't see a major difference in the "no-code-change" (yml) vs. the js approach, so I'm inclined to stick with the current approach.

@binh-dam-ibigroup
Copy link
Contributor

This PR seemed to be blocked pending #659, but those changes have been merged since. Removing the "Blocked" label.

@binh-dam-ibigroup
Copy link
Contributor

Per team discussion, need to add a config property to switch between the std list and the extended list.

@binh-dam-ibigroup
Copy link
Contributor

We can probably start reviewing this PR at this point. There may be some more refactorings possible that would touch parts that are not relevant to this PR, but let me know if you want to make them.

Copy link
Contributor

@miles-grant-ibigroup miles-grant-ibigroup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually looks quite good! The dropdown feels a bit janky but given that we're using a library this is perhaps to be expected. Other than a few style changes I think this might actually be good to go!

Thanks for updating the e2e tests as well.


/* Remove border and background of tags
* (a "tag" is a selected item displayed inside the input portion of the selector). */
.route-type-select .dropdown-trigger .tag {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bold looks awkward now that there is no background or border anymore. I'd either add them back (color coding might be a nice feature) or set the font-weight to match the rest of the UI

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which bold are you referring to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, in FF.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, addressed in bc14fed.

/* Custom classes for the DropdownTreeSelect component that
* override CSS from 'react-dropdown-tree-select/dist/styles.css'.
* Modified from https://dowjones.github.io/react-dropdown-tree-select/#/story/with-bootstrap-styles.
* !important tags are used because somehow the tree selector default styles are applied after this stylesheet.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably clean these up by using more specific selectors, but I personally don't mind the !important too much

Copy link
Contributor

@philip-cline philip-cline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@binh-dam-ibigroup binh-dam-ibigroup merged commit 2b5bb43 into dev Feb 25, 2022
@binh-dam-ibigroup binh-dam-ibigroup deleted the add-gtfs-extended-route-types branch February 25, 2022 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Extended GTFS Route Types
7 participants