Skip to content

Commit

Permalink
Fixes URL param bugs (#35741)
Browse files Browse the repository at this point in the history
* Fixes url param bugs

* Updates tests for url params bug fixes
  • Loading branch information
jasonrhodes authored Apr 30, 2019
1 parent 39091e7 commit af3594f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ describe('UrlParamsContext', () => {

expect(params).toEqual({
start: '2000-06-14T12:00:00.000Z',
serviceName: 'test',
end: '2000-06-15T12:00:00.000Z',
page: 0,
processorEvent: 'transaction',
rangeFrom: 'now-24h',
rangeTo: 'now',
refreshInterval: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function getPathParams(pathname: string = '') {
const paths = getPathAsArray(pathname);
const pageName = paths[1];

// TODO: use react router's real match params instead of guessing the path order
switch (pageName) {
case 'transactions':
return {
Expand All @@ -80,6 +81,9 @@ export function getPathParams(pathname: string = '') {
serviceName: paths[0]
};
default:
return {};
return {
processorEvent: 'transaction',
serviceName: paths[0]
};
}
}
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/public/context/UrlParamsContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function urlParamsReducer(
): IUrlParams {
switch (action.type) {
case LOCATION_UPDATE: {
return resolveUrlParams(action.location);
return resolveUrlParams(action.location, state);
}

case TIME_RANGE_REFRESH:
Expand All @@ -59,7 +59,7 @@ const UrlParamsProvider: React.FC<{}> = ({ children }) => {
const location = useLocation();
const [urlParams, dispatch] = useReducer(
urlParamsReducer,
resolveUrlParams(location)
resolveUrlParams(location, {})
);

function refreshTimeRange(time: TimeRange) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '../../components/shared/Links/url_helpers';
import { TIMEPICKER_DEFAULTS } from './constants';

export function resolveUrlParams(location: Location, state: IUrlParams = {}) {
export function resolveUrlParams(location: Location, state: IUrlParams) {
const {
processorEvent,
serviceName,
Expand Down

0 comments on commit af3594f

Please sign in to comment.