Skip to content

[GSoC] Automatic Documentation System for TypeScript Components #3056

Closed

Description

@thompsongl

A better automatic system for documenting EUI TypeScript components. Specifically, we're looking for a better method to extract the acceptable values for each prop on the API. This would be done through automatic transversal of the EUI components itself, combined with the type values from TS and our own inline comments.

Outcome
More accurate, robust prop documentation within the existing "Props" tab for each example section in component documentation. As the EUI team is nearing completion of complete TypeScript conversion, it is possible that the current type and prop traversal system can be entirely replaced.

Related Discussion


Interested in working on EUI for Google Summer of Code? See more details here: https://github.com/elastic/gsoc

Activity

  1. locked and limited conversation to collaborators on Mar 12, 2020
  2. unlocked this conversation on May 11, 2020
  3. thompsongl commented on May 11, 2020

    @thompsongl
    ContributorAuthor

    @ashikmeerankutty We'll use this issue to discuss and track modifications to your proposal.

    Comment in this thread and then I can assign the issue to you.

  4. ashikmeerankutty commented on May 11, 2020

    @ashikmeerankutty
    Contributor

    @thompsongl Thanks!

  5. ashikmeerankutty commented on May 21, 2020

    @ashikmeerankutty
    Contributor

    Should I continue this as a separate project outside eui and use the plugin in eui or shift the plugin development inside eui.

  6. thompsongl commented on May 21, 2020

    @thompsongl
    ContributorAuthor

    What do you think, @chandlerprall?

  7. chandlerprall commented on May 21, 2020

    @chandlerprall
    Contributor

    Let's move it inside eui; makes it easier to observer changes against any set of components

  8. ashikmeerankutty commented on May 21, 2020

    @ashikmeerankutty
    Contributor

    Out of curiosity! I just tried adding the plugin to eui. Few observations:

    • It's taking a lot of time.
    • Docs info is generated with most of the components.
    • Build is broken
  9. chandlerprall commented on May 21, 2020

    @chandlerprall
    Contributor

    It's taking a lot of time.

    Sounds like it's processing TypeScript code 😀

    Docs info is generated with most of the components.

    Sweet!

    Build is broken

    The only way to make things better :)

    Did you remove the existing ./scripts/babel/proptypes-from-ts-props plugin from babel's config? If not, it might be causing interference.

    Next week, I can help look into any issues you're not sure about. If this is too much of a problem right now, there's no rush on moving it into EUI.

  10. ashikmeerankutty commented on May 21, 2020

    @ashikmeerankutty
    Contributor

    Did you remove the existing ./scripts/babel/proptypes-from-ts-props plugin from babel's config? If not, it might be causing interference.

    No, I will try removing that.

    Next week, I can help look into any issues you're not sure about. If this is too much of a problem right now, there's no rush on moving it into EUI.

    It doesn't seem to be trouble. I think it's better to continue in eui. I will get a lot of components to try.

  11. ashikmeerankutty commented on May 22, 2020

    @ashikmeerankutty
    Contributor

    Just found a webpack loader that uses react-docgen-typescript 😐.
    Tried the same in eui and the results seems good 😐.

    image

  12. chandlerprall commented on May 27, 2020

    @chandlerprall
    Contributor

    How well does that loader / react-docgen-typescript work with components like EuiButton, which has a mix of our custom PropsForAnchor, PropsForButton, and ExclusiveUnion types? Or EuiBadge which nests those concepts

    } & CommonProps &
    ExclusiveUnion<WithIconOnClick, {}> &
    ExclusiveUnion<
    ExclusiveUnion<WithButtonProps, WithAnchorProps>,
    WithSpanProps
    >;

    Second aspect of react-docgen-typescript that wasn't great in the past was whether or not it supports types from 3rd party libs / node_modules. Ideally, I think we'd want to white list some like react-beautiful-dnd, either including the types directly or even maybe creating a link to their documentation.

    And we also don't want to lose support for generating prop types.

  13. ashikmeerankutty commented on May 27, 2020

    @ashikmeerankutty
    Contributor

    With EuiButton and EuiBadge all props are found except the onClick prop 😅. The reason onClick was not found is due to filtering props from node-modules.

    react-docgen-typescript support types from node-modules. I tried it with EuiDraggable it displays props from react-beautiful-dnd

    image

  14. 27 remaining items

  15. chandlerprall commented on Jun 15, 2020

    @chandlerprall
    Contributor

    Does it produce results with simple Component<> (imported from React)?

    Yes

    We can convert all React.Component<> to Component<>, that's fine!

  16. ashikmeerankutty commented on Jun 15, 2020

    @ashikmeerankutty
    Contributor

    What was the reason for adding the ScreenReaderOnlyDocsComponent?

    The EuiScreenReaderOnly component uses cloneElement and that was creating issues with react-docgen I guess

  17. thompsongl commented on Jun 15, 2020

    @thompsongl
    ContributorAuthor

    The EuiScreenReaderOnly component uses cloneElement and that was creating issues with react-docgen I guess

    Go ahead and change it if it is no longer the source of problems

  18. thompsongl commented on Jul 2, 2020

    @thompsongl
    ContributorAuthor

    This would be follow up work to the PR you already have open, but we'd also like to find a way to directly include types and interfaces in the Props table (see #1688)

    Tables are good example of this. We manually add complex types and interfaces through a propsInfo hack so that consumers can see subcomponent types in the table. For instance, Pagination is a valuable type, but one that wouldn't come through via simply including EuiTableProps.

  19. ashikmeerankutty commented on Jul 5, 2020

    @ashikmeerankutty
    Contributor

    One workaround for this issue I just found was to create a component called TableProps or OtherProps and let its component extend interfaces that we could display like for the table example:

    import React, { FunctionComponent } from 'react';
    import { Pagination } from './pagination_bar';
    import { EuiTableSortingType } from './table_types';
    
    export interface OtherProps extends Pagination, EuiTableSortingType<any> {}
    
    export const TableProps: FunctionComponent<OtherProps> = () => <div />;
    

    In the generated docgenInfo we could find extendedInterfaces that have all the extended props of the component as separate info.

    We could then pass it like TableProps.extendedInterfaces.Pagination to guideSection Page

    {
      "description": "",
      "displayName": "TableProps",
      "methods": [],
      "props": {
        "pageIndex": {
          "defaultValue": null,
          "description": "",
          "name": "pageIndex",
          "parent": {
            "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
            "name": "Pagination"
          },
          "required": true,
          "type": {
            "name": "number"
          }
        },
        "pageSize": {
          "defaultValue": null,
          "description": "",
          "name": "pageSize",
          "parent": {
            "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
            "name": "Pagination"
          },
          "required": true,
          "type": {
            "name": "number"
          }
        },
        "totalItemCount": {
          "defaultValue": null,
          "description": "",
          "name": "totalItemCount",
          "parent": {
            "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
            "name": "Pagination"
          },
          "required": true,
          "type": {
            "name": "number"
          }
        },
        "pageSizeOptions": {
          "defaultValue": null,
          "description": "",
          "name": "pageSizeOptions",
          "parent": {
            "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
            "name": "Pagination"
          },
          "required": false,
          "type": {
            "name": "number[]"
          }
        },
        "hidePerPageOptions": {
          "defaultValue": null,
          "description": "",
          "name": "hidePerPageOptions",
          "parent": {
            "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
            "name": "Pagination"
          },
          "required": false,
          "type": {
            "name": "boolean"
          }
        },
        "sort": {
          "defaultValue": null,
          "description": "",
          "name": "sort",
          "parent": {
            "fileName": "eui/src/components/basic_table/table_types.ts",
            "name": "EuiTableSortingType"
          },
          "required": false,
          "type": {
            "name": "{ field: string | number | symbol; direction: \"asc\" | \"desc\"; }"
          }
        },
        "allowNeutralSort": {
          "defaultValue": null,
          "description": "",
          "name": "allowNeutralSort",
          "parent": {
            "fileName": "eui/src/components/basic_table/table_types.ts",
            "name": "EuiTableSortingType"
          },
          "required": false,
          "type": {
            "name": "boolean"
          }
        },
        "enableAllColumns": {
          "defaultValue": null,
          "description": "",
          "name": "enableAllColumns",
          "parent": {
            "fileName": "eui/src/components/basic_table/table_types.ts",
            "name": "EuiTableSortingType"
          },
          "required": false,
          "type": {
            "name": "boolean"
          }
        }
      },
      "extends": [],
      "extendedInterfaces": {
        "Pagination": {
          "__docgenInfo": {
            "description": "",
            "displayName": "Pagination",
            "props": {
              "pageIndex": {
                "defaultValue": null,
                "description": "",
                "name": "pageIndex",
                "parent": {
                  "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
                  "name": "Pagination"
                },
                "required": true,
                "type": {
                  "name": "number"
                }
              },
              "pageSize": {
                "defaultValue": null,
                "description": "",
                "name": "pageSize",
                "parent": {
                  "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
                  "name": "Pagination"
                },
                "required": true,
                "type": {
                  "name": "number"
                }
              },
              "totalItemCount": {
                "defaultValue": null,
                "description": "",
                "name": "totalItemCount",
                "parent": {
                  "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
                  "name": "Pagination"
                },
                "required": true,
                "type": {
                  "name": "number"
                }
              },
              "pageSizeOptions": {
                "defaultValue": null,
                "description": "",
                "name": "pageSizeOptions",
                "parent": {
                  "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
                  "name": "Pagination"
                },
                "required": false,
                "type": {
                  "name": "number[]"
                }
              },
              "hidePerPageOptions": {
                "defaultValue": null,
                "description": "",
                "name": "hidePerPageOptions",
                "parent": {
                  "fileName": "eui/src/components/basic_table/pagination_bar.tsx",
                  "name": "Pagination"
                },
                "required": false,
                "type": {
                  "name": "boolean"
                }
              }
            }
          }
        },
        "EuiTableSortingType": {
          "__docgenInfo": {
            "description": "",
            "displayName": "EuiTableSortingType",
            "props": {
              "sort": {
                "defaultValue": null,
                "description": "",
                "name": "sort",
                "parent": {
                  "fileName": "eui/src/components/basic_table/table_types.ts",
                  "name": "EuiTableSortingType"
                },
                "required": false,
                "type": {
                  "name": "{ field: string | number | symbol; direction: \"asc\" | \"desc\"; }"
                }
              },
              "allowNeutralSort": {
                "defaultValue": null,
                "description": "",
                "name": "allowNeutralSort",
                "parent": {
                  "fileName": "eui/src/components/basic_table/table_types.ts",
                  "name": "EuiTableSortingType"
                },
                "required": false,
                "type": {
                  "name": "boolean"
                }
              },
              "enableAllColumns": {
                "defaultValue": null,
                "description": "",
                "name": "enableAllColumns",
                "parent": {
                  "fileName": "eui/src/components/basic_table/table_types.ts",
                  "name": "EuiTableSortingType"
                },
                "required": false,
                "type": {
                  "name": "boolean"
                }
              }
            }
          }
        }
      }
    }
    

    The issue here if two of the interface contains the same props only one among them will be shown.

  20. thompsongl commented on Jul 6, 2020

    @thompsongl
    ContributorAuthor

    Thanks for looking into it. Let's move discussion to that issue (#1688).

  21. thompsongl commented on Aug 13, 2020

    @thompsongl
    ContributorAuthor

    Reopening this so all the tracking continues in one issue.

    @ashikmeerankutty, please list any follow-up work to #3554 that you plan on doing (#3554 (review); sorting the props, for instance)

  22. ashikmeerankutty commented on Aug 13, 2020

    @ashikmeerankutty
    Contributor

    Follow ups

    • Sort the props table in increasing order of prop name
    • Vertical scroll for functions
    • Ref as a prop
  23. cchaos commented on Aug 25, 2020

    @cchaos
    Contributor

    @ashikmeerankutty Thank you so much for all the work you did on this project!!! 🎉 🎉 I know our all our Elastic engineers are extremely grateful for a more robust and reliable prop table with real Typescript types. The "Extends" bit, while seemingly small, is a game changer! Best of luck to you in future endeavors!

  24. thompsongl commented on Aug 25, 2020

    @thompsongl
    ContributorAuthor

    @ashikmeerankutty I merged #3944, which checks the last box here 🎉

    Just make sure you submit all your GSoC evaluations, etc. before the deadline later this week (if you haven't already).

    @cchaos is right: we're all thrilled with how it turned out! You did fantastic work over the last few months 🚀

  25. thompsongl commented on Aug 25, 2020

    @thompsongl
    ContributorAuthor

    🙌

  26. ashikmeerankutty commented on Aug 26, 2020

    @ashikmeerankutty
    Contributor

    @cchaos @thompsongl @chandlerprall Thanks for all your support. It was wonderful working with you 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions