Skip to content

Commit

Permalink
Minor: add application router class (#15069)
Browse files Browse the repository at this point in the history
* Minor: add application router class

* Refactor route elements in AuthenticatedAppRouter

* Add test for ApplicationRoutesClassBase
  • Loading branch information
Sachin-chaurasiya authored Feb 7, 2024
1 parent 314f686 commit 54b1d08
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 15 deletions.
10 changes: 3 additions & 7 deletions openmetadata-ui/src/main/resources/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* limitations under the License.
*/

import React, { FC, ReactNode } from 'react';
import React, { FC } from 'react';
import { HelmetProvider } from 'react-helmet-async';
import { I18nextProvider } from 'react-i18next';
import { Router } from 'react-router-dom';
Expand All @@ -34,19 +34,15 @@ import { TOAST_OPTIONS } from './constants/Toasts.constants';
import { history } from './utils/HistoryUtils';
import i18n from './utils/i18next/LocalUtil';

interface AppProps {
routeElements?: ReactNode;
}

const App: FC<AppProps> = ({ routeElements }) => {
const App: FC = () => {
return (
<div className="main-container">
<div className="content-wrapper" data-testid="content-wrapper">
<Router history={history}>
<I18nextProvider i18n={i18n}>
<ErrorBoundary>
<DirectionProvider>
<ApplicationConfigProvider routeElements={routeElements}>
<ApplicationConfigProvider>
<AuthProvider childComponentType={AppRouter}>
<TourProvider>
<HelmetProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import { CustomPageSettings } from '../../pages/CustomPageSettings/CustomPageSet
import DataQualityPage from '../../pages/DataQuality/DataQualityPage';
import { PersonaDetailsPage } from '../../pages/Persona/PersonaDetailsPage/PersonaDetailsPage';
import { PersonaPage } from '../../pages/Persona/PersonaListPage/PersonaPage';
import applicationRoutesClass from '../../utils/ApplicationRoutesClassBase';
import { checkPermission, userPermissions } from '../../utils/PermissionsUtils';
import {
getSettingCategoryPath,
getSettingPath,
getTeamsWithFqnPath,
} from '../../utils/RouterUtils';
import { useApplicationConfigContext } from '../ApplicationConfigProvider/ApplicationConfigProvider';
import { usePermissionProvider } from '../PermissionProvider/PermissionProvider';
import { ResourceEntity } from '../PermissionProvider/PermissionProvider.interface';
import AdminProtectedRoute from './AdminProtectedRoute';
Expand Down Expand Up @@ -507,7 +507,7 @@ const ApplicationPageV1 = withSuspenseFallback(

const AuthenticatedAppRouter: FunctionComponent = () => {
const { permissions } = usePermissionProvider();
const { routeElements } = useApplicationConfigContext();
const RouteElements = applicationRoutesClass.getRouteElements();

const glossaryPermission = useMemo(
() =>
Expand Down Expand Up @@ -1340,7 +1340,7 @@ const AuthenticatedAppRouter: FunctionComponent = () => {
GlobalSettingsMenuCategory.CUSTOM_PROPERTIES
)}
/>
{routeElements}
{RouteElements && <RouteElements />}
<Route
exact
path={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { EntityUnion } from '../Explore/ExplorePage.interface';
export interface ApplicationContextConfig
extends LogoConfiguration,
LoginConfiguration {
routeElements?: ReactNode;
userProfilePics: Record<string, User>;
updateUserProfilePics: (data: { id: string; user: User }) => void;
cachedEntityData: Record<string, EntityUnion>;
Expand Down Expand Up @@ -67,12 +66,10 @@ export const useApplicationConfigContext = () =>

interface ApplicationConfigProviderProps {
children: ReactNode;
routeElements?: ReactNode;
}

const ApplicationConfigProvider: FC<ApplicationConfigProviderProps> = ({
children,
routeElements,
}) => {
const location = useLocation();
const [applicationConfig, setApplicationConfig] = useState<LogoConfiguration>(
Expand Down Expand Up @@ -153,7 +150,6 @@ const ApplicationConfigProvider: FC<ApplicationConfigProviderProps> = ({
const contextValue = useMemo(
() => ({
...applicationConfig,
routeElements,
selectedPersona,
updateSelectedPersona,
userProfilePics,
Expand All @@ -164,7 +160,6 @@ const ApplicationConfigProvider: FC<ApplicationConfigProviderProps> = ({
}),
[
applicationConfig,
routeElements,
selectedPersona,
updateSelectedPersona,
userProfilePics,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FC } from 'react';
import { ApplicationRoutesClassBase } from './ApplicationRoutesClassBase';

describe('ApplicationRoutesClassCollate', () => {
let applicationRoutesClassBase: ApplicationRoutesClassBase;

beforeEach(() => {
applicationRoutesClassBase = new ApplicationRoutesClassBase();
});

it('should return CollateRouter from getRouteElements', () => {
const result: FC | null = applicationRoutesClassBase.getRouteElements();

expect(result).toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { FC } from 'react';

class ApplicationRoutesClassBase {
public getRouteElements(): FC | null {
return null;
}
}

const applicationRoutesClass = new ApplicationRoutesClassBase();

export default applicationRoutesClass;

export { ApplicationRoutesClassBase };

0 comments on commit 54b1d08

Please sign in to comment.