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

Remove injectI18n in dashboard plugin. #44580

Merged
merged 6 commits into from
Sep 5, 2019

Conversation

sainthkh
Copy link
Contributor

@sainthkh sainthkh commented Sep 2, 2019

Summary

Inspired by #44043. Related to #38243.

Update to recommended usage of localization, using i18n.translate instead of injected intl prop in Dashboard app.

According to the I18n doc, it is recommended to avoid injectI18n and use i18n.translate instead.

Thoughts & Questions

1.
FormattedMessage requires I18nProvider as an ancestor to work correctly. If not, you'll see the error message below:

console.error packages/kbn-i18n/node_modules/react-intl/lib/index.js:1533
    [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry. Using default message as fallback.

To solve this problem, I've introduced shallowWithI18nProvider and mountWithI18nProvider in enzyme_helpers.tsx.

In the new platform, we'll need to unit test React components that have FormattedMessage but without I18nProvider.

Without these 2 functions, you cannot test them without seeing the error message above.

I think it would be a good idea to write documentation about these functions in the I18n doc. What do you think?

2.

In DashboardSaveModal in save_modal.tsx, <FormatMessage> component is used for component attributes. How about changing them to i18n.translate()?

I think i18n.translate is visually better.

I left them as-is because it works well without any problem and I have to change the test snapshot.

3.

CloneDashboardModal and DashboardSaveModal => Names are a bit inconsistent. Should we leave them as-is? If not, I think DashboardSaveModal to SaveDashboardModal is a good idea.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

- [ ] This was checked for cross-browser compatibility, including a check against IE11

For maintainers

@mattkime @timroes It seems that you're trying to move Dashboard to new platform. Can I get some review from you? Thanks in advance.

@elasticmachine
Copy link
Contributor

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@mattkime mattkime self-requested a review September 3, 2019 14:24
@mattkime
Copy link
Contributor

mattkime commented Sep 3, 2019

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@mattkime
Copy link
Contributor

mattkime commented Sep 3, 2019

hello @sainthkh - Thanks for the PR. (removed mistaken comment)

@stacey-gammon
Copy link
Contributor

This is great @sainthkh! I saw @mattkime 's comment above and just wanted to say that I think FormattedMessage is appropriate to use (I was the PR author of the one you linked to, so I just went through this investigation).

In https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/GUIDELINE.md#in-reactjs

You should use <FormattedMessage> most of the time.

I'll try to take a look at the PR tomorrow. Just wanted to throw that in before you removed all usage of it!

@stacey-gammon
Copy link
Contributor

cc @Bamieh to comment on suggested documentation changed.

CloneDashboardModal and DashboardSaveModal => Names are a bit inconsistent. Should we leave them as-is? If not, I think DashboardSaveModal to SaveDashboardModal is a good idea.

++ good idea, but I would not make it part of this PR.

Sorry for the drive by commenting, but gotta run soon!

@sainthkh
Copy link
Contributor Author

sainthkh commented Sep 3, 2019

It seems that Jest Integration tests failed because of timeout, not my changes.

@mattkime
Copy link
Contributor

mattkime commented Sep 4, 2019

retest

@sainthkh
Copy link
Contributor Author

sainthkh commented Sep 4, 2019

I was a bit hasty. It started normal.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mattkime mattkime added non-issue Indicates to automation that a pull request should not appear in the release notes release_note:skip Skip the PR/issue when compiling release notes v7.5.0 labels Sep 4, 2019
@@ -128,3 +128,15 @@ export function renderWithIntl<T>(
}

export const nextTick = () => new Promise(res => process.nextTick(res));

export function shallowWithI18nProvider<T>(child: ReactElement<T>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try using this? https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/GUIDELINE.md#unit-tests

If so and it didn't work, lets talk about it. I want to make sure our reasoning is solid before adding new enzyme helpers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that the doc you're talking about is about using shallowWithIntl() or mountWithIntl() when injectI18n HOC is used.

We cannot use them in this PR, because I removed them. And it is recommended to do so in the i18n doc.

As far as I know, we need withI18nProvider functions to avoid the error message.

Copy link
Contributor Author

@sainthkh sainthkh Sep 4, 2019

Choose a reason for hiding this comment

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

And as you can see here in the commit, WrappedComponents are gone.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should update https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/GUIDELINE.md#unit-tests so it doesn't use props.intl in the example. I think @sainthkh's approach may be the right one, as long as there is a FormattedMessage somewhere in the line, then it'll need the provider wrapper.

@stacey-gammon
Copy link
Contributor

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@stacey-gammon stacey-gammon merged commit 8c44e89 into elastic:master Sep 5, 2019
stacey-gammon pushed a commit to stacey-gammon/kibana that referenced this pull request Sep 5, 2019
* Removed injectI18n from dashboard listing

* Added helpers for I18nProvider

* Remove intl from DashboardCloneModal

* Remove intl from options.tsx

* Remove intl from DashboardSaveModal
@stacey-gammon
Copy link
Contributor

backport PR : #44919

stacey-gammon added a commit that referenced this pull request Sep 5, 2019
* Removed injectI18n from dashboard listing

* Added helpers for I18nProvider

* Remove intl from DashboardCloneModal

* Remove intl from options.tsx

* Remove intl from DashboardSaveModal
jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 6, 2019
…ete-for-distance_feature

* 'master' of github.com:elastic/kibana: (89 commits)
  Replace TSVB timeseries charts with elastic-charts (elastic#33558)
  [TSVB][Top N aggregation] Unable to deal with negative values (elastic#43581)
  [alerting] Adds Action Type configuration support and whitelisting (elastic#44483)
  FTR: fix WebDriver Actions calls (elastic#44605)
  [Code] add NodeRepositoriesService to watch new repositories on local node (elastic#44677)
  [skip-ci][Maps] Improve Maps intro page (elastic#44721)
  [Maps] Update titles and descriptions for data sources (elastic#44833)
  Types + Extract Integration Util (elastic#44433)
  Downgrade log level from info to debug for cases when we cannot handle authentication attempt. (elastic#44933)
  [Reporting] Remove Chome stdout/stderr observables, Add Browser Logger observable (elastic#44359)
  Update Jest script to output coverage (elastic#44447)
  [ftr] support --kibana-install-dir flag (elastic#44552)
  [WATCHER] Allow user to set a threshold value of 0 (elastic#44810)
  Remove injectI18n in dashboard plugin. (elastic#44580)
  [Graph] Save modal (elastic#44261)
  Use external script for the OIDC Implicit flow handler page. (elastic#44866)
  disable router prefixing with pluginId (elastic#44855)
  [SIEM] Fix bug on url + inspect functionality on hosts/hostDetails page (elastic#44671)
  [ML] File data viz limiting uploaded doc chunk size (elastic#44768)
  [code] Append go env variable 'GOCACHE' to go lsp spawn command. (elastic#44864)
  ...
jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 6, 2019
…plate

* 'master' of github.com:elastic/kibana: (91 commits)
  [APM] Make number of x ticks responsive to the plot width (elastic#44870)
  [ML] Single metric viewer: Fix top nav refresh behaviour. (elastic#44860)
  Replace TSVB timeseries charts with elastic-charts (elastic#33558)
  [TSVB][Top N aggregation] Unable to deal with negative values (elastic#43581)
  [alerting] Adds Action Type configuration support and whitelisting (elastic#44483)
  FTR: fix WebDriver Actions calls (elastic#44605)
  [Code] add NodeRepositoriesService to watch new repositories on local node (elastic#44677)
  [skip-ci][Maps] Improve Maps intro page (elastic#44721)
  [Maps] Update titles and descriptions for data sources (elastic#44833)
  Types + Extract Integration Util (elastic#44433)
  Downgrade log level from info to debug for cases when we cannot handle authentication attempt. (elastic#44933)
  [Reporting] Remove Chome stdout/stderr observables, Add Browser Logger observable (elastic#44359)
  Update Jest script to output coverage (elastic#44447)
  [ftr] support --kibana-install-dir flag (elastic#44552)
  [WATCHER] Allow user to set a threshold value of 0 (elastic#44810)
  Remove injectI18n in dashboard plugin. (elastic#44580)
  [Graph] Save modal (elastic#44261)
  Use external script for the OIDC Implicit flow handler page. (elastic#44866)
  disable router prefixing with pluginId (elastic#44855)
  [SIEM] Fix bug on url + inspect functionality on hosts/hostDetails page (elastic#44671)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport pending non-issue Indicates to automation that a pull request should not appear in the release notes release_note:skip Skip the PR/issue when compiling release notes v7.5.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants