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

improve typescript documentation: enums & aliases! #1982

Merged
merged 22 commits into from
Jan 25, 2018

Conversation

giladgray
Copy link
Contributor

Changes proposed in this pull request:

There's a lot going on here, sorry! I had a good time over break hacking on the docs renderers.

  • tag renderers are now just React.SFC<ITag>, none of that awkward class with a render method.
    • except for @reactExample and @reactDocs, which still use a class cuz their data comes from outside documentalist
  • add context to Documentation root component which exposes renderBlock, renderType, and getDocsData functions, rather than passing huge data blobs around through props.
  • ⭐️ @interface tag now supports enums and type aliases too!!! (this is not demonstrated in the docs yet...)
    • greatly improved header includes kind, inheritance info, and link to source with package name!
  • Documentation requires Markdown data, optionally accepts Typescript and KSS data.

Reviewers should focus on:

  • the typescript data now includes non-interface-y things (namely enums and type aliases). should we rename the @interface tag to @typescript to match @css?

@blueprint-bot
Copy link

createDefaultRenderers()

Preview: documentation

@giladgray
Copy link
Contributor Author

well fudge, we've got a big problem:
image
extends any, and it's missing all the extended props.
i've been trying to chase this down for like an hour and made no progress. it works perfectly when debugging in VSCode against actual blueprint source, but fails when run from blueprint itself.

@giladgray
Copy link
Contributor Author

ok i figured it out! must set tsconfig path so it knows how to compile our code. palantir/documentalist#58

@blueprint-bot
Copy link

tsconfigPath option fixes interface inheritance!!!

Preview: documentation

@giladgray
Copy link
Contributor Author

'tis fixed!
image

@blueprint-bot
Copy link

Merge branch 'master' of github.com:palantir/blueprint into gg/docs-typescript

Preview: documentation

);
};
ApiHeader.contextTypes = DocumentationContextTypes;
ApiHeader.displayName = "Docs.ApiHeader";
Copy link
Contributor

Choose a reason for hiding this comment

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

bleh I prefer using React classes over SFCs, especially since code like these 2 lines looks silly. there are literally no benefits to SFCs in practice, and it's easier to "upgrade" components to be more complex as needed when they're classes. but it doesn't have to block this PR

</div>
<small className="docs-package-name">
<a href={GITHUB_URL + data.fileName.slice(3)} target="__blank">
@blueprintjs/{data.fileName.split("/", 2)[1]}
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be configurable... you're in the docs-theme package, not docs-app

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh snap so true. i think i need to add a url field to the DM data... typedoc already provides one that even links to line number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops this is not done. not sure how to support it either...

return `${title} ${array.join(", ")}`;
}

const GITHUB_URL = "https://github.com/palantir/blueprint/tree/master/packages/";
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, this needs to be configurable

}
}

// HACKHACK support `code` blocks until we get real markdown parsing in ts-quick-docs
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't use ts-quick-docs anymore

}
}

// HACKHACK support `code` blocks until we get real markdown parsing in ts-quick-docs
Copy link
Contributor

Choose a reason for hiding this comment

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

another reference to ts-quick-docs

Copy link
Contributor

Choose a reason for hiding this comment

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

also why is this code duplicated? make it a utility function

heading: tags.Heading,
interface: tags.TypescriptExample,
page: () => null,
// TODO: @see
Copy link
Contributor

Choose a reason for hiding this comment

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

what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

support the @see tag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll address this in the next PR

@adidahiya adidahiya changed the base branch from master to develop January 15, 2018 17:10
</div>
<small className="docs-package-name">
<a href={this.props.sourceUrl} target="_blank">
@blueprintjs/{this.props.fileName.split("/", 2)[1]}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adidahiya thoughts on how to make this configurable? perhaps a new context function getPackageName(entry: ITsDocBase) and some prop on Documentation?

Copy link
Contributor Author

@giladgray giladgray Jan 23, 2018

Choose a reason for hiding this comment

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

or renderViewSourceLinkText(entry: ITsDocBase): React.ReactNode which defaults to simply returning "View source"

(render...Text cuz the href itself is handled by sourceUrl)

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I like the latter approach. default to "View source" and don't do anything too fancy with package paths in this docs-theme package (we can be fancier in docs-app).

@blueprint-bot
Copy link

markdownCode util

Preview: documentation | landing | table

@blueprint-bot
Copy link

Documentation renderViewSourceLinkText prop

Preview: documentation | landing | table

@blueprint-bot
Copy link

Merge branch 'develop' of github.com:palantir/blueprint into gg/docs-typescript

Preview: documentation | landing | table

@giladgray
Copy link
Contributor Author

@adidahiya ok I think this is ready to go 🚢

Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

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

minor comments. -1 for the last one

private renderTags(entry: ITsEnumMember) {
const { flags: { isDeprecated } } = entry;
return (
(isDeprecated === true || typeof isDeprecated === "string") && (
Copy link
Contributor

Choose a reason for hiding this comment

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

not a fan of implicit type coercion and complicated JS inside JSX

return (
<>
{!isOptional && <Tag children="Required" className={Classes.MINIMAL} intent={Intent.SUCCESS} />}
{(isDeprecated === true || typeof isDeprecated === "string") && (
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

);
};
CssExample.contextTypes = DocumentationContextTypes;
CssExample.displayName = "Docs.CssExample";
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer making this a class for consistency, since it's complex enough (it requires a helper render function)

@@ -19,15 +19,15 @@ export class ReactDocsTagRenderer {
* it to an actual component class in the given map, or in the default map which contains
* valid docs components from this package. Provide a custom map to inject your own components.
*/
public render: TagRenderer = ({ value: componentName }, key) => {
public render: React.SFC<ITag> = ({ value: componentName }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

why limit this to SFCs? prefer React.ComponentType<ITag>

Copy link
Contributor Author

@giladgray giladgray Jan 25, 2018

Choose a reason for hiding this comment

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

this is the type of this render function, not the type of the component, so it's actually correct here. but i'll make the change elsewhere to support SFCs in docs components.

see 958dfbd

@blueprint-bot
Copy link

tag renderers can be SFCs or classes

Preview: documentation | landing | table

@giladgray giladgray merged commit 02c4a98 into develop Jan 25, 2018
@giladgray giladgray deleted the gg/docs-typescript branch January 25, 2018 19:42
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.

3 participants