import React, {useEffect, useState} from "react"; import {useTranslation} from "react-i18next"; import {Outlet, useParams} from "react-router-dom"; import {useNavigation} from "../../hooks/navigationHook"; import { faCampground, faChartArea, faChartLine, faCogs, faCubes, faGlobe, faInfoCircle, faLocationArrow, faSearch, faUserGroup, faUsers } from "@fortawesome/free-solid-svg-icons"; import {useAuth} from "../../hooks/authenticationHook"; import Sidebar from "../../components/navigation/Sidebar"; import Header from "../../components/navigation/Header"; import ColorSelectorModal from "../../components/modal/ColorSelectorModal"; import {useMetadata} from "../../hooks/metadataHook"; import {faCalendarCheck} from "@fortawesome/free-regular-svg-icons"; import ErrorPage from "./ErrorPage"; import {SwitchTransition} from "react-transition-group"; import MainPageRedirect from "../../components/navigation/MainPageRedirect"; import {useDataRequest} from "../../hooks/dataFetchHook"; import {fetchServerIdentity} from "../../service/serverService"; import {ServerExtensionContextProvider, useServerExtensionContext} from "../../hooks/serverExtensionDataContext"; import {iconTypeToFontAwesomeClass} from "../../util/icons"; import {staticSite} from "../../service/backendConfiguration"; const ServerSidebar = () => { const {t, i18n} = useTranslation(); const {sidebarItems, setSidebarItems} = useNavigation(); const {extensionData} = useServerExtensionContext(); useEffect(() => { const items = [ {name: 'html.label.serverOverview', icon: faInfoCircle, href: "overview"}, {}, {name: 'html.label.information'}, { name: 'html.label.onlineActivity', icon: faChartArea, contents: [ { nameShort: 'html.label.overview', name: 'html.label.playersOnlineOverview', icon: faChartArea, href: "online-activity" }, {name: 'html.label.sessions', icon: faCalendarCheck, href: "sessions"}, {name: 'html.label.pvpPve', icon: faCampground, href: "pvppve"} ] }, { name: 'html.label.playerbase', icon: faUsers, contents: [ { nameShort: 'html.label.overview', name: 'html.label.playerbaseOverview', icon: faChartLine, href: "playerbase" }, {name: 'html.label.joinAddresses', icon: faLocationArrow, href: "join-addresses"}, // {name: 'html.label.playerRetention', icon: faUsersViewfinder, href: "retention"}, {name: 'html.label.playerList', icon: faUserGroup, href: "players"}, {name: 'html.label.geolocations', icon: faGlobe, href: "geolocations"}, ] }, {name: 'html.label.performance', icon: faCogs, href: "performance"}, {}, {name: 'html.label.plugins'}, {name: 'html.label.pluginsOverview', icon: faCubes, href: "plugins-overview"} ] if (extensionData) { extensionData.extensions.filter(extension => extension.wide) .map(extension => extension.extensionInformation) .map(info => { return { name: info.pluginName, icon: [iconTypeToFontAwesomeClass(info.icon.family), info.icon.iconName], href: `plugins/${encodeURIComponent(info.pluginName)}` } }).forEach(item => items.push(item)) } if (!staticSite) { items.push( {}, {name: 'html.label.links'}, {name: 'html.label.query', icon: faSearch, href: "/query"} ); } setSidebarItems(items); window.document.title = `Plan | Server Analysis`; }, [t, i18n, extensionData, setSidebarItems]) return ( ) } const ServerPage = () => { const {t} = useTranslation(); const {identifier} = useParams(); const {isProxy, serverName, networkMetadata} = useMetadata(); const { data: serverIdentity, loadingError: identityLoadingError } = useDataRequest(fetchServerIdentity, [identifier]); const [error] = useState(undefined); const {currentTab} = useNavigation(); const {authRequired, loggedIn} = useAuth(); if (authRequired && !loggedIn) return const getDisplayedServerName = () => { if (serverIdentity) { return serverIdentity.serverName; } if (isProxy) { const fromMetadata = networkMetadata?.servers?.find(server => server.serverUUID === identifier); return fromMetadata ? fromMetadata.serverName : identifier; } else { return serverName && serverName.startsWith('Server') ? "Plan" : serverName } } const displayedServerName = getDisplayedServerName(); if (error) return ; if (identityLoadingError) { if (identityLoadingError.status === 404) return return } return ( <>
) } export default ServerPage;