From 67701521abe54f819ce11d7bdc53f50aa0eaceb7 Mon Sep 17 00:00:00 2001 From: Sachin Chaurasiya Date: Fri, 13 Oct 2023 11:42:33 +0530 Subject: [PATCH] chore(ui): add base class for left sidebar (#13548) --- .../src/main/resources/ui/src/App.tsx | 7 ++-- .../ApplicationConfigProvider.tsx | 12 +------ .../LeftSidebar/LeftSidebar.component.tsx | 11 +++--- .../ui/src/utils/LeftSidebarClassBase.ts | 36 +++++++++++++++++++ 4 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/utils/LeftSidebarClassBase.ts diff --git a/openmetadata-ui/src/main/resources/ui/src/App.tsx b/openmetadata-ui/src/main/resources/ui/src/App.tsx index 32071b64286..c897ab6e0fb 100644 --- a/openmetadata-ui/src/main/resources/ui/src/App.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/App.tsx @@ -34,19 +34,16 @@ import i18n from './utils/i18next/LocalUtil'; interface AppProps { routeElements?: ReactNode; - sideBarElements?: ReactNode; } -const App: FC = ({ routeElements, sideBarElements }) => { +const App: FC = ({ routeElements }) => { return (
- + diff --git a/openmetadata-ui/src/main/resources/ui/src/components/ApplicationConfigProvider/ApplicationConfigProvider.tsx b/openmetadata-ui/src/main/resources/ui/src/components/ApplicationConfigProvider/ApplicationConfigProvider.tsx index 77e05f93ab5..fc2cad0f0fa 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/ApplicationConfigProvider/ApplicationConfigProvider.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/ApplicationConfigProvider/ApplicationConfigProvider.tsx @@ -26,7 +26,6 @@ import { getCustomLogoConfig } from '../../rest/settingConfigAPI'; interface ContextConfig extends LogoConfiguration { routeElements?: ReactNode; - sideBarElements?: ReactNode; selectedPersona: EntityReference; updateSelectedPersona: (personaFqn: EntityReference) => void; } @@ -41,13 +40,11 @@ export const useApplicationConfigContext = () => interface ApplicationConfigProviderProps { children: ReactNode; routeElements?: ReactNode; - sideBarElements?: ReactNode; } const ApplicationConfigProvider: FC = ({ children, routeElements, - sideBarElements, }) => { const [applicationConfig, setApplicationConfig] = useState( {} as LogoConfiguration @@ -81,17 +78,10 @@ const ApplicationConfigProvider: FC = ({ () => ({ ...applicationConfig, routeElements, - sideBarElements, selectedPersona, updateSelectedPersona, }), - [ - applicationConfig, - routeElements, - sideBarElements, - selectedPersona, - updateSelectedPersona, - ] + [applicationConfig, routeElements, selectedPersona, updateSelectedPersona] ); return ( diff --git a/openmetadata-ui/src/main/resources/ui/src/components/MyData/LeftSidebar/LeftSidebar.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/MyData/LeftSidebar/LeftSidebar.component.tsx index 92faf48157c..a5a02dfdda3 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/MyData/LeftSidebar/LeftSidebar.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/MyData/LeftSidebar/LeftSidebar.component.tsx @@ -21,14 +21,12 @@ import { useAuthContext } from '../../../components/authentication/auth-provider import { SETTING_ITEM, SIDEBAR_GOVERN_LIST, - SIDEBAR_LIST, } from '../../../constants/LeftSidebar.constants'; -import { useApplicationConfigContext } from '../../ApplicationConfigProvider/ApplicationConfigProvider'; +import leftSidebarClassBase from '../../../utils/LeftSidebarClassBase'; import './left-sidebar.less'; import LeftSidebarItem from './LeftSidebarItem.component'; const LeftSidebar = () => { - const { sideBarElements } = useApplicationConfigContext(); const { t } = useTranslation(); const { onLogoutHandler } = useAuthContext(); const [showConfirmLogoutModal, setShowConfirmLogoutModal] = useState(false); @@ -92,6 +90,9 @@ const LeftSidebar = () => { ]; }, []); + const sideBarItems = leftSidebarClassBase.getSidebarItems(); + const SideBarElements = leftSidebarClassBase.getSidebarElements(); + const handleLogoutClick = () => { setShowConfirmLogoutModal(true); }; @@ -103,7 +104,7 @@ const LeftSidebar = () => { return (
- {SIDEBAR_LIST.map((item) => ( + {sideBarItems.map((item) => ( @@ -115,7 +116,7 @@ const LeftSidebar = () => { selectedKeys={subMenuItemSelected} triggerSubMenuAction="click" /> - {sideBarElements} + {SideBarElements && } diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/LeftSidebarClassBase.ts b/openmetadata-ui/src/main/resources/ui/src/utils/LeftSidebarClassBase.ts new file mode 100644 index 00000000000..ee40da29c95 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/utils/LeftSidebarClassBase.ts @@ -0,0 +1,36 @@ +/* + * Copyright 2023 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 { SIDEBAR_LIST } from '../constants/LeftSidebar.constants'; + +class LeftSidebarClassBase { + /** + * getSidebarElements + */ + public getSidebarElements(): FC | null { + return null; + } + + /** + * getSidebarItems + */ + public getSidebarItems(): typeof SIDEBAR_LIST { + return SIDEBAR_LIST; + } +} + +const leftSidebarClassBase = new LeftSidebarClassBase(); + +export default leftSidebarClassBase; + +export { LeftSidebarClassBase };