chore(ui): add base class for left sidebar (#13548)

This commit is contained in:
Sachin Chaurasiya 2023-10-13 11:42:33 +05:30 committed by GitHub
parent 001f75ceb8
commit 67701521ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 21 deletions

View File

@ -34,19 +34,16 @@ import i18n from './utils/i18next/LocalUtil';
interface AppProps { interface AppProps {
routeElements?: ReactNode; routeElements?: ReactNode;
sideBarElements?: ReactNode;
} }
const App: FC<AppProps> = ({ routeElements, sideBarElements }) => { const App: FC<AppProps> = ({ routeElements }) => {
return ( return (
<div className="main-container"> <div className="main-container">
<div className="content-wrapper" data-testid="content-wrapper"> <div className="content-wrapper" data-testid="content-wrapper">
<Router history={history}> <Router history={history}>
<I18nextProvider i18n={i18n}> <I18nextProvider i18n={i18n}>
<ErrorBoundary> <ErrorBoundary>
<ApplicationConfigProvider <ApplicationConfigProvider routeElements={routeElements}>
routeElements={routeElements}
sideBarElements={sideBarElements}>
<AuthProvider childComponentType={AppRouter}> <AuthProvider childComponentType={AppRouter}>
<TourProvider> <TourProvider>
<HelmetProvider> <HelmetProvider>

View File

@ -26,7 +26,6 @@ import { getCustomLogoConfig } from '../../rest/settingConfigAPI';
interface ContextConfig extends LogoConfiguration { interface ContextConfig extends LogoConfiguration {
routeElements?: ReactNode; routeElements?: ReactNode;
sideBarElements?: ReactNode;
selectedPersona: EntityReference; selectedPersona: EntityReference;
updateSelectedPersona: (personaFqn: EntityReference) => void; updateSelectedPersona: (personaFqn: EntityReference) => void;
} }
@ -41,13 +40,11 @@ export const useApplicationConfigContext = () =>
interface ApplicationConfigProviderProps { interface ApplicationConfigProviderProps {
children: ReactNode; children: ReactNode;
routeElements?: ReactNode; routeElements?: ReactNode;
sideBarElements?: ReactNode;
} }
const ApplicationConfigProvider: FC<ApplicationConfigProviderProps> = ({ const ApplicationConfigProvider: FC<ApplicationConfigProviderProps> = ({
children, children,
routeElements, routeElements,
sideBarElements,
}) => { }) => {
const [applicationConfig, setApplicationConfig] = useState<LogoConfiguration>( const [applicationConfig, setApplicationConfig] = useState<LogoConfiguration>(
{} as LogoConfiguration {} as LogoConfiguration
@ -81,17 +78,10 @@ const ApplicationConfigProvider: FC<ApplicationConfigProviderProps> = ({
() => ({ () => ({
...applicationConfig, ...applicationConfig,
routeElements, routeElements,
sideBarElements,
selectedPersona, selectedPersona,
updateSelectedPersona, updateSelectedPersona,
}), }),
[ [applicationConfig, routeElements, selectedPersona, updateSelectedPersona]
applicationConfig,
routeElements,
sideBarElements,
selectedPersona,
updateSelectedPersona,
]
); );
return ( return (

View File

@ -21,14 +21,12 @@ import { useAuthContext } from '../../../components/authentication/auth-provider
import { import {
SETTING_ITEM, SETTING_ITEM,
SIDEBAR_GOVERN_LIST, SIDEBAR_GOVERN_LIST,
SIDEBAR_LIST,
} from '../../../constants/LeftSidebar.constants'; } from '../../../constants/LeftSidebar.constants';
import { useApplicationConfigContext } from '../../ApplicationConfigProvider/ApplicationConfigProvider'; import leftSidebarClassBase from '../../../utils/LeftSidebarClassBase';
import './left-sidebar.less'; import './left-sidebar.less';
import LeftSidebarItem from './LeftSidebarItem.component'; import LeftSidebarItem from './LeftSidebarItem.component';
const LeftSidebar = () => { const LeftSidebar = () => {
const { sideBarElements } = useApplicationConfigContext();
const { t } = useTranslation(); const { t } = useTranslation();
const { onLogoutHandler } = useAuthContext(); const { onLogoutHandler } = useAuthContext();
const [showConfirmLogoutModal, setShowConfirmLogoutModal] = useState(false); const [showConfirmLogoutModal, setShowConfirmLogoutModal] = useState(false);
@ -92,6 +90,9 @@ const LeftSidebar = () => {
]; ];
}, []); }, []);
const sideBarItems = leftSidebarClassBase.getSidebarItems();
const SideBarElements = leftSidebarClassBase.getSidebarElements();
const handleLogoutClick = () => { const handleLogoutClick = () => {
setShowConfirmLogoutModal(true); setShowConfirmLogoutModal(true);
}; };
@ -103,7 +104,7 @@ const LeftSidebar = () => {
return ( return (
<div className="d-flex flex-col justify-between h-full"> <div className="d-flex flex-col justify-between h-full">
<Row className="p-y-sm"> <Row className="p-y-sm">
{SIDEBAR_LIST.map((item) => ( {sideBarItems.map((item) => (
<Col key={item.key} span={24}> <Col key={item.key} span={24}>
<LeftSidebarItem data={item} /> <LeftSidebarItem data={item} />
</Col> </Col>
@ -115,7 +116,7 @@ const LeftSidebar = () => {
selectedKeys={subMenuItemSelected} selectedKeys={subMenuItemSelected}
triggerSubMenuAction="click" triggerSubMenuAction="click"
/> />
{sideBarElements} {SideBarElements && <SideBarElements />}
</Row> </Row>
<Row className="p-y-sm"> <Row className="p-y-sm">
<Col span={24}> <Col span={24}>

View File

@ -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 };