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

Routing example plugin #69581

Merged

Conversation

stacey-gammon
Copy link
Contributor

@stacey-gammon stacey-gammon commented Jun 18, 2020

Add an example plugin that shows some basic routing examples.

I still need to add tests but first want buy in on what is showcased from the @elastic/kibana-platform team

Screen Shot 2020-06-18 at 4 42 19 PM

Screen Shot 2020-06-18 at 4 42 22 PM

@stacey-gammon stacey-gammon added release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.9.0 v8.0.0 labels Jun 18, 2020
@stacey-gammon stacey-gammon force-pushed the 2020-06-18-routing-examples branch from 808aa62 to ebd5055 Compare June 18, 2020 20:48
Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

Some nits, did not review the react components code.

Overall this seems like a good example plugin.


import { RoutingExamplePlugin } from './plugin';

export const plugin: PluginInitializer<void, void> = () => new RoutingExamplePlugin();
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: returning void as a contract got subtle issues, such as not being able to check if the plugin is enabled or not when used as an optional dependency from another plugin.

We really need to educate to use {} instead, so having it in our test plugins would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do. There are other example plugins that use void. Couldn't this be type checked? TSetup extends object = object,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, the default is void

export interface Plugin<
  TSetup = void,
  TStart = void,
  TPluginsSetup extends object = object,
  TPluginsStart extends object = object
> {

which makes it actually seem like void is supposed to be the default, not {}.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are other example plugins that use void. Couldn't this be type checked?

Yea, the current default is void. And even some non-example plugins are using it.

TBH I tried a few weeks back to change it to extends object and adapt all usages, but this is way bigger than is looks due to the amount of plugins, and this type is using in some sensible TS magic in core, causing lots of TS errors.

You can keep void for now if you want, as we'll have to fix all the plugins at once when we'll perform this change.

@restrry @joshdover Before I open an actual issue, do we all agree that plugins should always return a contract (even empty) instead of void?

examples/routing_example/server/plugin.ts Outdated Show resolved Hide resolved
Comment on lines +43 to +45
} catch (e) {
return e;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

should we remove the catch(e) throw e blocks? Or do we want them to show that fetch throws in case of code >= 400 ?

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 wanted consumers to be forced to handle the possibility of an error, which is explicit when the return is Response | Error not just Response.

But, I don't know, I'm also torn because then consumers need to do the isError(response) check which isn't that nice either.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh sorry, I misread that for a catch/throw instead of catch/return.

FYI, platform is going to open a discussion issue on this subject (should core APIs throw errors or return Either<success, error>-ish monads)

examples/routing_example/public/index.ts Outdated Show resolved Hide resolved
examples/routing_example/public/is_error.ts Outdated Show resolved Hide resolved
@stacey-gammon
Copy link
Contributor Author

Added tests.

@stacey-gammon
Copy link
Contributor Author

@elasticmachine merge upstream

@stacey-gammon
Copy link
Contributor Author

ping @elastic/kibana-platform

@stacey-gammon
Copy link
Contributor Author

@elasticmachine merge upstream

@stacey-gammon
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM

<EuiListGroup
listItems={[
{
label: 'IRouter API docs',
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess i18n is out of the scope of the example?

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'm torn on it. None of the examples use translations right now.

I don't think these will ever actually be translated because examples aren't in the distributable (though I could be wrong. @Bamieh - do you know if there is a way to run via yarn start and specify a different language, and have these translations that aren't in the distributable actually translated?).

If you could run it with a different language, it'd be helpful for developers who want to read the examples in a different language (although all of our code comments and READMEs are in English).

It'd be good to have them so copy/pastes will include translations, but this probably wouldn't be code that would be copy/pasted. If a third party developer writes an app and uses these translation services, their code still won't be translated. They need to do extra work.

It's a good question, but until I have clarity, I'm going to leave as is, at least for code that isn't meant to be copy/pasted.

examples/routing_example/public/is_error.ts Outdated Show resolved Hide resolved
@stacey-gammon
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@spalger spalger added v7.10.0 and removed 7.10.0 labels Jul 15, 2020
@stacey-gammon stacey-gammon merged commit 339e13b into elastic:master Jul 15, 2020
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Jul 15, 2020
* Routing example plugin

* Routing example plugin

* address review comments

* consolidate route registration into single function

* ts fix

* Add functional tests

* typescript fix

* Fix typo

* check against HttpFetchError not Error

* fix ts

* fix unhappy ci

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
stacey-gammon added a commit that referenced this pull request Jul 15, 2020
* Routing example plugin

* Routing example plugin

* address review comments

* consolidate route registration into single function

* ts fix

* Add functional tests

* typescript fix

* Fix typo

* check against HttpFetchError not Error

* fix ts

* fix unhappy ci

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants