mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-24 01:50:06 +00:00
90 lines
3.0 KiB
TypeScript
90 lines
3.0 KiB
TypeScript
![]() |
import React, { useState } from 'react';
|
||
|
import { Link } from 'react-router-dom';
|
||
|
import { Menu } from 'antd';
|
||
|
import styled from 'styled-components';
|
||
|
import { BankOutlined, BarChartOutlined, MenuOutlined } from '@ant-design/icons';
|
||
|
import Sider from 'antd/lib/layout/Sider';
|
||
|
import { useGetAuthenticatedUser } from './useGetAuthenticatedUser';
|
||
|
import { useAppConfig } from './useAppConfig';
|
||
|
import { ANTD_GRAY } from './entity/shared/constants';
|
||
|
|
||
|
const ToggleContainer = styled.div`
|
||
|
background-color: ${ANTD_GRAY[4]};
|
||
|
border-top-right-radius: 2px;
|
||
|
border-bottom-right-radius: 2px;
|
||
|
`;
|
||
|
|
||
|
const ControlMenu = styled(Menu)`
|
||
|
padding-top: 28px;
|
||
|
height: 100%;
|
||
|
`;
|
||
|
|
||
|
const ControlSlideOut = styled(Sider)``;
|
||
|
|
||
|
/**
|
||
|
* Container for all views behind an authentication wall.
|
||
|
*/
|
||
|
export const AdminConsole = (): JSX.Element => {
|
||
|
const me = useGetAuthenticatedUser();
|
||
|
|
||
|
const [adminConsoleOpen, setAdminConsoleOpen] = useState(false);
|
||
|
const { config } = useAppConfig();
|
||
|
|
||
|
const isAnalyticsEnabled = config?.analyticsConfig.enabled;
|
||
|
const isPoliciesEnabled = config?.policiesConfig.enabled;
|
||
|
|
||
|
const showAnalytics = (isAnalyticsEnabled && me && me.platformPrivileges.viewAnalytics) || false;
|
||
|
const showPolicyBuilder = (isPoliciesEnabled && me && me.platformPrivileges.managePolicies) || false;
|
||
|
const showAdminConsole = showAnalytics || showPolicyBuilder;
|
||
|
|
||
|
const onMenuItemClick = () => {
|
||
|
setAdminConsoleOpen(false);
|
||
|
};
|
||
|
|
||
|
const onCollapse = (collapsed) => {
|
||
|
if (collapsed) {
|
||
|
setAdminConsoleOpen(false);
|
||
|
} else {
|
||
|
setAdminConsoleOpen(true);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const toggleView = (
|
||
|
<ToggleContainer style={{}}>
|
||
|
<MenuOutlined style={{ color: ANTD_GRAY[9] }} />
|
||
|
</ToggleContainer>
|
||
|
);
|
||
|
|
||
|
return (
|
||
|
<>
|
||
|
{showAdminConsole && (
|
||
|
<ControlSlideOut
|
||
|
zeroWidthTriggerStyle={{ top: '90%' }}
|
||
|
collapsible
|
||
|
collapsed={!adminConsoleOpen}
|
||
|
onCollapse={onCollapse}
|
||
|
collapsedWidth="0"
|
||
|
trigger={toggleView}
|
||
|
>
|
||
|
<ControlMenu selectable={false} mode="inline" onSelect={onMenuItemClick}>
|
||
|
{showAnalytics && (
|
||
|
<Menu.Item key="analytics" icon={<BarChartOutlined />}>
|
||
|
<Link onClick={onMenuItemClick} to="/analytics">
|
||
|
Analytics
|
||
|
</Link>
|
||
|
</Menu.Item>
|
||
|
)}
|
||
|
{showPolicyBuilder && (
|
||
|
<Menu.Item key="policies" icon={<BankOutlined />}>
|
||
|
<Link onClick={onMenuItemClick} to="/policies">
|
||
|
Policies
|
||
|
</Link>
|
||
|
</Menu.Item>
|
||
|
)}
|
||
|
</ControlMenu>
|
||
|
</ControlSlideOut>
|
||
|
)}
|
||
|
</>
|
||
|
);
|
||
|
};
|