Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Mar 5, 2020
1 parent fadba44 commit 1b9b195
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 52 deletions.
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.

5 changes: 4 additions & 1 deletion src/plugins/kibana_utils/common/url/encode_uri_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ export const encodeQuery = (
}
});

export const makeUrlFromQuery = (query: ParsedUrlQuery | {}) =>
export const stringifyWithEncoding = (query: ParsedUrlQuery | {}) =>
stringify(query, undefined, undefined, { encodeURIComponent: encodeUriQuery });

export const stringifyWithoutEncoding = (query: ParsedUrlQuery | {}) =>
stringify(query, undefined, undefined, { encodeURIComponent: (c: unknown) => c });
10 changes: 8 additions & 2 deletions src/plugins/kibana_utils/common/url/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
* under the License.
*/

import { encodeUriQuery, encodeQuery, makeUrlFromQuery } from './encode_uri_query';
import {
encodeUriQuery,
encodeQuery,
stringifyWithEncoding,
stringifyWithoutEncoding,
} from './encode_uri_query';

export const url = {
encodeQuery,
encodeUriQuery,
makeUrlFromQuery,
stringifyWithEncoding,
stringifyWithoutEncoding,
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function removeQueryParam(history: History, param: string, replace: boole

delete query[param];

const newSearch = url.makeUrlFromQuery(query);
const newSearch = url.stringifyWithEncoding(query);
const newLocation: Location<any> = {
...oldLocation,
search: newSearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function replaceUrlHashQuery(
const url = parseUrl(rawUrl);
const hash = parseUrlHash(rawUrl);
const newQuery = queryReplacer(hash?.query || {});
const searchQueryString = urlUtils.makeUrlFromQuery(newQuery);
const searchQueryString = urlUtils.stringifyWithEncoding(newQuery);

if ((!hash || !hash.search) && !searchQueryString) return rawUrl; // nothing to change. return original url
return formatUrl({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ export function getRelativeToHistoryPath(absoluteUrl: string, history: History):

return formatUrl({
pathname: stripBasename(parsedUrl.pathname),
search: urlUtils.makeUrlFromQuery(parsedUrl.query),
search: urlUtils.stringifyWithEncoding(parsedUrl.query),
hash: parsedHash
? formatUrl({
pathname: parsedHash.pathname,
search: urlUtils.makeUrlFromQuery(parsedHash.query),
search: urlUtils.stringifyWithEncoding(parsedHash.query),
})
: parsedUrl.hash,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export function fromQuery(query: Record<string, any>) {
encodeURIComponent(value).replace(/%3A/g, ':')
);

return stringify(encodedQuery, undefined, undefined, {
encodeURIComponent: (c: unknown) => c
});
return url.stringifyWithEncoding(encodedQuery);
}

export type APMQueryParams = {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/ml/public/application/util/url_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const useUrlState = (accessor: string): UrlState => {
}

try {
const oldLocationSearch = url.makeUrlFromQuery(parsedQueryString);
const oldLocationSearch = url.stringifyWithoutEncoding(parsedQueryString);

Object.keys(urlState).forEach(a => {
if (isRisonSerializationRequired(a)) {
Expand All @@ -93,11 +93,11 @@ export const useUrlState = (accessor: string): UrlState => {
parsedQueryString[a] = urlState[a];
}
});
const newLocationSearch = url.makeUrlFromQuery(parsedQueryString);
const newLocationSearch = url.stringifyWithoutEncoding(parsedQueryString);

if (oldLocationSearch !== newLocationSearch) {
history.push({
search: url.makeUrlFromQuery(parsedQueryString),
search: url.stringifyWithEncoding(parsedQueryString),
});
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const MlHostConditionalContainer = React.memo<MlHostConditionalProps>(({
if (queryStringDecoded.query != null) {
queryStringDecoded.query = replaceKQLParts(queryStringDecoded.query as string);
}
const reEncoded = urlUtils.makeUrlFromQuery(queryStringDecoded);
const reEncoded = urlUtils.stringifyWithoutEncoding(queryStringDecoded);
return <Redirect to={`/${SiemPageName.hosts}?${reEncoded}`} />;
}}
/>
Expand All @@ -55,7 +55,7 @@ export const MlHostConditionalContainer = React.memo<MlHostConditionalProps>(({
queryStringDecoded.query = replaceKQLParts(queryStringDecoded.query);
}
if (emptyEntity(hostName)) {
const reEncoded = urlUtils.makeUrlFromQuery(queryStringDecoded);
const reEncoded = urlUtils.stringifyWithoutEncoding(queryStringDecoded);

return (
<Redirect to={`/${SiemPageName.hosts}/${HostsTableType.anomalies}?${reEncoded}`} />
Expand All @@ -67,13 +67,13 @@ export const MlHostConditionalContainer = React.memo<MlHostConditionalProps>(({
hosts,
queryStringDecoded.query || ''
);
const reEncoded = stringify(urlUtils.encodeQuery(queryStringDecoded));
const reEncoded = urlUtils.stringifyWithoutEncoding(queryStringDecoded);

return (
<Redirect to={`/${SiemPageName.hosts}/${HostsTableType.anomalies}?${reEncoded}`} />
);
} else {
const reEncoded = stringify(urlUtils.encodeQuery(queryStringDecoded));
const reEncoded = urlUtils.stringifyWithoutEncoding(queryStringDecoded);

return (
<Redirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const MlNetworkConditionalContainer = React.memo<MlNetworkConditionalProp
queryStringDecoded.query = replaceKQLParts(queryStringDecoded.query);
}

const reEncoded = urlUtils.makeUrlFromQuery(queryStringDecoded);
const reEncoded = urlUtils.stringifyWithEncoding(queryStringDecoded);

return <Redirect to={`/${SiemPageName.network}?${reEncoded}`} />;
}}
Expand All @@ -57,7 +57,7 @@ export const MlNetworkConditionalContainer = React.memo<MlNetworkConditionalProp
}

if (emptyEntity(ip)) {
const reEncoded = urlUtils.makeUrlFromQuery(queryStringDecoded);
const reEncoded = urlUtils.stringifyWithEncoding(queryStringDecoded);

return <Redirect to={`/${SiemPageName.network}?${reEncoded}`} />;
} else if (multipleEntities(ip)) {
Expand All @@ -67,10 +67,10 @@ export const MlNetworkConditionalContainer = React.memo<MlNetworkConditionalProp
ips,
queryStringDecoded.query || ''
);
const reEncoded = urlUtils.makeUrlFromQuery(queryStringDecoded);
const reEncoded = urlUtils.stringifyWithEncoding(queryStringDecoded);
return <Redirect to={`/${SiemPageName.network}?${reEncoded}`} />;
} else {
const reEncoded = urlUtils.makeUrlFromQuery(queryStringDecoded);
const reEncoded = urlUtils.stringifyWithEncoding(queryStringDecoded);
return <Redirect to={`/${SiemPageName.network}/ip/${ip}?${reEncoded}`} />;
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export const replaceStateKeyInQueryString = <T>(stateKey: string, urlState: T) =
if (urlState == null || (typeof urlState === 'string' && urlState === '')) {
delete previousQueryValues[stateKey];

return url.makeUrlFromQuery(previousQueryValues);
return url.stringifyWithEncoding(previousQueryValues);
}

// ಠ_ಠ Code was copied from x-pack/legacy/plugins/infra/public/utils/url_state.tsx ಠ_ಠ
// Remove this if these utilities are promoted to kibana core
const encodedUrlState =
typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined;

return url.makeUrlFromQuery({
return url.stringifyWithEncoding({
...previousQueryValues,
[stateKey]: encodedUrlState,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const getOverallAnomalyExplorerLink = (pathname: string, jobId: string, timeRang
},
});

const hash = `/explorer?${urlUtils.makeUrlFromQuery({ _g })}`;
const hash = `/explorer?${urlUtils.stringifyWithEncoding({ _g })}`;

return url.format({
pathname,
Expand Down Expand Up @@ -94,7 +94,7 @@ const getPartitionSpecificSingleMetricViewerLink = (
},
});

const hash = `/timeseriesexplorer?${urlUtils.makeUrlFromQuery({ _g, _a })}`;
const hash = `/timeseriesexplorer?${urlUtils.stringifyWithEncoding({ _g, _a })}`;

return url.format({
pathname,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/infra/public/utils/url_state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const replaceStateKeyInQueryString = <UrlState extends any>(
const encodedUrlState =
typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined;

return url.makeUrlFromQuery({
return url.stringifyWithEncoding({
...previousQueryValues,
[stateKey]: encodedUrlState,
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/infra/public/utils/use_url_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const replaceStateKeyInQueryString = <UrlState extends any>(
const encodedUrlState =
typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined;

return url.makeUrlFromQuery({
return url.stringifyWithEncoding({
...previousQueryValues,
[stateKey]: encodedUrlState,
});
Expand Down

0 comments on commit 1b9b195

Please sign in to comment.