Remove injectI18n in dashboard plugin.#44580
Conversation
|
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? |
|
retest |
💔 Build Failed |
|
hello @sainthkh - Thanks for the PR. (removed mistaken comment) |
|
This is great @sainthkh! I saw @mattkime 's comment above and just wanted to say that I think In https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/GUIDELINE.md#in-reactjs I'll try to take a look at the PR tomorrow. Just wanted to throw that in before you removed all usage of it! |
|
cc @Bamieh to comment on suggested documentation changed.
++ good idea, but I would not make it part of this PR. Sorry for the drive by commenting, but gotta run soon! |
|
It seems that Jest Integration tests failed because of timeout, not my changes. |
|
retest |
|
I was a bit hasty. It started normal. |
💚 Build Succeeded |
|
|
||
| export const nextTick = () => new Promise(res => process.nextTick(res)); | ||
|
|
||
| export function shallowWithI18nProvider<T>(child: ReactElement<T>) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
And as you can see here in the commit, WrappedComponents are gone.
There was a problem hiding this comment.
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.
|
retest |
💚 Build Succeeded |
* Removed injectI18n from dashboard listing * Added helpers for I18nProvider * Remove intl from DashboardCloneModal * Remove intl from options.tsx * Remove intl from DashboardSaveModal
|
backport PR : #44919 |
…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) ...
…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) ...
Summary
Inspired by #44043. Related to #38243.
Update to recommended usage of localization, using
i18n.translateinstead of injectedintlprop in Dashboard app.According to the I18n doc, it is recommended to avoid
injectI18nand usei18n.translateinstead.Thoughts & Questions
1.
FormattedMessagerequiresI18nProvideras an ancestor to work correctly. If not, you'll see the error message below:To solve this problem, I've introduced
shallowWithI18nProviderandmountWithI18nProviderinenzyme_helpers.tsx.In the new platform, we'll need to unit test React components that have
FormattedMessagebut withoutI18nProvider.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
DashboardSaveModalinsave_modal.tsx,<FormatMessage>component is used for component attributes. How about changing them toi18n.translate()?I think
i18n.translateis visually better.I left them as-is because it works well without any problem and I have to change the test snapshot.
3.
CloneDashboardModalandDashboardSaveModal=> Names are a bit inconsistent. Should we leave them as-is? If not, I thinkDashboardSaveModaltoSaveDashboardModalis a good idea.Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.- [ ] This was checked for cross-browser compatibility, including a check against IE11--> Question about this is added above.
- [ ] This was checked for keyboard-only and screenreader accessibilityFor 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.