Skip to content

Commit

Permalink
Don't expose increment
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed Feb 2, 2021
1 parent 874f943 commit 378c08f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ describe('TraceLink', () => {
describe('when no transaction is found', () => {
it('renders a trace page', () => {
jest.spyOn(urlParamsHooks, 'useUrlParams').mockReturnValue({
incrementRangeId: () => {},
rangeId: 0,
refreshTimeRange: jest.fn(),
uiFilters: {},
Expand Down Expand Up @@ -89,7 +88,6 @@ describe('TraceLink', () => {
describe('transaction page', () => {
beforeAll(() => {
jest.spyOn(urlParamsHooks, 'useUrlParams').mockReturnValue({
incrementRangeId: () => {},
rangeId: 0,
refreshTimeRange: jest.fn(),
uiFilters: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function MockUrlParamsProvider({
return (
<UrlParamsContext.Provider
value={{
incrementRangeId: () => {},
rangeId: 0,
refreshTimeRange: mockRefreshTimeRange,
urlParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function DatePicker() {
})
);

const { incrementRangeId, urlParams, refreshTimeRange } = useUrlParams();
const { urlParams, refreshTimeRange } = useUrlParams();

function updateUrl(nextQuery: {
rangeFrom?: string;
Expand Down Expand Up @@ -111,7 +111,6 @@ export function DatePicker() {
onTimeChange={onTimeChange}
onRefresh={({ start, end }) => {
clearCache();
incrementRangeId();
refreshTimeRange({ rangeFrom: start, rangeTo: end });
}}
onRefreshChange={onRefreshChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export function MockUrlParamsContextProvider({
return (
<UrlParamsContext.Provider
value={{
incrementRangeId: () => {},
rangeId: 0,
refreshTimeRange,
urlParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { mapValues } from 'lodash';
import React, {
createContext,
useMemo,
useCallback,
useMemo,
useRef,
useState,
} from 'react';
import { withRouter } from 'react-router-dom';
import { uniqueId, mapValues } from 'lodash';
import { IUrlParams } from './types';
import { getDateRange } from './helpers';
import { resolveUrlParams } from './resolve_url_params';
import { UIFilters } from '../../../typings/ui_filters';
import {
localUIFilterNames,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../server/lib/ui_filters/local_ui_filters/config';
import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';
import { LocalUIFilterName } from '../../../common/ui_filter';
import { pickKeys } from '../../../common/utils/pick_keys';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { localUIFilterNames } from '../../../server/lib/ui_filters/local_ui_filters/config';
import { UIFilters } from '../../../typings/ui_filters';
import { useDeepObjectIdentity } from '../../hooks/useDeepObjectIdentity';
import { LocalUIFilterName } from '../../../common/ui_filter';
import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';
import { getDateRange } from './helpers';
import { resolveUrlParams } from './resolve_url_params';
import { IUrlParams } from './types';

interface TimeRange {
rangeFrom: string;
Expand All @@ -48,7 +46,6 @@ function useUiFilters(params: IUrlParams): UIFilters {
const defaultRefresh = (_time: TimeRange) => {};

const UrlParamsContext = createContext({
incrementRangeId: () => {},
rangeId: 0,
refreshTimeRange: defaultRefresh,
uiFilters: {} as UIFilters,
Expand All @@ -64,8 +61,6 @@ const UrlParamsProvider: React.ComponentClass<{}> = withRouter(
// Counter to force an update in useFetcher when the refresh button is clicked.
const [rangeId, setRangeId] = useState(0);

const [, forceUpdate] = useState('');

const urlParams = useMemo(
() =>
resolveUrlParams(location, {
Expand All @@ -79,25 +74,19 @@ const UrlParamsProvider: React.ComponentClass<{}> = withRouter(

refUrlParams.current = urlParams;

const incrementRangeId = () => setRangeId((prevRangeId) => prevRangeId + 1);

const refreshTimeRange = useCallback(
(timeRange: TimeRange) => {
refUrlParams.current = {
...refUrlParams.current,
...getDateRange({ state: {}, ...timeRange }),
};
const refreshTimeRange = useCallback((timeRange: TimeRange) => {
refUrlParams.current = {
...refUrlParams.current,
...getDateRange({ state: {}, ...timeRange }),
};

forceUpdate(uniqueId());
},
[forceUpdate]
);
setRangeId((prevRangeId) => prevRangeId + 1);
}, []);

const uiFilters = useUiFilters(urlParams);

const contextValue = useMemo(() => {
return {
incrementRangeId,
rangeId,
refreshTimeRange,
urlParams,
Expand Down

0 comments on commit 378c08f

Please sign in to comment.