Skip to content

Commit 0af4a20

Browse files
Routing: Import useLocation from compat package (grafana#92071)
* Routing: Import useLocation from compat package * Add ComparRouter * Add CompatRouter * Fix tests * Add CompatRouter to TestProvider * Use findBy * Remove AppChromeService * Remove historyOptions * Routing: Fix alerting/test utils issues from react compat router usage (grafana#92127) * Use render from test-utils * Use compat router * Convert more tests --------- Co-authored-by: Tom Ratcliffe <[email protected]>
1 parent d24b21d commit 0af4a20

38 files changed

+94
-158
lines changed

public/app/core/components/AppChrome/MegaMenu/MegaMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { css } from '@emotion/css';
22
import { DOMAttributes } from '@react-types/shared';
33
import { memo, forwardRef, useCallback } from 'react';
4-
import { useLocation } from 'react-router-dom';
4+
import { useLocation } from 'react-router-dom-v5-compat';
55

66
import { GrafanaTheme2, NavModelItem } from '@grafana/data';
77
import { selectors } from '@grafana/e2e-selectors';

public/app/core/components/AppChrome/MegaMenu/MegaMenuItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { css, cx } from '@emotion/css';
22
import { useEffect, useRef } from 'react';
33
import * as React from 'react';
4-
import { useLocation } from 'react-router-dom';
4+
import { useLocation } from 'react-router-dom-v5-compat';
55
import { useLocalStorage } from 'react-use';
66

77
import { GrafanaTheme2, NavModelItem, toIconName } from '@grafana/data';

public/app/core/components/AppChrome/TopBar/SignInLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css } from '@emotion/css';
2-
import { useLocation } from 'react-router-dom';
2+
import { useLocation } from 'react-router-dom-v5-compat';
33

44
import { GrafanaTheme2, locationUtil, textUtil } from '@grafana/data';
55
import { useStyles2 } from '@grafana/ui';

public/app/core/components/AppChrome/TopBar/TopSearchBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { css } from '@emotion/css';
22
import { cloneDeep } from 'lodash';
33
import { memo } from 'react';
4-
import { useLocation } from 'react-router-dom';
4+
import { useLocation } from 'react-router-dom-v5-compat';
55

66
import { GrafanaTheme2, locationUtil, textUtil } from '@grafana/data';
77
import { Dropdown, ToolbarButton, useStyles2 } from '@grafana/ui';

public/app/core/hooks/useQueryParams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback, useMemo } from 'react';
2-
import { useLocation } from 'react-router-dom';
2+
import { useLocation } from 'react-router-dom-v5-compat';
33

44
import { UrlQueryMap } from '@grafana/data';
55
import { locationSearchToObject, locationService } from '@grafana/runtime';

public/app/core/navigation/GrafanaRouteError.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { css } from '@emotion/css';
22
import { ErrorInfo, useEffect } from 'react';
3-
import { useLocation } from 'react-router-dom';
3+
import { useLocation } from 'react-router-dom-v5-compat';
44

55
import { GrafanaTheme2, locationUtil, PageLayoutType } from '@grafana/data';
66
import { Button, ErrorWithStack, useStyles2 } from '@grafana/ui';

public/app/core/navigation/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLocation } from 'react-router-dom';
1+
import { useLocation } from 'react-router-dom-v5-compat';
22

33
import { locationService } from '@grafana/runtime';
44

public/app/features/alerting/unified/components/notification-policies/Policy.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { render, renderHook, screen, within } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33
import { first, noop } from 'lodash';
44
import { Router } from 'react-router-dom';
5+
import { CompatRouter } from 'react-router-dom-v5-compat';
56

67
import { config, locationService } from '@grafana/runtime';
78
import { contextSrv } from 'app/core/core';
@@ -347,7 +348,9 @@ describe('Policy', () => {
347348
const renderPolicy = (element: JSX.Element) =>
348349
render(
349350
<Router history={locationService.getHistory()}>
350-
<AlertmanagerProvider accessType="notification">{element}</AlertmanagerProvider>
351+
<CompatRouter>
352+
<AlertmanagerProvider accessType="notification">{element}</AlertmanagerProvider>
353+
</CompatRouter>
351354
</Router>
352355
);
353356

public/app/features/alerting/unified/components/panel-alerts-tab/NewRuleFromPanelButton.test.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
3+
import { render } from 'test/test-utils';
34

45
import { PanelModel } from 'app/features/dashboard/state';
56
import { createDashboardModelFixture } from 'app/features/dashboard/state/__fixtures__/dashboardFixtures';
@@ -16,12 +17,6 @@ jest.mock('app/types', () => {
1617
};
1718
});
1819

19-
jest.mock('react-router-dom', () => ({
20-
useLocation: () => ({
21-
pathname: 'localhost:3000/example/path',
22-
}),
23-
}));
24-
2520
jest.spyOn(analytics, 'logInfo');
2621

2722
jest.mock('react-use', () => ({

public/app/features/alerting/unified/components/panel-alerts-tab/NewRuleFromPanelButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLocation } from 'react-router-dom';
1+
import { useLocation } from 'react-router-dom-v5-compat';
22
import { useAsync } from 'react-use';
33

44
import { urlUtil } from '@grafana/data';

0 commit comments

Comments
 (0)