Skip to content

Commit

Permalink
fix: moved routing components to own high-level folder (#997)
Browse files Browse the repository at this point in the history
* refactor: moved routing components to own high-level folder

* fix: move routing.consts to routing folder

* fix: upstream merge changes

* refactor: split uninitialisedRouter

* fix: reparent ROUTES type to routing/types

* fix: high-level routing folder
  • Loading branch information
ckbedwell authored Nov 28, 2024
1 parent 5383102 commit 02a0a95
Show file tree
Hide file tree
Showing 66 changed files with 257 additions and 236 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
'^faro',
'^sessionStorage',
'^utils',
'^routing',
'^validation',
'^datasource',
'^contexts',
Expand Down
5 changes: 3 additions & 2 deletions src/components/AlertStatus/AlertStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { GrafanaTheme2 } from '@grafana/data';
import { Icon, IconButton, LinkButton, Tooltip, useStyles2, useTheme2 } from '@grafana/ui';
import { css, cx } from '@emotion/css';

import { AlertSensitivity, Check, PrometheusAlertsGroup, ROUTES } from 'types';
import { AlertSensitivity, Check, PrometheusAlertsGroup } from 'types';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { useAlertRules } from 'hooks/useAlertRules';
import { useMetricsDS } from 'hooks/useMetricsDS';
import { AlertSensitivityBadge } from 'components/AlertSensitivityBadge';
import { getRoute } from 'components/Routing.utils';
import { Toggletip } from 'components/Toggletip';

type AlertStatusProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { AppRootProps } from '@grafana/data';
import { css, Global } from '@emotion/react';

import { ProvisioningJsonData } from 'types';
import { InitialisedRouter } from 'routing/InitialisedRouter';
import { MetaContextProvider } from 'contexts/MetaContext';
import { PermissionsContextProvider } from 'contexts/PermissionsContext';
import { SMDatasourceProvider } from 'contexts/SMDatasourceContext';
import { queryClient } from 'data/queryClient';
import { queryKeys as alertingQueryKeys } from 'data/useAlerts';

import { FeatureFlagProvider } from './FeatureFlagProvider';
import { InitialisedRouter } from './Routing';

export const App = (props: AppRootProps<ProvisioningJsonData>) => {
const { meta } = props;
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Alert, Button, Spinner, useStyles2 } from '@grafana/ui';
import { css } from '@emotion/css';
import { DataTestIds } from 'test/dataTestIds';

import { ROUTES } from 'types';
import { hasGlobalPermission } from 'utils';
import { ROUTES } from 'routing/types';
import { useAppInitializer } from 'hooks/useAppInitializer';
import { useMeta } from 'hooks/useMeta';
import { MismatchedDatasourceModal } from 'components/MismatchedDatasourceModal';
Expand Down
4 changes: 2 additions & 2 deletions src/components/CheckEditor/CheckProbes/PrivateProbesAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { Alert, LinkButton, Stack, TextLink } from '@grafana/ui';
import { useLocalStorage } from 'usehooks-ts';

import { ROUTES } from 'types';
import { getRoute } from 'components/Routing.utils';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';

export const PrivateProbesAlert = () => {
const [dismissed, setDismissed] = useLocalStorage<boolean>('dismissedPrivateProbesAlert', false);
Expand Down
5 changes: 3 additions & 2 deletions src/components/CheckForm/CheckForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { PluginPage } from '@grafana/runtime';
import { Alert, Button, Stack, Text, Tooltip, useStyles2 } from '@grafana/ui';
import { css } from '@emotion/css';
import { zodResolver } from '@hookform/resolvers/zod';
import { generateRoutePath } from 'routes';
import { DataTestIds } from 'test/dataTestIds';

import { Check, CheckFormValues, CheckType, ROUTES } from 'types';
import { Check, CheckFormValues, CheckType } from 'types';
import { createNavModel } from 'utils';
import { ROUTES } from 'routing/types';
import { generateRoutePath } from 'routing/utils';
import { AdHocCheckResponse } from 'datasource/responses.types';
import { useCheckTypeGroupOption } from 'hooks/useCheckTypeGroupOptions';
import { useCheckTypeOptions } from 'hooks/useCheckTypeOptions';
Expand Down
3 changes: 2 additions & 1 deletion src/components/CheckForm/checkForm.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { ScriptedCheckSchema } from 'schemas/forms/ScriptedCheckSchema';
import { TCPCheckSchema } from 'schemas/forms/TCPCheckSchema';
import { TracerouteCheckSchema } from 'schemas/forms/TracerouteCheckSchema';

import { Check, CheckFormValues, CheckType, ROUTES } from 'types';
import { Check, CheckFormValues, CheckType } from 'types';
import { ROUTES } from 'routing/types';
import { AdHocCheckResponse } from 'datasource/responses.types';
import { useCUDChecks, useTestCheck } from 'data/useChecks';
import { useNavigation } from 'hooks/useNavigation';
Expand Down
2 changes: 1 addition & 1 deletion src/components/CheckList/AddNewCheckButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Button } from '@grafana/ui';

import { ROUTES } from 'types';
import { ROUTES } from 'routing/types';
import { useCanWriteSM } from 'hooks/useDSPermission';
import { useNavigation } from 'hooks/useNavigation';

Expand Down
5 changes: 3 additions & 2 deletions src/components/CheckList/CheckList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { render } from 'test/render';
import { server } from 'test/server';
import { getSelect, selectOption } from 'test/utils';

import { Check, FeatureName, ROUTES } from 'types';
import { Check, FeatureName } from 'types';
import { ROUTES } from 'routing/types';
import { generateRoutePath } from 'routing/utils';

import { generateRoutePath } from '../../routes';
import { CheckList } from './CheckList';

jest.mock('hooks/useNavigation', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/CheckList/EmptyCheckList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GrafanaTheme2 } from '@grafana/data';
import { Button, useStyles2 } from '@grafana/ui';
import { css } from '@emotion/css';

import { ROUTES } from 'types';
import { ROUTES } from 'routing/types';
import { useNavigation } from 'hooks/useNavigation';

const getStyles = (theme: GrafanaTheme2) => ({
Expand Down
6 changes: 3 additions & 3 deletions src/components/CheckListItem/CheckItemActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, { useState } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { ConfirmModal, IconButton, LinkButton, useStyles2 } from '@grafana/ui';
import { css } from '@emotion/css';
import { generateRoutePath } from 'routes/utils';

import { Check, ROUTES } from 'types';
import { Check } from 'types';
import { ROUTES } from 'routing/types';
import { generateRoutePath, getRoute } from 'routing/utils';
import { useDeleteCheck } from 'data/useChecks';
import { useCanReadMetrics, useCanWriteSM } from 'hooks/useDSPermission';
import { getRoute } from 'components/Routing.utils';

const getStyles = (theme: GrafanaTheme2) => ({
actionButtonGroup: css`
Expand Down
5 changes: 3 additions & 2 deletions src/components/ChooseCheckGroup/CheckGroupCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { Icon, LinkButton, Stack, useStyles2 } from '@grafana/ui';
import { css } from '@emotion/css';
import { DataTestIds } from 'test/dataTestIds';

import { CheckTypeGroup, ROUTES } from 'types';
import { CheckTypeGroup } from 'types';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { CheckTypeGroupOption } from 'hooks/useCheckTypeGroupOptions';
import { useCheckTypeOptions } from 'hooks/useCheckTypeOptions';
import { useLimits } from 'hooks/useLimits';
import { CheckStatusInfo, NewStatusBadge } from 'components/CheckEditor/FormComponents/CheckStatusInfo';
import { getRoute } from 'components/Routing.utils';

import { Card } from '../Card';
import { Protocol } from './Protocol';
Expand Down
4 changes: 2 additions & 2 deletions src/components/ConfigActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, { useState } from 'react';
import { getBackendSrv } from '@grafana/runtime';
import { Button, LinkButton } from '@grafana/ui';

import { ROUTES } from 'types';
import { hasGlobalPermission } from 'utils';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { useMeta } from 'hooks/useMeta';

import { DisablePluginModal } from './DisablePluginModal';
import { getRoute } from './Routing.utils';

export const ConfigActions = ({ initialized }: { initialized?: boolean }) => {
const [showDisableModal, setShowDisableModal] = useState(false);
Expand Down
4 changes: 2 additions & 2 deletions src/components/OverLimitAlert/BrowserCheckLimitAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { TextLink } from '@grafana/ui';

import { ROUTES } from 'types';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { useLimits } from 'hooks/useLimits';
import { getRoute } from 'components/Routing.utils';
import { Ul } from 'components/Ul';

import { AlertContainer } from './AlertContainer';
Expand Down
4 changes: 2 additions & 2 deletions src/components/OverLimitAlert/CheckLimitAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { TextLink } from '@grafana/ui';

import { ROUTES } from 'types';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { useLimits } from 'hooks/useLimits';
import { getRoute } from 'components/Routing.utils';
import { Ul } from 'components/Ul';

import { AlertContainer } from './AlertContainer';
Expand Down
4 changes: 2 additions & 2 deletions src/components/OverLimitAlert/ExecutionLimitAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { TextLink } from '@grafana/ui';

import { ROUTES } from 'types';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { FREE_EXECUTION_LIMIT } from 'hooks/useAtHgExecutionLimit';
import { getRoute } from 'components/Routing.utils';
import { Ul } from 'components/Ul';

import { AlertContainer } from './AlertContainer';
Expand Down
4 changes: 2 additions & 2 deletions src/components/OverLimitAlert/ScriptedCheckLimitAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { TextLink } from '@grafana/ui';

import { ROUTES } from 'types';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { useLimits } from 'hooks/useLimits';
import { getRoute } from 'components/Routing.utils';
import { Ul } from 'components/Ul';

import { AlertContainer } from './AlertContainer';
Expand Down
5 changes: 3 additions & 2 deletions src/components/ProbeCard/ProbeCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { OFFLINE_PROBE, ONLINE_PROBE, PRIVATE_PROBE, PUBLIC_PROBE } from 'test/f
import { render } from 'test/render';
import { probeToExtendedProbe, runTestAsViewer } from 'test/utils';

import { type ExtendedProbe, ROUTES } from 'types';
import { type ExtendedProbe } from 'types';
import { ROUTES } from 'routing/types';
import { generateRoutePath } from 'routing/utils';

import { generateRoutePath } from '../../routes';
import { ProbeCard } from './ProbeCard';

it(`Displays the correct information`, async () => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/ProbeCard/ProbeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { Card, Link, LinkButton, useStyles2 } from '@grafana/ui';
import { css } from '@emotion/css';
import { generateRoutePath } from 'routes/utils';

import { type ExtendedProbe, type Label, ROUTES } from 'types';
import { type ExtendedProbe, type Label } from 'types';
import { ROUTES } from 'routing/types';
import { generateRoutePath } from 'routing/utils';
import { useCanEditProbe } from 'hooks/useCanEditProbe';
import { SuccessRateGaugeProbe } from 'components/Gauges';

Expand Down
5 changes: 3 additions & 2 deletions src/components/ProbeEditor/ProbeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { css } from '@emotion/css';
import { zodResolver } from '@hookform/resolvers/zod';
import { ProbeSchema } from 'schemas/forms/ProbeSchema';

import { ExtendedProbe, FeatureName, Probe, ROUTES } from 'types';
import { ExtendedProbe, FeatureName, Probe } from 'types';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { useCanEditProbe } from 'hooks/useCanEditProbe';
import { FeatureFlag } from 'components/FeatureFlag';
import { HorizontalCheckboxField } from 'components/HorizonalCheckboxField';
import { LabelField } from 'components/LabelField';
import { ProbeRegionsSelect } from 'components/ProbeRegionsSelect';
import { getRoute } from 'components/Routing.utils';
import { SimpleMap } from 'components/SimpleMap';

type ProbeEditorProps = {
Expand Down
6 changes: 3 additions & 3 deletions src/components/ProbeUsageLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';
import { ThemeTypographyVariantTypes } from '@grafana/data';
import { TextLink } from '@grafana/ui';

import { ExtendedProbe, ROUTES } from 'types';
import { ExtendedProbe } from 'types';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';

import { DataTestIds } from '../test/dataTestIds';
import { getRoute } from './Routing.utils';

interface ProbeUsageLinkProps {
probe: ExtendedProbe;
variant?: keyof Omit<ThemeTypographyVariantTypes, 'code'>;
Expand Down
7 changes: 0 additions & 7 deletions src/components/Routing.utils.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/SceneRedirecter.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { Navigate } from 'react-router-dom-v5-compat';
import { LoadingPlaceholder } from '@grafana/ui';
import { generateRoutePath } from 'routes/utils';

import { ROUTES } from 'types';
import { ROUTES } from 'routing/types';
import { generateRoutePath } from 'routing/utils';
import { useChecks } from 'data/useChecks';
import { useQuery } from 'hooks/useQuery';

Expand Down
5 changes: 3 additions & 2 deletions src/configPage/PluginConfigPage/PluginConfigPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { Alert, Badge, Button, Card, Divider, LinkButton, TextLink, useStyles2 }
import { css } from '@emotion/css';
import { DataTestIds } from 'test/dataTestIds';

import { ProvisioningJsonData, ROUTES } from 'types';
import { ProvisioningJsonData } from 'types';
import { hasGlobalPermission } from 'utils';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import type { SMDataSource } from 'datasource/DataSource';
import { getRoute } from 'components/Routing.utils';

import { DataSourceInfo, useLinkedDataSources } from './PluginConfigPage.hooks';
import { enablePlugin } from './PluginConfigPage.utils';
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/SMDatasourceContext.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { createContext, PropsWithChildren, useContext } from 'react';
import { PluginPage } from '@grafana/runtime';

import { UninitialisedRouter } from 'routing/UninitialisedRouter';
import { SMDataSource } from 'datasource/DataSource';
import { useGetSMDatasource } from 'data/useSMSetup';
import { CenteredSpinner } from 'components/CenteredSpinner';
import { UninitialisedRouter } from 'components/Routing';

type SMDatasourceContextValue = {
smDS: SMDataSource;
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useAppInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { DataSourceInstanceSettings, DataSourceJsonData } from '@grafana/data';
import { config, getBackendSrv } from '@grafana/runtime';
import { isNumber } from 'lodash';

import { ROUTES, SubmissionErrorWrapper } from 'types';
import { SubmissionErrorWrapper } from 'types';
import { FaroEvent, reportError, reportEvent } from 'faro';
import { initializeDatasource } from 'utils';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { LEGACY_LOGS_DS_NAME, LEGACY_METRICS_DS_NAME } from 'components/constants';
import { getRoute } from 'components/Routing.utils';

import { useMeta } from './useMeta';

Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useCheckTypeGroupOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ReactNode, useContext } from 'react';
import { IconName } from '@grafana/data';

import { CheckType, CheckTypeGroup, FeatureName, ROUTES } from 'types';
import { CheckType, CheckTypeGroup, FeatureName } from 'types';
import { ROUTES } from 'routing/types';
import { getRoute } from 'routing/utils';
import { FeatureFlagContext } from 'contexts/FeatureFlagContext';
import { getRoute } from 'components/Routing.utils';

import { CHECK_TYPE_OPTIONS } from './useCheckTypeOptions';

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback } from 'react';
import { useNavigate } from 'react-router-dom-v5-compat';
import { getLocationSrv } from '@grafana/runtime';

import { PLUGIN_URL_PATH } from 'components/Routing.consts';
import { PLUGIN_URL_PATH } from 'routing/constants';

export type QueryParamMap = {
[key: string]: string;
Expand Down
2 changes: 1 addition & 1 deletion src/page/AlertingWelcomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { TextLink } from '@grafana/ui';

import { ROUTES } from 'types';
import { ROUTES } from 'routing/types';

import { SubsectionWelcomePage } from './SubsectionWelcomePage';

Expand Down
9 changes: 5 additions & 4 deletions src/page/ChecksPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import { apiRoute } from 'test/handlers';
import { ComponentWrapperProps, render } from 'test/render';
import { server } from 'test/server';

import { AlertSensitivity, Check, CheckTypeGroup, ROUTES } from 'types';
import { AlertSensitivity, Check, CheckTypeGroup } from 'types';
import { PLUGIN_URL_PATH } from 'routing/constants';
import { InitialisedRouter } from 'routing/InitialisedRouter';
import { ROUTES } from 'routing/types';
import { generateRoutePath } from 'routing/utils';

import { FeatureFlagProvider } from '../components/FeatureFlagProvider';
import { InitialisedRouter } from '../components/Routing';
import { PLUGIN_URL_PATH } from '../components/Routing.consts';
import { MetaContextProvider } from '../contexts/MetaContext';
import { PermissionsContextProvider } from '../contexts/PermissionsContext';
import { SMDatasourceProvider } from '../contexts/SMDatasourceContext';
import { getQueryClient } from '../data/queryClient';
import { generateRoutePath } from '../routes';
import { SM_META } from '../test/fixtures/meta';

function RouteWrapper({ children, meta, history }: ComponentWrapperProps) {
Expand Down
2 changes: 1 addition & 1 deletion src/page/ChecksWelcomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { TextLink } from '@grafana/ui';

import { ROUTES } from 'types';
import { ROUTES } from 'routing/types';

import { SubsectionWelcomePage } from './SubsectionWelcomePage';

Expand Down
Loading

0 comments on commit 02a0a95

Please sign in to comment.