diff --git a/web_ui/frontend/app/config/Config.tsx b/web_ui/frontend/app/config/Config.tsx index 0505e1c28..4badc6199 100644 --- a/web_ui/frontend/app/config/Config.tsx +++ b/web_ui/frontend/app/config/Config.tsx @@ -77,7 +77,10 @@ function Config({ metadata }: { metadata: ParameterMetadataRecord }) { 'getConfig', async () => await alertOnError( - async () => (await getConfig()).json(), 'Could not get config', dispatch) + async () => (await getConfig()).json(), + 'Could not get config', + dispatch + ) ); const serverConfig = useMemo(() => { diff --git a/web_ui/frontend/app/director/components/GeoIpErrorTable.tsx b/web_ui/frontend/app/director/components/GeoIpErrorTable.tsx index 4e89504c8..ef133090c 100644 --- a/web_ui/frontend/app/director/components/GeoIpErrorTable.tsx +++ b/web_ui/frontend/app/director/components/GeoIpErrorTable.tsx @@ -19,98 +19,131 @@ import { tableCellClasses } from '@mui/material/TableCell'; import useSWR from 'swr'; import { query_raw, VectorResponseData } from '@/components'; -import { GeoIPOverride, GeoIPOverrideForm, ParameterValueRecord, submitConfigChange } from '@/components/configuration'; +import { + GeoIPOverride, + GeoIPOverrideForm, + ParameterValueRecord, + submitConfigChange, +} from '@/components/configuration'; import { alertOnError } from '@/helpers/util'; import { Dispatch, useCallback, useContext, useMemo, useState } from 'react'; -import { AlertDispatchContext, AlertReducerAction } from '@/components/AlertProvider'; +import { + AlertDispatchContext, + AlertReducerAction, +} from '@/components/AlertProvider'; import { getConfig } from '@/helpers/api'; import LatitudeLongitudePicker from '@/components/LatitudeLongitudePicker'; import ObjectModal from '@/components/configuration/Fields/ObjectField/ObjectModal'; import CircularProgress from '@mui/material/CircularProgress'; const GeoIpErrorTable = () => { - const dispatch = useContext(AlertDispatchContext); - const {data: ipErrors} = useSWR('geoip_errors', getIpErrorRows) + const { data: ipErrors } = useSWR('geoip_errors', getIpErrorRows); - const { data: config, mutate, error, isValidating } = useSWR( + const { + data: config, + mutate, + error, + isValidating, + } = useSWR( 'getConfig', async () => await alertOnError(getOverriddenGeoIps, 'Could not get config', dispatch) ); const patchedIps = useMemo(() => { - return config?.GeoIPOverrides === undefined ? - [] : - Object.values(config.GeoIPOverrides).map((x: GeoIPOverride) => x.ip) - }, [config]) - const [geoIPOverrides, setGeoIPOverrides] = useState>({}) + return config?.GeoIPOverrides === undefined + ? [] + : Object.values(config.GeoIPOverrides).map((x: GeoIPOverride) => x.ip); + }, [config]); + const [geoIPOverrides, setGeoIPOverrides] = useState< + Record + >({}); - const [open, setOpen] = useState(false) - const [ip, setIp] = useState("") + const [open, setOpen] = useState(false); + const [ip, setIp] = useState(''); const onSubmit = useCallback((x: GeoIPOverride) => { setGeoIPOverrides((p) => { - return {...p, [x.ip]: x} - }) - setOpen(false) - }, []) + return { ...p, [x.ip]: x }; + }); + setOpen(false); + }, []); return ( <> - + Un-located Networks - {isValidating && } + {isValidating && } - - - + + +
Un-located Network - Project - Source - # of Errors - Locate + Project + Source + # of Errors + Locate - {ipErrors && ipErrors - .filter((x) => !patchedIps.includes(x.metric?.network)) - .sort((a, b) => parseInt(b.value[1]) - parseInt(a.value[1])) - .map((row) => ( - - {row.metric?.network} - {row.metric?.proj} - {row.metric?.source} - {parseInt(row.value[1]).toLocaleString()} - - - - - ))} + {row.metric?.network} + {row.metric?.proj} + {row.metric?.source} + + {parseInt(row.value[1]).toLocaleString()} + + + + + + ))}
{Object.keys(geoIPOverrides).length > 0 && ( )}
- setOpen(!open)} open={open}> - + setOpen(!open)} + open={open} + > + - ) -} + ); +}; interface GeoUpdateFormProps { open: boolean; @@ -132,30 +172,30 @@ interface GeoUpdateFormProps { } const StyledTableCell = styled(TableCell)(({ theme }) => ({ - [`&.${tableCellClasses.head}`]: { - backgroundColor: theme.palette.warning.main + backgroundColor: theme.palette.warning.main, }, })); const getIpErrorRows = async () => { - const response = await query_raw("last_over_time(pelican_director_geoip_errors[1d])") - return response.data.result -} + const response = await query_raw( + 'last_over_time(pelican_director_geoip_errors[1d])' + ); + return response.data.result; +}; const getOverriddenGeoIps = async () => { - let tries = 0 - while(tries < 2) { + let tries = 0; + while (tries < 2) { try { - const response = await getConfig() - const config = await response.json() - return {GeoIPOverrides: config.GeoIPOverrides} - } catch(e) { - tries++ - await new Promise(r => setTimeout(r, (10 ** tries) * 500)); - + const response = await getConfig(); + const config = await response.json(); + return { GeoIPOverrides: config.GeoIPOverrides }; + } catch (e) { + tries++; + await new Promise((r) => setTimeout(r, 10 ** tries * 500)); } } -} +}; export default GeoIpErrorTable; diff --git a/web_ui/frontend/components/LatitudeLongitudePicker.tsx b/web_ui/frontend/components/LatitudeLongitudePicker.tsx index 818f9bf57..e871da6ed 100644 --- a/web_ui/frontend/components/LatitudeLongitudePicker.tsx +++ b/web_ui/frontend/components/LatitudeLongitudePicker.tsx @@ -25,7 +25,7 @@ const LatitudeLongitudePicker = ({