-
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
Fix ilm navigation #81664
Fix ilm navigation #81664
Conversation
# Conflicts: # x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/constants.ts # x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy.tsx
@elasticmachine merge upstream |
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
… characters (#80835) * Add uri decode to es_ui_shared and fix data stream issue with % name * Add a test for data streams tab opened for name with a dollar sign * Import uri decode function from es_ui_shared and fix navigation issues for filters * Add tests for data streams with special characters in name * Revert react router navigate changes (is done in a separate PR) * Reverting changes to dataManagement es client and get data stream api route * Fix data stream name filter when activated from a url parameter * Clean up for better consistency and fixes after #81664 Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
… characters (elastic#80835) * Add uri decode to es_ui_shared and fix data stream issue with % name * Add a test for data streams tab opened for name with a dollar sign * Import uri decode function from es_ui_shared and fix navigation issues for filters * Add tests for data streams with special characters in name * Revert react router navigate changes (is done in a separate PR) * Reverting changes to dataManagement es client and get data stream api route * Fix data stream name filter when activated from a url parameter * Clean up for better consistency and fixes after elastic#81664 Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
… characters (#80835) (#81897) * Add uri decode to es_ui_shared and fix data stream issue with % name * Add a test for data streams tab opened for name with a dollar sign * Import uri decode function from es_ui_shared and fix navigation issues for filters * Add tests for data streams with special characters in name * Revert react router navigate changes (is done in a separate PR) * Reverting changes to dataManagement es client and get data stream api route * Fix data stream name filter when activated from a url parameter * Clean up for better consistency and fixes after #81664 Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
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.
Tested locally, code LGTM! Had a couple comments and a concern that I think is worth blocking on.
Edit page navigation will not work in some cases for policies with names that contain either dollar sign with other special characters or %25 sequence.
Is it possible to add a test case to define this expected behavior? If it's not possible to add a client integration test (which seems likely, since the problematic behavior only occurs on browser reload if I understand correctly), then I think it's worth extracting the decoding logic in edit_policy.container.tsx
into a utility file that can be unit tested, and add the additional test cases there. If a bug is ever reported about this behavior, these tests and accompanying comments will make it crystal clear that the bug is expected. WDYT?
@@ -7,6 +7,9 @@ | |||
import { PolicyFromES } from '../../../common/types'; | |||
|
|||
export const POLICY_NAME = 'my_policy'; | |||
// navigation doesn't work for % with other special chars or sequence %25 | |||
// https://github.com/elastic/kibana/pull/81664 | |||
export const SPECIAL_CHARS_NAME = 'test?#'; |
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.
This file is only consumed in app.test.ts
, and I find it's a bit easier to understand the tests if this value is colocated with the code that consumes it. Can we define it there until it needs to be used in multiple files, at which point we can extract it to a common location like this file?
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.
Also, what do you think of using the full set of reserved characters that the API allows?
export const SPECIAL_CHARS_NAME = 'test?#$+=&@:';
@@ -76,12 +76,22 @@ export const EditPolicy: React.FunctionComponent<Props & RouteComponentProps<Rou | |||
); | |||
} | |||
|
|||
let decodedPolicyName = policyName; |
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.
Can we add a comment here that this code can be removed if we upgrade to react-router 6 and history 5?
@elasticmachine merge upstream |
merge conflict between base and head |
Thank you for the review @cjcenizal ! I added more tests to demonstrate known issues with navigation and linked to a new issue that tracks this. Also there is a comment in |
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.
Thanks for making these changes! Tested locally, code LGTM. Had a couple suggestions to make it easier for people to understand the tests.
test('when loading edit policy page url with double encoding', async () => { | ||
await act(async () => { | ||
testBed = await setup([ | ||
encodeURI(`/policies/edit/${encodeURIComponent(SPECIAL_CHARS_NAME)}`), |
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.
As a reader of this file, I'd benefit from some explanation about why we test double-encoding. I also noticed that we have three tests for double-encoding. I think we can simplify the code and help the reader understand why we're testing double-encoding by creating a helper function at the top of this file or inside of the helpers file, consuming it everywhere we test double-encoding, and adding a comment inside it. For example:
const doubleEncodePolicyPath = (policyName) => {
// The UI double-encodes links to this path to anticipate the `decodeURI` call made by `history.push()`.
return encodeURI(`/policies/edit/${encodeURIComponent(policyName)}`);
}
/* snip */
testBed = await setup([doubleEncodePolicyPath(DOLLAR_SIGN_WITH_OTHER_CHARS_NAME)];
WDYT?
); | ||
}); | ||
|
||
test('when loading edit policy page url', async () => { |
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.
Can we describe the assertion we're making, too? This will help me scan the tests and identify which ones verify things work and which ones verify things don't work. For example, if the prior test description was this:
test('when clicked on policy name in table decodes correctly', async () => {
I'd expect this one to be:
test('when loading edit policy page url decodes incorrectly', async () => {
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 agree, it was not very clear which tests were confirming the navigation bug, so I changed the test titles similar to what you suggested.
…ded paths and better description in test names
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Async chunks
Distributable file count
Page load bundle
History
To update your PR or re-run it, just comment with: |
* Fix edit policy page navigation * Fix edit policy page navigation * Add links to PR for explanation * Added more tests and linked to a github issue about navigation issues * Fix decoding function for undefined values * Fix type check issues * Renamed dollar sign to percent sign, added a method for (double) encoded paths and better description in test names * Deleted Index Management from required bundles in ILM * Fixed merge conflicts * Revert "Deleted Index Management from required bundles in ILM" This reverts commit 5a735df Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
* master: (39 commits) Fix ilm navigation (elastic#81664) [Lens] Distinct icons for XY and pie chart value labels toolbar (elastic#82927) [data.search.aggs] Throw an error when trying to create an agg type that doesn't exist. (elastic#81509) Index patterns api - load field list on server (elastic#82629) New events resolver (elastic#82170) [App Search] Misc naming tech debt (elastic#82770) load empty_kibana in test to have clean starting point (elastic#82772) Remove data <--> expressions circular dependencies. (elastic#82685) Update 8.0 breaking change template to gather information on how to programmatically detect it. (elastic#82905) Add alerting as codeowners to related documentation folder (elastic#82777) Add captions to user and space grid pages (elastic#82713) add alternate path for x-pack/Cloud test for Lens (elastic#82634) Uses asCurrentUser in getClusterUuid (elastic#82908) [Alerting][Connectors] Add new executor subaction to get 3rd party case fields (elastic#82519) Fix test import objects (elastic#82767) [ML] Add option for anomaly charts for metric detector should plot min, mean or max as appropriate (elastic#81662) Update alert type selection layout to rows instead of grid (elastic#73665) Prevent Kerberos and PKI providers from initiating a new session for unauthenticated XHR/API requests. (elastic#82817) Update grunt and related packages (elastic#79327) Allow the repository to search across all namespaces (elastic#82863) ...
* Fix edit policy page navigation * Fix edit policy page navigation * Add links to PR for explanation * Added more tests and linked to a github issue about navigation issues * Fix decoding function for undefined values * Fix type check issues * Renamed dollar sign to percent sign, added a method for (double) encoded paths and better description in test names * Deleted Index Management from required bundles in ILM * Fixed merge conflicts * Revert "Deleted Index Management from required bundles in ILM" This reverts commit 5a735df Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
…kibana into bootstrap-node-details-overlay * 'bootstrap-node-details-overlay' of github.com:phillipb/kibana: (49 commits) [Security Solution] Fix DNS Network table query (elastic#82778) [Workplace Search] Consolidate groups routes (elastic#83015) Adds cloud links to user menu (elastic#82803) [Security Solution][Detections] - follow up cleanup on auto refresh rules (elastic#83023) [App Search] Added the log retention panel to the Settings page (elastic#82982) [Maps] show icon when layer is filtered by time and allow layers to ignore global time range (elastic#83006) [DOCS] Consolidates drilldown pages (elastic#82081) [Maps] add on-prem EMS config (elastic#82525) migrate i18n mixin to KP (elastic#81799) [bundle optimization] fix imports of react-use lib (elastic#82847) [Discover] Add metric on adding filter (elastic#82961) [Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation (elastic#82829) skip flaky suite (elastic#82804) Fix SO query for searching across spaces (elastic#83025) renaming built-in alerts to Stack Alerts (elastic#82873) [TSVB] Disable using top_hits in pipeline aggregations (elastic#82278) [Visualizations] Remove kui usage (elastic#82810) [Visualizations] Make the icon buttons labels more descriptive (elastic#82585) [Lens] Do not reset formatting when switching between custom ranges and auto histogram (elastic#82694) Fix ilm navigation (elastic#81664) ...
Summary
Fixes #81394.
This PR adds a decoding attempt of policy name on edit policy page.
Examples with different special characters
Example for policy name
test?
:navigation is done from policy table via react router
test%3F
test%3F
test?
when the user reloads the page, it works similar to router navigation 1.
when the user copies link to the edit page from the policy table or opens it in a new tab, the url in the address bar is different
test%253F
(because of the double encoding at the beginning)test%3F
%25
is already decoded by react router, so that match param is different from value in the address bartest?
reloading the page with double encoded url in the address bar works similar to 3.
Percent sign in the policy name
test%
test%25
test%25
test%
test%25
test%
%25
is being automatically decoded by the react router and is now different from the value in the address barURI malformed
error and uses initialtest%
valuetest%2525
test%25
test%
Known issues:
Since sequence
%25
is being automatically decoded by react router in match param, percent sign can't be used with other special characters and the sequence itself can't be used in policy names.Example percent sign with other characters
test%?
reactRouterNavigate('test%25%3F')
test%25%3F
test%25%3F
test%?
test%25%3F
test%%3F
partially decodedtest%%3F
wrong policy nametest%2525%253F
test%25%3F
(%25
decoded to%
)test%?
Example
%25
sequencetest%25
reactRouterNavigate('test%252525')
test%2525
test%2525
test%25
test%2525
test%25
(%25
decoded to%
)test%
wrong policy nametest%252525
test%2525
(%25
decoded to%
)test%25
TL;DR Edit page navigation will not work in some cases for policies with names that contain either percent sign with other special characters or
%25
sequence.