-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Routing example plugin #69581
Conversation
808aa62
to
ebd5055
Compare
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.
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(); |
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.
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.
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.
will do. There are other example plugins that use void
. Couldn't this be type checked? TSetup extends object = object,
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.
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 {}.
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 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/routes/random_number_generator.ts
Outdated
Show resolved
Hide resolved
} catch (e) { | ||
return e; | ||
} |
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.
should we remove the catch(e) throw e
blocks? Or do we want them to show that fetch
throws in case of code >= 400 ?
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.
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.
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 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)
…n/kibana into 2020-06-18-routing-examples
Added tests. |
@elasticmachine merge upstream |
ping @elastic/kibana-platform |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
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.
LGTM
<EuiListGroup | ||
listItems={[ | ||
{ | ||
label: 'IRouter API docs', |
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.
I guess i18n is out of the scope of the example?
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.
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.
@elasticmachine merge upstream |
💚 Build SucceededBuild metrics
History
To update your PR or re-run it, just comment with: |
* 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>
* 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>
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