Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Nov 19, 2024
1 parent 0ac23a2 commit 483dbf0
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 66 deletions.
25 changes: 11 additions & 14 deletions web_ui/frontend/app/director/components/NamespaceCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { secureFetch } from '@/helpers/login';
import React, { useState } from 'react';
import {
Box,
Paper,
Typography,
} from '@mui/material';
import { Box, Paper, Typography } from '@mui/material';
import { NamespaceIcon } from '@/components/Namespace/index';
import { NamespaceDropdown } from './NamespaceDropdown';
import { Namespace, ServerDetailed, ServerGeneral } from '@/types';
Expand All @@ -15,7 +11,9 @@ export interface NamespaceCardProps {

export const NamespaceCard = ({ namespace }: NamespaceCardProps) => {
const [dropdownOpen, setDropdownOpen] = useState<boolean>(false);
const [servers, setServers] = useState<ServerDetailed[] | undefined>(undefined);
const [servers, setServers] = useState<ServerDetailed[] | undefined>(
undefined
);

return (
<>
Expand All @@ -39,9 +37,7 @@ export const NamespaceCard = ({ namespace }: NamespaceCardProps) => {
}}
>
<Box my={'auto'} ml={1} display={'flex'} flexDirection={'row'}>
<NamespaceIcon
serverType={'namespace'}
/>
<NamespaceIcon serverType={'namespace'} />
<Typography sx={{ pt: '2px' }}>{namespace.path}</Typography>
</Box>
</Box>
Expand All @@ -56,16 +52,17 @@ export const NamespaceCard = ({ namespace }: NamespaceCardProps) => {
};

const getAssociatedServers = async (namespace: Namespace) => {
const servers = await Promise.all([...namespace.origins, ...namespace.caches].map(getServer));
const servers = await Promise.all(
[...namespace.origins, ...namespace.caches].map(getServer)
);

// Alert the console if any servers are undefined, as this is unlikely to happen naturally
if(servers.some((s) => s === undefined)) {
console.error("Failed to fetch all servers, some are undefined");
if (servers.some((s) => s === undefined)) {
console.error('Failed to fetch all servers, some are undefined');
}

return servers.filter((s) => s !== undefined) as ServerDetailed[];

}
};

// TODO: Consolidate this when https://github.com/PelicanPlatform/pelican/pull/1687 is merged
const getServer = async (name: string): Promise<ServerDetailed | undefined> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React, {
useState
} from 'react';
import React, { useState } from 'react';
import { Box, TextField } from '@mui/material';
import { NamespaceCard, NamespaceCardProps } from './';
import { CardList } from '@/components';
Expand Down
62 changes: 43 additions & 19 deletions web_ui/frontend/app/director/components/NamespaceDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface NamespaceDropdownProps {
export const NamespaceDropdown = ({
namespace,
servers,
transition
transition,
}: NamespaceDropdownProps) => {
return (
<>
Expand All @@ -22,33 +22,57 @@ export const NamespaceDropdown = ({
<Grid item xs={12} md={12}>
<InformationSpan name={'Path'} value={namespace.path} />
<InformationSpanHeader title={'Token Generation'} />
{namespace.tokenGeneration?.map((tg) =>
{namespace.tokenGeneration?.map((tg) => (
<Fragment key={tg.issuer}>
<InformationSpan indent={1} name={'Issuer'} value={tg.issuer} />
<InformationSpan indent={2} name={'Strategy'} value={tg.strategy} />
<InformationSpan indent={2} name={'VaultServer'} value={tg.vaultServer} />
<InformationSpan indent={2} name={'Max Scope Depth'} value={tg.maxScopeDepth.toString()} />
<InformationSpan
indent={2}
name={'Strategy'}
value={tg.strategy}
/>
<InformationSpan
indent={2}
name={'VaultServer'}
value={tg.vaultServer}
/>
<InformationSpan
indent={2}
name={'Max Scope Depth'}
value={tg.maxScopeDepth.toString()}
/>
</Fragment>
)}
))}
<InformationSpanHeader title={'Token Issuer'} />
{namespace.tokenIssuer?.map((ti) =>
{namespace.tokenIssuer?.map((ti) => (
<Fragment key={ti.issuer}>
<InformationSpan indent={1} name={'Issuer'} value={ti.issuer} />
<InformationSpanHeader indent={2} title={"Base Paths"} />
{ti.basePaths.map((bp) =>
<InformationSpan key={bp} indent={3} name={'Base Path'} value={bp} />
)}
{ ti.restrictedPaths && (
<InformationSpanHeader indent={2} title={'Base Paths'} />
{ti.basePaths.map((bp) => (
<InformationSpan
key={bp}
indent={3}
name={'Base Path'}
value={bp}
/>
))}
{ti.restrictedPaths && (
<>
<InformationSpanHeader indent={2} title={"Restricted Paths"} />
{ti.restrictedPaths?.map((rp) =>
<InformationSpan key={rp} indent={3} name={'Restricted Path'} value={rp} />
)}
<InformationSpanHeader
indent={2}
title={'Restricted Paths'}
/>
{ti.restrictedPaths?.map((rp) => (
<InformationSpan
key={rp}
indent={3}
name={'Restricted Path'}
value={rp}
/>
))}
</>
)
}
)}
</Fragment>
)}
))}
</Grid>
</Grid>
<Box sx={{ my: 1 }}>
Expand Down
20 changes: 14 additions & 6 deletions web_ui/frontend/app/director/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import { NamespaceCardList } from './components/NamespaceCardList';

export default function Page() {
const { data } = useSWR<ServerGeneral[]>('getServers', getServers);
const { data: namespaces } = useSWR<Namespace[]>('getNamespaces', getNamespaces);
const { data: namespaces } = useSWR<Namespace[]>(
'getNamespaces',
getNamespaces
);

const { data: user, error } = useSWR('getUser', getUser);

Expand Down Expand Up @@ -87,9 +90,11 @@ export default function Page() {
</Typography>
{cacheData ? (
<NamespaceCardList
data={namespaces?.map((namespace) => {
return {namespace}
}) || []}
data={
namespaces?.map((namespace) => {
return { namespace };
}) || []
}
/>
) : (
<Box>
Expand Down Expand Up @@ -122,7 +127,10 @@ const getServers = async () => {
};

const getNamespaces = async () => {
const url = new URL('/api/v1.0/director_ui/namespaces', window.location.origin);
const url = new URL(
'/api/v1.0/director_ui/namespaces',
window.location.origin
);

let response = await fetch(url);
if (response.ok) {
Expand All @@ -132,4 +140,4 @@ const getNamespaces = async () => {
}

throw new Error('Failed to fetch servers');
}
};
21 changes: 12 additions & 9 deletions web_ui/frontend/components/InformationSpan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import React, { ReactNode } from 'react';

export const InformationSpanHeader = ({
title,
indent = 0
indent = 0,
}: {
title: string,
indent?: number
title: string;
indent?: number;
}) => {
return (
<Box
Expand All @@ -25,18 +25,19 @@ export const InformationSpanHeader = ({
}}
>
<Typography variant={'body2'} sx={{ display: 'inline', mr: 2 }}>
{"\u00A0\u00A0\u00A0\u00A0".repeat(Math.max(indent - 1, 0))}{indent > 0 ? "↳\u00A0" : ""}{title}
</Typography>
<Typography variant={'body2'} sx={{ display: 'inline' }}>
{'\u00A0\u00A0\u00A0\u00A0'.repeat(Math.max(indent - 1, 0))}
{indent > 0 ? '↳\u00A0' : ''}
{title}
</Typography>
<Typography variant={'body2'} sx={{ display: 'inline' }}></Typography>
</Box>
);
}
};

export const InformationSpan = ({
name,
value,
indent = 0
indent = 0,
}: {
name: string;
value: string;
Expand All @@ -58,7 +59,9 @@ export const InformationSpan = ({
}}
>
<Typography variant={'body2'} sx={{ display: 'inline', mr: 2 }}>
{"\u00A0\u00A0\u00A0\u00A0".repeat(Math.max(indent - 1, 0))}{indent > 0 ? "↳\u00A0" : ""}{name}:
{'\u00A0\u00A0\u00A0\u00A0'.repeat(Math.max(indent - 1, 0))}
{indent > 0 ? '↳\u00A0' : ''}
{name}:
</Typography>
<Typography variant={'body2'} sx={{ display: 'inline' }}>
{value}
Expand Down
17 changes: 8 additions & 9 deletions web_ui/frontend/components/Namespace/NamespaceIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const NamespaceIcon = ({
color?: string;
bgcolor?: string;
}) => {

const avatarPixelSize = useMemo(() => {
switch (size) {
case 'large':
Expand All @@ -25,7 +24,7 @@ const NamespaceIcon = ({
default:
return 30;
}
}, [size])
}, [size]);

const iconPixelSize = useMemo(() => {
switch (size) {
Expand All @@ -38,7 +37,7 @@ const NamespaceIcon = ({
default:
return 24;
}
}, [])
}, []);

if (serverType == 'namespace') {
return (
Expand All @@ -51,10 +50,10 @@ const NamespaceIcon = ({
width: avatarPixelSize,
my: 'auto',
mr: 1,
bgcolor
bgcolor,
}}
>
<FolderOpen sx={{fontSize: iconPixelSize}} htmlColor={color} />
<FolderOpen sx={{ fontSize: iconPixelSize }} htmlColor={color} />
</Avatar>
</Tooltip>
</Box>
Expand All @@ -72,10 +71,10 @@ const NamespaceIcon = ({
width: avatarPixelSize,
my: 'auto',
mr: 1,
bgcolor
bgcolor,
}}
>
<TripOrigin sx={{fontSize: iconPixelSize}} htmlColor={color} />
<TripOrigin sx={{ fontSize: iconPixelSize }} htmlColor={color} />
</Avatar>
</Tooltip>
</Box>
Expand All @@ -93,10 +92,10 @@ const NamespaceIcon = ({
width: avatarPixelSize,
my: 'auto',
mr: 1,
bgcolor
bgcolor,
}}
>
<Storage sx={{fontSize: iconPixelSize}} htmlColor={color} />
<Storage sx={{ fontSize: iconPixelSize }} htmlColor={color} />
</Avatar>
</Tooltip>
</Box>
Expand Down
22 changes: 16 additions & 6 deletions web_ui/frontend/components/NamespaceCapabilitiesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { grey } from '@mui/material/colors';
import { NamespaceIcon } from '@/components/Namespace';

interface NamespaceCapabilitiesTableProps {
namespace: Namespace
servers?: ServerDetailed[]
namespace: Namespace;
servers?: ServerDetailed[];
}

/**
Expand All @@ -26,9 +26,8 @@ interface NamespaceCapabilitiesTableProps {
*/
export const NamespaceCapabilitiesTable = ({
namespace,
servers
servers,
}: NamespaceCapabilitiesTableProps) => {

const theme = useTheme();

return (
Expand Down Expand Up @@ -64,8 +63,19 @@ export const NamespaceCapabilitiesTable = ({
<Grid container spacing={1}>
<Grid item xs={3}>
<Box display={'flex'} height={'100%'}>
<Typography variant={'body2'} my={'auto'} display={"flex"}>
<NamespaceIcon serverType={server.type.toLowerCase() as 'origin' | 'cache'} size={"small"} bgcolor={"white"} color={theme.palette.primary.main} />
<Typography
variant={'body2'}
my={'auto'}
display={'flex'}
>
<NamespaceIcon
serverType={
server.type.toLowerCase() as 'origin' | 'cache'
}
size={'small'}
bgcolor={'white'}
color={theme.palette.primary.main}
/>
{server.name}
</Typography>
</Box>
Expand Down

0 comments on commit 483dbf0

Please sign in to comment.