Skip to content

Commit

Permalink
[ui/utils/query_string]: Remove unused methods & migrate apps to quer…
Browse files Browse the repository at this point in the history
…ystring lib (#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>
  • Loading branch information
3 people authored Feb 12, 2020
1 parent b7ba72b commit deda49e
Show file tree
Hide file tree
Showing 70 changed files with 399 additions and 525 deletions.
8 changes: 1 addition & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,7 @@ module.exports = {
settings: {
// instructs import/no-extraneous-dependencies to treat certain modules
// as core modules, even if they aren't listed in package.json
'import/core-modules': [
'plugins',
'legacy/ui',
'uiExports',
// TODO: Remove once https://github.com/benmosher/eslint-plugin-import/issues/1374 is fixed
'querystring',
],
'import/core-modules': ['plugins', 'legacy/ui', 'uiExports'],

'import/resolver': {
'@kbn/eslint-import-resolver-kibana': {
Expand Down
25 changes: 0 additions & 25 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,28 +218,3 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

---
This product includes code that was extracted from angular@1.3.
Original license:
The MIT License

Copyright (c) 2010-2014 Google, Inc. http://angularjs.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
"prop-types": "15.6.0",
"proxy-from-env": "1.0.0",
"pug": "^2.0.4",
"querystring-browser": "1.0.4",
"query-string": "6.10.1",
"raw-loader": "3.1.0",
"react": "^16.12.0",
"react-color": "^2.13.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ exports.getWebpackConfig = function(kibanaPath, projectRoot, config) {
// Kibana defaults https://github.com/elastic/kibana/blob/6998f074542e8c7b32955db159d15661aca253d7/src/legacy/ui/ui_bundler_env.js#L30-L36
ui: fromKibana('src/legacy/ui/public'),
test_harness: fromKibana('src/test_harness/public'),
querystring: 'querystring-browser',

// Dev defaults for test bundle https://github.com/elastic/kibana/blob/6998f074542e8c7b32955db159d15661aca253d7/src/core_plugins/tests_bundle/index.js#L73-L78
ng_mock$: fromKibana('src/test_utils/public/ng_mock'),
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/http/http_server.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import { Request } from 'hapi';
import { merge } from 'lodash';
import { Socket } from 'net';

import querystring from 'querystring';
import { stringify } from 'query-string';

import { schema } from '@kbn/config-schema';

Expand Down Expand Up @@ -55,7 +54,8 @@ function createKibanaRequestMock({
socket = new Socket(),
routeTags,
}: RequestFixtureOptions = {}) {
const queryString = querystring.stringify(query);
const queryString = stringify(query, { sort: false });

return KibanaRequest.from(
createRawRequestMock({
headers,
Expand Down
5 changes: 2 additions & 3 deletions src/core/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import { ParsedUrlQuery } from 'querystring';
import { ParsedQuery } from 'query-string';
import { format as formatUrl, parse as parseUrl, UrlObject } from 'url';

/**
Expand All @@ -33,7 +32,7 @@ export interface URLMeaningfulParts {
protocol?: string | null;
slashes?: boolean | null;
port?: string | null;
query: ParsedUrlQuery;
query: ParsedQuery;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/server/logging/log_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import Stream from 'stream';
import moment from 'moment-timezone';
import { get, _ } from 'lodash';
import queryString from 'query-string';
import numeral from '@elastic/numeral';
import chalk from 'chalk';
import stringify from 'json-stringify-safe';
import querystring from 'querystring';
import applyFiltersToKeys from './apply_filters_to_keys';
import { inspect } from 'util';
import { logWithMetadata } from './log_with_metadata';
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class TransformObjStream extends Stream.Transform {
contentLength: contentLength,
};

const query = querystring.stringify(event.query);
const query = queryString.stringify(event.query, { sort: false });
if (query) data.req.url += '?' + query;

data.message = data.req.method.toUpperCase() + ' ';
Expand Down
5 changes: 0 additions & 5 deletions src/legacy/ui/public/state_management/global_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

import { QueryString } from '../utils/query_string';
import { StateProvider } from './state';
import { uiModules } from '../modules';
import { createLegacyClass } from '../utils/legacy_class';
Expand All @@ -35,10 +34,6 @@ export function GlobalStateProvider(Private) {
// if the url param is missing, write it back
GlobalState.prototype._persistAcrossApps = true;

GlobalState.prototype.removeFromUrl = function(url) {
return QueryString.replaceParamInUrl(url, this._urlParam, null);
};

return new GlobalState();
}

Expand Down
129 changes: 0 additions & 129 deletions src/legacy/ui/public/utils/query_string.js

This file was deleted.

1 change: 0 additions & 1 deletion src/legacy/ui/ui_exports/ui_export_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const UI_EXPORT_DEFAULTS = {
ui: resolve(ROOT, 'src/legacy/ui/public'),
__kibanaCore__$: resolve(ROOT, 'src/core/public'),
test_harness: resolve(ROOT, 'src/test_harness/public'),
querystring: 'querystring-browser',
moment$: resolve(ROOT, 'webpackShims/moment'),
'moment-timezone$': resolve(ROOT, 'webpackShims/moment-timezone'),
},
Expand Down
1 change: 0 additions & 1 deletion src/legacy/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export { BinderBase } from './binder';
export { BinderFor } from './binder_for';
export { deepCloneWithBuffers } from './deep_clone_with_buffers';
export { unset } from './unset';
export { encodeQueryComponent } from './encode_query_component';
export { watchStdioForLine } from './watch_stdio_for_line';
export { IS_KIBANA_DISTRIBUTABLE } from './artifact_type';
export { IS_KIBANA_RELEASE } from './artifact_type';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import React, { CSSProperties, useCallback, useEffect, useRef, useState } from '
import { EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { debounce } from 'lodash';

// Node v5 querystring for browser.
// @ts-ignore
import * as qs from 'querystring-browser';

import { parse } from 'query-string';
import { EuiIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { useServicesContext, useEditorReadContext } from '../../../../contexts';
import { useUIAceKeyboardMode } from '../use_ui_ace_keyboard_mode';
Expand All @@ -51,6 +47,10 @@ export interface EditorProps {
initialTextValue: string;
}

interface QueryParams {
load_from: string;
}

const abs: CSSProperties = {
position: 'absolute',
top: '0',
Expand Down Expand Up @@ -98,7 +98,8 @@ function EditorUI({ initialTextValue }: EditorProps) {

const readQueryParams = () => {
const [, queryString] = (window.location.hash || '').split('?');
return qs.parse(queryString || '');

return parse(queryString || '', { sort: false }) as Required<QueryParams>;
};

const loadBufferFromRemote = (url: string) => {
Expand Down Expand Up @@ -138,6 +139,7 @@ function EditorUI({ initialTextValue }: EditorProps) {
window.addEventListener('hashchange', onHashChange);

const initialQueryParams = readQueryParams();

if (initialQueryParams.load_from) {
loadBufferFromRemote(initialQueryParams.load_from);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/console/public/lib/es/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { stringify as formatQueryString } from 'querystring';
import $ from 'jquery';
import { stringify } from 'query-string';

const esVersion: string[] = [];

Expand All @@ -35,7 +35,7 @@ export function send(method: string, path: string, data: any) {
const wrappedDfd = $.Deferred(); // eslint-disable-line new-cap

const options: JQuery.AjaxSettings = {
url: '../api/console/proxy?' + formatQueryString({ path, method }),
url: '../api/console/proxy?' + stringify({ path, method }, { sort: false }),
data,
contentType: getContentType(data),
cache: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import qs from 'querystring';
import { parse } from 'query-string';

export function parseQueryString() {
// window.location.search is an empty string
Expand All @@ -27,5 +26,5 @@ export function parseQueryString() {
return {};
}

return qs.parse(hrefSplit[1]);
return parse(hrefSplit[1], { sort: false });
}
1 change: 1 addition & 0 deletions src/plugins/kibana_utils/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export * from './state_containers';
export * from './typed_json';
export { createGetterSetter, Get, Set } from './create_getter_setter';
export { distinctUntilChangedWithInitialValue } from './distinct_until_changed_with_initial_value';
export { url } from './url';
Loading

0 comments on commit deda49e

Please sign in to comment.