-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeader.tsx
More file actions
144 lines (129 loc) · 4.1 KB
/
Header.tsx
File metadata and controls
144 lines (129 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React from "react";
import { useNavigate, useLocation } from "react-router-dom";
import { useHeaderHooks, Header } from "../../Hooks/useHeaderHooks.tsx";
import {
TabList,
Tab,
TabValue,
Menu,
MenuTrigger,
MenuPopover,
MenuList,
MenuItem,
MenuDivider,
Avatar,
} from "@fluentui/react-components";
import { ArrowExit } from "../../Imports/bundleIcons.tsx";
import MainLogo from "../../Imports/MainLogo.svg";
import "./Header.css";
import { DocumentBulletListCubeRegular, InfoRegular } from "@fluentui/react-icons"
import useAuth from "../../msal-auth/useAuth.ts";
import { useSelector, shallowEqual } from 'react-redux';
import { RootState } from '../../store/index.ts';
import useSwaggerPreview from "../../Hooks/useSwaggerPreview.ts";
interface HeaderPageProps {
toggleTheme: () => void;
isDarkMode: boolean;
}
const tabConfigs = [
{
icon: <DocumentBulletListCubeRegular />, // Import bundle icon
value: "default", // Route path defined in App.tsx
label: "Content", // Visible label on UI
},
{
icon: <DocumentBulletListCubeRegular />, // Import bundle icon
value: "api", // Route path defined in App.tsx
label: "API Documentation", // Visible label on UI
},
// Add more
];
const HeaderPage: React.FC<HeaderPageProps> = ({ toggleTheme, isDarkMode }) => {
const { user, logout } = useAuth();
const authEnabled = process.env.REACT_APP_AUTH_ENABLED?.toLowerCase() !== 'false'; // Defaults to true if not set
const { openSwaggerUI } = useSwaggerPreview();
const store = useSelector((state: RootState) => ({
swaggerJSON: state.leftPanel.swaggerJSON,
}), shallowEqual);
const navigate = useNavigate();
const location = useLocation();
//const fetchWithAuth = useApiFetch();
// Map routes to TabValues
const tabRoutes: { [key: string]: TabValue } = {
"/home": "home",
"/default": "default",
"/auxiliary": "auxiliary",
};
// Get the current tab based on the route
const currentTab =
Object.keys(tabRoutes).find((route) =>
location.pathname.startsWith(route)
) || "/home"; // Default to "home"
const handleTabChange = (
_: React.SyntheticEvent,
data: { value: TabValue }
) => {
if (data.value == 'api') {
_.preventDefault();
const apiUrl: string = process.env.REACT_APP_API_BASE_URL as string;
const token = localStorage.getItem('token') ?? undefined;
openSwaggerUI(store.swaggerJSON, apiUrl, token)
} else {
const newRoute = Object.keys(tabRoutes).find(
(key) => tabRoutes[key] === data.value
);
if (newRoute) {
navigate(newRoute);
}
}
};
return (
<Header
avatarSrc={MainLogo} // Profile icon for businesses
title="Content Processing" // Site title
subtitle="Accelerator" // Optional subtitle
badge="" // Optional badge
>
<div className="headerNav">
<TabList
selectedValue={tabRoutes[currentTab]}
onTabSelect={handleTabChange}
aria-label="Site Navigation Tabs"
size="small"
>
{tabConfigs.map(({ icon, value, label }) => (
<Tab key={value} icon={icon} value={value}>
{label}
</Tab>
))}
</TabList>
</div>
<div className="headerTag">
<InfoRegular style={{ marginRight: "4px" }} />
<span>AI-generated content may be incorrect</span>
</div>
{/* Tools Section */}
{ authEnabled &&
<div className="headerTools">
<Menu hasIcons positioning={{ autoSize: true }}>
<MenuTrigger disableButtonEnhancement>
<Avatar
color="colorful"
name={user?.name}
aria-label="App"
className="clickable-avatar"
/>
</MenuTrigger>
<MenuPopover style={{ minWidth: "192px" }}>
<MenuList>
<MenuDivider />
<MenuItem icon={<ArrowExit />} onClick={logout}>Logout</MenuItem>
</MenuList>
</MenuPopover>
</Menu>
</div>
}
</Header>
);
};
export default HeaderPage;