-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1737 from CannonLock/namespace-ui
Namespace UI
- Loading branch information
Showing
30 changed files
with
756 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { secureFetch } from '@/helpers/login'; | ||
import React, { useContext, useState } from 'react'; | ||
import { Box, Paper, Typography } from '@mui/material'; | ||
import { NamespaceIcon } from '@/components/Namespace/index'; | ||
import { NamespaceDropdown } from './NamespaceDropdown'; | ||
import { DirectorNamespace, ServerDetailed, ServerGeneral } from '@/types'; | ||
import { getDirectorServer } from '@/helpers/api'; | ||
import { alertOnError } from '@/helpers/util'; | ||
import { AlertDispatchContext } from '@/components/AlertProvider'; | ||
|
||
export interface NamespaceCardProps { | ||
namespace: DirectorNamespace; | ||
} | ||
|
||
export const NamespaceCard = ({ namespace }: NamespaceCardProps) => { | ||
const dispatch = useContext(AlertDispatchContext); | ||
const [dropdownOpen, setDropdownOpen] = useState<boolean>(false); | ||
const [servers, setServers] = useState<ServerDetailed[] | undefined>( | ||
undefined | ||
); | ||
|
||
return ( | ||
<> | ||
<Paper> | ||
<Box | ||
sx={{ | ||
cursor: 'pointer', | ||
display: 'flex', | ||
width: '100%', | ||
justifyContent: 'space-between', | ||
border: 'solid #ececec 1px', | ||
borderRadius: '4px', | ||
transition: 'background-color 0.3s', | ||
p: 1, | ||
}} | ||
onClick={async () => { | ||
setDropdownOpen(!dropdownOpen); | ||
if (servers === undefined) { | ||
alertOnError( | ||
async () => setServers(await getAssociatedServers(namespace)), | ||
'Failed to fetch servers', | ||
dispatch | ||
); | ||
} | ||
}} | ||
> | ||
<Box my={'auto'} ml={1} display={'flex'} flexDirection={'row'}> | ||
<NamespaceIcon serverType={'namespace'} /> | ||
<Typography sx={{ pt: '2px' }}>{namespace.path}</Typography> | ||
</Box> | ||
</Box> | ||
</Paper> | ||
<NamespaceDropdown | ||
namespace={namespace} | ||
servers={servers} | ||
transition={dropdownOpen} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
const getAssociatedServers = async (namespace: DirectorNamespace) => { | ||
const servers = await Promise.all( | ||
[...namespace.origins, ...namespace.caches].map(async (name) => | ||
(await getDirectorServer(name)).json() | ||
) | ||
); | ||
|
||
// 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'); | ||
} | ||
|
||
return servers.filter((s) => s !== undefined) as ServerDetailed[]; | ||
}; | ||
|
||
export default NamespaceCard; |
31 changes: 31 additions & 0 deletions
31
web_ui/frontend/app/director/components/NamespaceCardList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { useState } from 'react'; | ||
import { Box, TextField } from '@mui/material'; | ||
import { NamespaceCard, NamespaceCardProps } from './'; | ||
import { CardList } from '@/components'; | ||
import useFuse from '@/helpers/useFuse'; | ||
|
||
interface NamespaceCardListProps { | ||
data?: Partial<NamespaceCardProps>[]; | ||
} | ||
|
||
export function NamespaceCardList({ data }: NamespaceCardListProps) { | ||
const [search, setSearch] = useState<string>(''); | ||
|
||
const searchedData = useFuse<Partial<NamespaceCardProps>>(data || [], search); | ||
|
||
return ( | ||
<Box> | ||
<Box sx={{ pb: 1 }}> | ||
<TextField | ||
size={'small'} | ||
value={search} | ||
onChange={(e) => setSearch(e.target.value)} | ||
label='Search' | ||
/> | ||
</Box> | ||
<CardList data={searchedData} Card={NamespaceCard} /> | ||
</Box> | ||
); | ||
} | ||
|
||
export default NamespaceCardList; |
Oops, something went wrong.