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

[ui/utils/query_string]: Remove unused methods & migrate apps to querystring lib #56957

Merged
merged 35 commits into from
Feb 12, 2020

Conversation

alexwizp
Copy link
Contributor

@alexwizp alexwizp commented Feb 6, 2020

Closes: #56704

Summary

What was done:

  1. querystring-browser dependency was removed
    This library is no longer being updated. We cannot use it in TypeScript code without @ ts-ignore, because there are no types available for it.

  2. query-string library was added instead of querystring . All import from querystring/querystring-browser were replaced to use new library

  3. kibana_utils/public/url service was introduced. Now we stringify all objects using one encodeQueryComponent method.

  4. encodeQueryComponent method was unified. Before that we had 3 different copies of that method. All duplicated were removed

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@alexwizp alexwizp changed the title replace querystring (querystring-browser) -> query-string [ui/utils/query_string]: Remove unused methods & migrate apps to querystring lib Feb 6, 2020
@elastic elastic deleted a comment from kibanamachine Feb 6, 2020
@alexwizp alexwizp self-assigned this Feb 6, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@elastic elastic deleted a comment from elasticmachine Feb 7, 2020
# Conflicts:
#	x-pack/legacy/plugins/rollup/server/routes/api/index_patterns.js
#	x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js
@elastic elastic deleted a comment from elasticmachine Feb 7, 2020
@elastic elastic deleted a comment from elasticmachine Feb 7, 2020
@elastic elastic deleted a comment from kibanamachine Feb 9, 2020
Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

Overall looks good. Didn't test yet.
Added couple of questions.

@@ -34,5 +34,6 @@ export function encodeQueryComponent(val: string, pctEncodeSpaces = false) {
.replace(/%3A/gi, ':')
.replace(/%24/g, '$')
.replace(/%2C/gi, ',')
.replace(/%3B/gi, ';')
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like an actual logic change. Why was this added?

@@ -71,11 +71,11 @@ function getPdfUrlParts(

export function getPdfUrl(...args: Arguments): string {
const urlParts = getPdfUrlParts(...args);
const param = (key: string, val: any) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not add the param function to the URL utils?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use this method only in one place. Not sure that we need it somewhere else

x-pack/legacy/plugins/infra/public/utils/url_state.tsx Outdated Show resolved Hide resolved
@@ -443,7 +443,7 @@ export default function({ getService }: FtrProviderContext) {
it('should invalidate access token on IdP initiated logout', async () => {
const logoutRequest = await createLogoutRequest({ sessionIndex: idpSessionIndex });
const logoutResponse = await supertest
.get(`/api/security/logout?${querystring.stringify(logoutRequest)}`)
.get(`/api/security/logout?${stringify(logoutRequest, { sort: false })}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

In other places if seems you replaced stringing with url.stringifyUrlQuery. why isn't this the case here?

Copy link
Contributor Author

@alexwizp alexwizp Feb 10, 2020

Choose a reason for hiding this comment

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

You are right, I did it in almost all places instead functional tests and kibana-core code. Not sure that we should add import from 'kibana_utils' from that places.

@elastic elastic deleted a comment from kibanamachine Feb 10, 2020
@lizozom lizozom requested a review from a team February 12, 2020 13:02
) =>
transform(query, (result, value, key) => {
if (key) {
const singleValue = Array.isArray(value) ? value.join(',') : value;
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the same as arrayFormat: 'comma'?

queryString.stringify({ foo: [1, 2, 3] }, { arrayFormat: 'comma'} );
//=> 'foo=1,2,3'

Copy link
Contributor Author

@alexwizp alexwizp Feb 12, 2020

Choose a reason for hiding this comment

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

@sqren yes, if you don't need to encode your object using encodeQuery method you can definitely use { arrayFormat: 'comma'}. Now you can do it cause all plugins use query-string library directly without any wrappers. Thank you for your previous suggestion.

But I added this line, because initially the encodeUriQuery method worked only with the string type, but should also work fine with string arrays.

If you have any suggestions how to modify that code to use { arrayFormat: 'comma'} please let me know.

});
const encodedQuery = url.encodeQuery(query, value =>
encodeURIComponent(value).replace(/%3A/g, ':')
);
Copy link
Member

@sorenlouv sorenlouv Feb 12, 2020

Choose a reason for hiding this comment

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

Thanks for making the changes above!

I think that perhaps url.encodeQuery changes the format of the encoded values slightly. This is probably not a problem, but I'd like the change to be explicit.

I've added a few specs to capture previous behaviour. Can you do me a favour and add them to x-pack/legacy/plugins/apm/public/components/shared/Links/url_helpers.test.tsx:

  it('should not encode the following characters', () => {
    expect(
      fromQuery({
        a: true,
        b: 5000,
        c: ':'
      })
    ).toEqual('a=true&b=5000&c=:');
  });

  it('should encode the following characters', () => {
    expect(
      fromQuery({
        a: '@',
        b: '.',
        c: ';',
        d: ' '
      })
    ).toEqual('a=%40&b=.&c=%3B&d=%20');
  });

  it('should handle null and undefined', () => {
    expect(
      fromQuery({
        a: undefined,
        b: null
      })
    ).toEqual('a=&b=');
  });

  it('should handle arrays', () => {
    expect(
      fromQuery({
        arr: ['a', 'b']
      })
    ).toEqual('arr=a&arr=b');
  });

That should make any discrepancies between the old and new behaviour clear.
Most notably I think the new encoding changes the array format, and handling of null and undefined.

Copy link
Contributor Author

@alexwizp alexwizp Feb 12, 2020

Choose a reason for hiding this comment

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

@sqren tests were added

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@alexwizp alexwizp merged commit deda49e into elastic:master Feb 12, 2020
alexwizp added a commit to alexwizp/kibana that referenced this pull request Feb 12, 2020
…ystring lib (elastic#56957)

* replace querystring (querystring-browser) -> query-string

* QueryString remove encode/decode methods

* remove query_string file

* remove querystring-browser from package.json

* add kibana_utils\url module

* cleanup

* update notice.txt

* fix merge conflict

* fix CI

* fix wrong import

* fix CI

* fix X-Pack firefox smoke test

* remove urlUtils.parseUrlQuery

* remove url.stringifyUrlQuery

* use url.encodeQuery

* Record<string, any> -> ParsedQuery

* Update src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx

Co-Authored-By: Luke Elmers <lukeelmers@gmail.com>

* add more tests for APM

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

# Conflicts:
#	x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/middleware.ts
alexwizp added a commit to alexwizp/kibana that referenced this pull request Feb 13, 2020
…ystring lib (elastic#56957)

* replace querystring (querystring-browser) -> query-string

* QueryString remove encode/decode methods

* remove query_string file

* remove querystring-browser from package.json

* add kibana_utils\url module

* cleanup

* update notice.txt

* fix merge conflict

* fix CI

* fix wrong import

* fix CI

* fix X-Pack firefox smoke test

* remove urlUtils.parseUrlQuery

* remove url.stringifyUrlQuery

* use url.encodeQuery

* Record<string, any> -> ParsedQuery

* Update src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx

Co-Authored-By: Luke Elmers <lukeelmers@gmail.com>

* add more tests for APM

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

# Conflicts:
#	x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/middleware.ts
alexwizp added a commit that referenced this pull request Feb 13, 2020
…ystring lib (#56957) (#57533)

* replace querystring (querystring-browser) -> query-string

* QueryString remove encode/decode methods

* remove query_string file

* remove querystring-browser from package.json

* add kibana_utils\url module

* cleanup

* update notice.txt

* fix merge conflict

* fix CI

* fix wrong import

* fix CI

* fix X-Pack firefox smoke test

* remove urlUtils.parseUrlQuery

* remove url.stringifyUrlQuery

* use url.encodeQuery

* Record<string, any> -> ParsedQuery

* Update src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx

Co-Authored-By: Luke Elmers <lukeelmers@gmail.com>

* add more tests for APM

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

# Conflicts:
#	x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/middleware.ts
oatkiller pushed a commit to oatkiller/kibana that referenced this pull request Feb 18, 2020
…ystring lib (elastic#56957)

This was already backported, but changes to endpoint app could not be
backported, since endpoint app itself hadn't been backported. Now that
the endpoint app is backported, reapply the endpoint specific changes
from the original commit.
oatkiller pushed a commit that referenced this pull request Feb 18, 2020
* Add Endpoint plugin and Resolver embeddable (#51994)

* Add functional tests for plugins to x-pack (so we can do a functional test of the Resolver embeddable)
* Add Endpoint plugin
* Add Resolver embeddable
* Test that Resolver embeddable can be rendered

 Conflicts:
	x-pack/.i18nrc.json
	x-pack/test/api_integration/apis/index.js

* [Endpoint] Register endpoint app (#53527)

* register app, create functional test

* formatting

* update tests

* adjust test data for endpoint

* add endpoint tests for testing spaces, app enabled, disabled, etc

* linting

* add read privileges to endpoint

* rename variable since its used now

* remove deprecated context

* remove unused variable

* fix type check

* correct test suite message

Co-Authored-By: Larry Gregory <lgregorydev@gmail.com>

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

* [Endpoint] add react router to endpoint app (#53808)

* add react router to endpoint app

* linting

* linting

* linting

* correct tests

* change history from hash to browser, add new test util

* remove default values in helper functions

* fix type check, use FunctionComponent as oppsed to FC

* use BrowserRouter component

* use BrowserRouter component lin

* add comments to test framework, change function name to include browserHistory

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

* EMT-issue-65: add endpoint list api (#53861)

add endpoint list api

* EMT-65:always return accurate endpoint count (#54423)

EMT-65:always return accurate endpoint count, independent of paging properties

* Resolver component w/ sample data (#53619)

Resolver is a map. It shows processes that ran on a computer. The processes are drawn as nodes and lines connect processes with their parents.

Resolver is not yet implemented in Kibana. This PR adds a 'map' type UX. The user can click and drag to pan the map and zoom using trackpad pinching (or ctrl and mousewheel.)

There is no code providing actual data. Sample data is included. The sample data is used to draw a map. The fundamental info needed is:

process names
the parent of a process
With this info we can topologically lay out the processes. The sample data isn't yet in a realistic format. We'll be fixing that soon.

Related issue: elastic/endpoint-app-team#30

* Resolver test plugin not using mount context. (#54933)

Mount context was deprecated. Use core.getStartServices() instead.

* Resolver nonlinear zoom (#54936)

* [Endpoint] add Redux saga Middleware and app Store (#53906)

* Added saga library
* Initialize endpoint app redux store

* Resolver is overflow: hidden to prevent obscured elements from showing up (#55076)

* [Endpoint] Fix saga to start only after store is created and stopped on app unmount (#55245)

- added `stop()`/`start()` methods to the Saga Middleware creator factory
- adjust tests based on changes
- changed application `renderApp` to stop sagas when react app is unmounted

* Resolver zoom, pan, and center controls (#55221)

* Resolver zoom, pan, and center controls

* add tests, fix north panning

* fix type issue

* update west and east panning to behave like google maps

* [Endpoint] FIX: Increase tests `sleep` default duration back to 100ms (#55492)

Revert `sleep()` default duration, in the saga tests, back to 100ms in order to prevent intermittent failures during CI runs.

Fixes #55464
Fixes #55465

* [Endpoint] EMT-65: make endpoint data types common, restructure (#54772)

[Endpoint] EMT-65: make endpoint data types common, use schema changes

* Basic Functionality Alert List (#55800)

* sets up initial grid and data type

* data feeds in from backend but doesnt update

* sample data feeding in correctly

* Fix combineReducers issue by importing Redux type from 'redux' package

* Add usePageId hook that fires action when user navigates to page

* Strict typing for middleware

* addresses comments and uses better types

* move types to common/types.ts

* Move types to endpoint/types.ts, address PR comments

blah 2

Co-authored-by: Pedro Jaramillo <peluja1012@gmail.com>

* [Endpoint] Add Endpoint Details route (#55746)

* Add Endpoint Details route

* add Endpoint Details tests

* sacrifices to the Type gods

* update to latest endpoint schema

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

* [Endpoint] EMT-67: add kql support for endpoint list (#56328)

[Endpoint] EMT-67: add kql support for endpoint list

* [Endpoint] ERT-82 ERT-83 ERT-84: Alert list API with pagination (#56538)

* ERT-82 ERT-83 ERT-84 (partial): Add Alert List API with pagination

* Better type safety for alert list API

* Add Test to Verify Endpoint App Landing Page (#57129)

 Conflicts:
	x-pack/test/functional/page_objects/index.ts

* fixes render bug in alert list (#57152)

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

* Resolver: Animate camera, add sidebar (#55590)

This PR adds a sidebar navigation. clicking the icons in the nav will focus the camera on the different nodes. There is an animation effect when the camera moves.

 Conflicts:
	yarn.lock

* [Endpoint] Task/basic endpoint list (#55623)

* Adds host management list to endpoint security plugin

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

* [Endpoint] Policy List UI route and initial view (#56918)

* Initial Policy List view

* Add `endpoint/policy` route and displays Policy List
* test cases (both unit and functional)

Does not yet interact with API (Ingest).

* Add ApplicationService app status management (#50223)

This was already backported, but changes to endpoint app could not be
backported, since endpoint app itself hadn't been backported. Now that
the endpoint app is backported, reapply the endpoint specific changes
from the original commit.

* Implements `getStartServices` on server-side (#55156)

This was already backported, but changes to endpoint app could not be
backported, since endpoint app itself hadn't been backported. Now that
the endpoint app is backported, reapply the endpoint specific changes
from the original commit.

* [ui/utils/query_string]: Remove unused methods & migrate apps to querystring lib (#56957)

This was already backported, but changes to endpoint app could not be
backported, since endpoint app itself hadn't been backported. Now that
the endpoint app is backported, reapply the endpoint specific changes
from the original commit.

Co-authored-by: Kevin Logan <56395104+kevinlog@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Larry Gregory <lgregorydev@gmail.com>
Co-authored-by: nnamdifrankie <56440728+nnamdifrankie@users.noreply.github.com>
Co-authored-by: Davis Plumlee <56367316+dplumlee@users.noreply.github.com>
Co-authored-by: Paul Tavares <56442535+paul-tavares@users.noreply.github.com>
Co-authored-by: Pedro Jaramillo <peluja1012@gmail.com>
Co-authored-by: Dan Panzarella <pzl@users.noreply.github.com>
Co-authored-by: Madison Caldwell <madison.rey.caldwell@gmail.com>
Co-authored-by: Charlie Pichette <56399229+charlie-pichette@users.noreply.github.com>
Co-authored-by: Candace Park <56409205+parkiino@users.noreply.github.com>
Co-authored-by: Pierre Gayvallet <pierre.gayvallet@gmail.com>
Co-authored-by: Alexey Antonov <alexwizp@gmail.com>
lukeelmers added a commit to lukeelmers/kibana that referenced this pull request Feb 28, 2020
Fixes elastic#58684.

In elastic#56957 we consolidated usage of various query string utils by using
the `query-string` dependency everywhere. Unfortunately, this introduced
a regression where Kibana failed in IE11 due to dropped IE support as of
`query-string` v6.0.0. Downgrading is not an easy option due to changed
APIs and lack of type definitions.

This POC experiments with the idea of requiring the original
`query-string` package, copying the files into this package, and running
them through babel.

As a result, plugins can use `@kbn/query-string` as a drop-in
replacement for `query-string`, the only difference being that the
upstream library has now been transpiled.
@alexwizp alexwizp mentioned this pull request Mar 9, 2020
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ui/utils/query_string]: Remove unused methods & migrate apps to querystring lib