shlink-web-client/src/servers/ServersDropdown.tsx

49 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-10-17 19:13:06 +02:00
import { faPlus as plusIcon, faServer as serverIcon } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
2023-02-18 11:11:01 +01:00
import { Link } from 'react-router-dom';
import { DropdownItem, DropdownMenu, DropdownToggle, UncontrolledDropdown } from 'reactstrap';
2023-02-18 10:40:37 +01:00
import type { SelectedServer, ServersMap } from './data';
import { getServerId } from './data';
export interface ServersDropdownProps {
servers: ServersMap;
selectedServer: SelectedServer;
}
export const ServersDropdown = ({ servers, selectedServer }: ServersDropdownProps) => {
2023-11-01 10:03:09 +01:00
const serversList = Object.values(servers);
const renderServers = () => {
2023-11-01 10:03:09 +01:00
if (serversList.length === 0) {
2021-10-17 19:13:06 +02:00
return (
<DropdownItem tag={Link} to="/server/create">
<FontAwesomeIcon icon={plusIcon} /> <span className="ms-1">Add a server</span>
2021-10-17 19:13:06 +02:00
</DropdownItem>
);
}
return (
2020-11-13 22:44:26 +01:00
<>
{serversList.map(({ name, id }) => (
<DropdownItem key={id} tag={Link} to={`/server/${id}`} active={getServerId(selectedServer) === id}>
{name}
</DropdownItem>
))}
2023-09-30 10:45:52 +02:00
<DropdownItem divider tag="hr" />
2021-10-17 19:13:06 +02:00
<DropdownItem tag={Link} to="/manage-servers">
<FontAwesomeIcon icon={serverIcon} /> <span className="ms-1">Manage servers</span>
</DropdownItem>
2020-11-13 22:44:26 +01:00
</>
);
};
return (
<UncontrolledDropdown nav inNavbar>
<DropdownToggle nav caret>
<FontAwesomeIcon icon={serverIcon} /> <span className="ms-1">Servers</span>
</DropdownToggle>
2022-03-11 16:37:41 +01:00
<DropdownMenu end style={{ right: 0 }}>{renderServers()}</DropdownMenu>
</UncontrolledDropdown>
);
};