github.com/pelicanplatform/pelican@v1.0.5/web_ui/frontend/components/FederationOverview.tsx (about)

     1  'use client'
     2  
     3  import LaunchIcon from '@mui/icons-material/Launch';
     4  import {useEffect, useState} from "react";
     5  import {Config} from "@/app/config/page";
     6  import {Box, Typography} from "@mui/material";
     7  import {isLoggedIn} from "@/helpers/login";
     8  import Link from "next/link";
     9  
    10  
    11  const LinkBox = ({href, text} : {href: string, text: string}) => {
    12      return (
    13          <Link href={href}>
    14              <Box p={1} px={2} display={"flex"} flexDirection={"row"} bgcolor={"info.light"} borderRadius={2} mb={1}>
    15                  <Typography sx={{pb: 0}}>
    16                      {text}
    17                  </Typography>
    18                  <Box ml={"auto"} my={"auto"} display={"flex"}>
    19                      <LaunchIcon/>
    20                  </Box>
    21              </Box>
    22          </Link>
    23      )
    24  }
    25  
    26  const FederationOverview = () => {
    27  
    28      const [config, setConfig] = useState<{ [key: string] : string | undefined} | undefined>(undefined)
    29  
    30      let getConfig = async () => {
    31  
    32          //Check if the user is logged in
    33          if(!(await isLoggedIn())){
    34              window.location.replace("/view/login/")
    35          }
    36  
    37          let response = await fetch("/api/v1.0/config")
    38          if(response.ok) {
    39              const responseData = await response.json() as Config
    40  
    41              setConfig({
    42                  JwkUrl: (responseData?.Federation as Config)?.NamespaceUrl as undefined | string,
    43                  NamespaceUrl: (responseData?.Federation as Config)?.NamespaceUrl as undefined | string,
    44                  DirectorUrl: (responseData?.Federation as Config)?.DirectorUrl as undefined | string,
    45                  TopologyNamespaceUrl: (responseData?.Federation as Config)?.TopologyNamespaceUrl as undefined | string,
    46                  DiscoveryUrl: (responseData?.Federation as Config)?.DiscoveryUrl as undefined | string,
    47              })
    48          } else {
    49              console.error("Failed to fetch config for Federation Overview, response status: " + response.status)
    50          }
    51      }
    52  
    53      useEffect(() => {
    54          getConfig()
    55      }, [])
    56  
    57      if(config === undefined) {
    58          return
    59      }
    60  
    61      return (
    62  
    63          <Box>
    64              {!Object.values(config).every(x => x == undefined) ? <Typography variant={"h4"} component={"h2"}  mb={2}>Federation Overview</Typography> : null}
    65              {config?.NamespaceUrl ?
    66                  <LinkBox href={config?.NamespaceUrl} text={"Namespace Registry"}/> : null
    67              }
    68              {config?.DirectorUrl ?
    69                  <LinkBox href={config?.DirectorUrl} text={"Director"}/> : null
    70              }
    71              {config?.TopologyNamespaceUrl ?
    72                  <LinkBox href={config?.TopologyNamespaceUrl} text={"Topology Namespace"}/> : null
    73              }
    74              {config?.DiscoveryUrl ?
    75                  <LinkBox href={config?.DiscoveryUrl} text={"Discovery"}/> : null
    76              }
    77              {config?.JwkUrl ?
    78                  <LinkBox href={config?.JwkUrl} text={"JWK"}/> : null
    79              }
    80  
    81          </Box>
    82      )
    83  }
    84  
    85  export default FederationOverview;