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

Update to Storybook v6, add base TypeScript support at project level and add typings for two packages #250

Merged
merged 7 commits into from
Jun 18, 2021

Conversation

evansiroky
Copy link
Contributor

@evansiroky evansiroky commented May 16, 2021

This is the first of many PRs to add TypeScript types throughout this project. This first PR sets up the overall project to be able to handle TypeScript in the first place. As a part of adding TypeScript, Storybook was also updated to v6 to be able to take advantage of the automatic generation of Storybook documentation from type definitions.

This PR does the following specifically:

Project-wide changes

Typescript stuff

  • Adds the TypeScript preset to the babel config so that babel can still transpile TypeScript files
  • Adds a TypeScript script that will run TypeScript within all packages where the TypeScript script is defined. This will also result in the generation of type declaration files that can be included in releases so that other packages can read in these typed files
  • Changes the prepublish script to also run TypeScript which will generate TypeScript typings for each project configured to have typings
  • Adds TypeScript support within the linting process by change the base linting configuration from airbnb to airbnb-typescript, adding the @typescript-eslint/recommended plugin, and substituting a few common eslint checks for TypeScript-friendly checks. (see more info on this as it might come up later).
  • Makes sure stylelint works with .ts files (but doesn't analyze generated *.d.ts files).

Storybook stuff

Changes to base-map package

  • Added a few eslint-disables to some new eslint typescript rules. We might deal with these later if needed when adding TypeScript support for this package.
  • Moved story info text to component class JSDoc

Changes to humanize-duration package

  • Adds complete TypeScript coverage to the package
  • Adds a TypeScript test file to the package to prove that writing tests in TypeScript works and is executed properly by jest
  • Adds TypeScript type path, script and configuration file to make sure TypeScript type declarations are generated and (🤞) included in future releases

Changes to icons package

  • Refactors stories to be more meaningful. Instead of showing each icon as a different story, stories are now shown for the various LegIcon and ModeIcon components.

Changes to itinerary-body package

  • Refactors stories so that they are separated into otp-ui and otp-react-redux folders.

Changes to location-field package

  • Changed around the order of some variable declarations to fix a linting error.
  • Refactors stories so that they are separated into "Desktop Context" and "Mobile Context" folders.

Changes to location-icon package

  • Adds complete TypeScript coverage to the package
  • Adds TypeScript type path, script and configuration file to make sure TypeScript type declarations are generated and (🤞) included in future releases

@landonreed
Copy link
Member

landonreed commented May 17, 2021

Storybook 6 should hopefully parse TypeScript typings and JSDoc out-of-the-box

@evansiroky, let's just bump to Storybook 6 in that case? Unless the migration is overly cumbersome?

@@ -1,4 +1,4 @@
import React from "react";
Copy link
Collaborator

Choose a reason for hiding this comment

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

This story is not being shown in Storybook. Add the .story.tsx extension to /.storybook/config.js.

Copy link
Collaborator

@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.

Upgrading storybook doesn't look straight forward and will need some more investigation.

Copy link
Member

@fpurcell fpurcell left a comment

Choose a reason for hiding this comment

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

If no objections, I'm going to merge in #242 and then deploy Storybook of latest 'dev' to the github pages site.

@evansiroky evansiroky changed the title Add base TypeScript support at project level and add typings for two packages Update to Storybook v6, add base TypeScript support at project level and add typings for two packages May 27, 2021
@evansiroky
Copy link
Contributor Author

Ready for review again, this time with an update to Storybook v6.

@evansiroky evansiroky removed their assignment May 27, 2021
@@ -0,0 +1,14 @@
import React from "react";
Copy link
Member

Choose a reason for hiding this comment

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

Is there not a way to output the leg- and mode-icon stories as they previously were handled? This new code just seems like a lot of extra files/boilerplate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree to the extent that some of the related code is a bit overkill and not directly related to the PR, although I like the grouping by each LegIcon and ModeIcon component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is not a way to output as they were before since there is no way to dynamically generate a lot of stories once storiesOf is deprecated. See storybookjs/storybook#9828. The previous way was also quite difficult to browse and somewhat meaningless. This new method shows the output of the various LegIcon and ModeIcon components which I feel is an improvement.

Comment on lines +105 to +133
export const MenuItemA = styled.a`
background-color: ${props => (props.active ? "#337ab7" : "transparent")};
clear: both;
color: ${props => (props.active ? "#fff" : "#333")};
display: block;
font-weight: 400;
line-height: 1.42857143;
padding: 3px 20px;
text-decoration: none;
white-space: nowrap;
`;

export const MenuItemHeader = styled.li`
color: navy;
display: block;
font-size: 14px;
font-weight: 600;
line-height: 1.42857143;
padding: 3px 20px;
text-align: ${props => (props.centeredText ? "center" : "left")};
white-space: nowrap;
`;

export const MenuItemLi = styled.li`
&:hover {
background-color: ${props => !props.disabled && "#f5f5f5"};
}
`;

Copy link
Member

Choose a reason for hiding this comment

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

Are these components just moved around this file? If so, I don't fully understand why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As part of updating the eslint config, the new rule of no-use-before-define became active. The moving around of these variables is to comply with this new rule.

Copy link
Collaborator

@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.

Please add to the PR description about a fix to #187. Consider some of the minor tweaks mentioned. My comments regarding LegIcon (#27) are non-blocking, it might be worth an internal discussion.


addons.setConfig({
sidebar: {
showRoots: false
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this setting do? (probably needs a comment if we are overriding a default)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment in 2695404

babel.config.js Outdated
"babel-plugin-styled-components"
],
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
["@babel/preset-typescript"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove array notation if we are not passing extra params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored in 2695404

@@ -0,0 +1,14 @@
import React from "react";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree to the extent that some of the related code is a bit overkill and not directly related to the PR, although I like the grouping by each LegIcon and ModeIcon component.

Comment on lines +6 to +27
const bikeOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-only.json");
const bikeRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-rental.json");
const eScooterRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/e-scooter-rental.json");
const parkAndRideItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/park-and-ride.json");
const tncTransitTncItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/tnc-transit-tnc.json");
const walkOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-only.json");
const walkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk.json");
const walkTransitWalkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk-transit-walk.json");

const exampleLegs = [
{ leg: bikeOnlyItinerary.legs[0], type: "Personal bike" },
{ leg: bikeRentalItinerary.legs[1], type: "Bike rental" },
{ leg: walkTransitWalkTransitWalkItinerary.legs[1], type: "Bus" },
{
leg: eScooterRentalItinerary.legs[1],
type: "Micromobility (from Razor company)"
},
{ leg: parkAndRideItinerary.legs[0], type: "Park & Ride" },
{ leg: tncTransitTncItinerary.legs[0], type: "TNC (Uber)" },
{ leg: walkTransitWalkItinerary.legs[1], type: "Tram" },
{ leg: walkOnlyItinerary.legs[0], type: "Walk" }
];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Importing an entire leg seems overkill. But maybe that comes from the redundancy between ModeIcon and LegIcon, so should we address #27 in the near future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The leg is needed because it is an input into a LegIcon component.

I'm not sure how this related to #27. I believe we may have already resolved it by have a TriMetLegIcon, ClassicLegIcon and StandardLegIcon classes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be for another discussion... if we addressed #27 you wouldn't have to load all of these itineraries just to extract one leg and ultimately the mode for that leg.

packages/humanize-distance/src/index.ts Show resolved Hide resolved
packages/location-icon/src/index.tsx Show resolved Hide resolved
@evansiroky evansiroky removed their assignment Jun 5, 2021
@landonreed landonreed assigned evansiroky and unassigned landonreed Jun 14, 2021
@evansiroky evansiroky merged commit ef6aa0a into opentripplanner:master Jun 18, 2021
@evansiroky evansiroky deleted the typescript branch June 18, 2021 04:59
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.

Storybook: upgrade to v6 Storybook: look to switch from addon-info to addon-docs
4 participants