Skip to content

Commit 94bcdf1

Browse files
authored
ref: Move hooks useQueryParamState() and urlParamBatchContext() into utils/ (#94741)
These are not only applicable to the widget-builder usecase, although these might be new implementations of things that already exist. By putting things together i hope to expose any duplicate helpers, and that'll make it easier to followup: keeping the best features and de-duplicating
1 parent 37aba30 commit 94bcdf1

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import {LocationFixture} from 'sentry-fixture/locationFixture';
22

33
import {act, renderHook} from 'sentry-test/reactTestingLibrary';
44

5+
import {
6+
UrlParamBatchProvider,
7+
useUrlBatchContext,
8+
} from 'sentry/utils/url/urlParamBatchContext';
59
import {useLocation} from 'sentry/utils/useLocation';
610
import {useNavigate} from 'sentry/utils/useNavigate';
711

8-
import {UrlParamBatchProvider, useUrlBatchContext} from './urlParamBatchContext';
9-
1012
jest.mock('sentry/utils/useLocation');
1113
jest.mock('sentry/utils/useNavigate');
1214

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {act, renderHook} from 'sentry-test/reactTestingLibrary';
44

55
import type {Sort} from 'sentry/utils/discover/fields';
66
import {decodeSorts} from 'sentry/utils/queryString';
7+
import {UrlParamBatchProvider} from 'sentry/utils/url/urlParamBatchContext';
8+
import {useQueryParamState} from 'sentry/utils/url/useQueryParamState';
79
import {useLocation} from 'sentry/utils/useLocation';
810
import {useNavigate} from 'sentry/utils/useNavigate';
9-
import {UrlParamBatchProvider} from 'sentry/views/dashboards/widgetBuilder/contexts/urlParamBatchContext';
10-
import {useQueryParamState} from 'sentry/views/dashboards/widgetBuilder/hooks/useQueryParamState';
1111
import {formatSort} from 'sentry/views/explore/contexts/pageParamsContext/sortBys';
1212

1313
jest.mock('sentry/utils/useLocation');

static/app/views/dashboards/widgetBuilder/hooks/useQueryParamState.tsx renamed to static/app/utils/url/useQueryParamState.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import * as Sentry from '@sentry/react';
33

44
import {defined} from 'sentry/utils';
55
import {type decodeList, decodeScalar, type decodeSorts} from 'sentry/utils/queryString';
6+
import {useUrlBatchContext} from 'sentry/utils/url/urlParamBatchContext';
67
import useLocationQuery from 'sentry/utils/url/useLocationQuery';
7-
import {useUrlBatchContext} from 'sentry/views/dashboards/widgetBuilder/contexts/urlParamBatchContext';
88

99
interface UseQueryParamStateWithScalarDecoder<T> {
1010
fieldName: string;

static/app/views/dashboards/widgetBuilder/contexts/widgetBuilderContext.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type React from 'react';
22
import {createContext, useContext} from 'react';
33

4+
import {UrlParamBatchProvider} from 'sentry/utils/url/urlParamBatchContext';
45
import useWidgetBuilderState from 'sentry/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState';
56

6-
import {UrlParamBatchProvider} from './urlParamBatchContext';
7-
87
const WidgetBuilderContext = createContext<
98
ReturnType<typeof useWidgetBuilderState> | undefined
109
>(undefined);

static/app/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import {
1616
decodeScalar,
1717
decodeSorts,
1818
} from 'sentry/utils/queryString';
19+
import {useQueryParamState} from 'sentry/utils/url/useQueryParamState';
1920
import {getDatasetConfig} from 'sentry/views/dashboards/datasetConfig/base';
2021
import {DisplayType, WidgetType} from 'sentry/views/dashboards/types';
2122
import type {ThresholdsConfig} from 'sentry/views/dashboards/widgetBuilder/buildSteps/thresholdsStep/thresholdsStep';
2223
import {MAX_NUM_Y_AXES} from 'sentry/views/dashboards/widgetBuilder/buildSteps/yAxisStep/yAxisSelector';
23-
import {useQueryParamState} from 'sentry/views/dashboards/widgetBuilder/hooks/useQueryParamState';
2424
import {
2525
DISABLED_SORT,
2626
TAG_SORT_DENY_LIST,

0 commit comments

Comments
 (0)