-
Notifications
You must be signed in to change notification settings - Fork 80
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
Conversation
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 ( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this 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!
gtfs.yml
Outdated
- value: 100 | ||
text: Railway Service |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
lib/editor/components/EditorInput.js
Outdated
{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 => ( |
There was a problem hiding this comment.
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
I have added:
|
There was a problem hiding this 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.
There was a problem hiding this 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.
lib/editor/components/EditorInput.js
Outdated
for (const option in fieldOptions) { | ||
if (fieldOptions[option].group === 'Standard') { | ||
standardTypes.push(fieldOptions[option]) | ||
} else { | ||
extendedTypes.push(fieldOptions[option]) | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
})
There was a problem hiding this comment.
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
Commentary is a little muddy here, so I'm going to add a PR and share my recs there. |
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. |
@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 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. |
@landonreed Thanks for sharing your solution. Looks great |
@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? |
Re: @mvanlaar's point about avoiding a code change, yes, there may be some value in that. But these |
refactor(EditorInput): suggest changes for #656
This PR seemed to be blocked pending #659, but those changes have been merged since. Removing the "Blocked" label. |
Per team discussion, need to add a config property to switch between the std list and the extended list. |
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. |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this 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!
and then added logic to display the route_type field as an optgroupFix #645