2020-08-29 21:20:45 +03:00
|
|
|
import { isEmpty, values } from 'ramda';
|
|
|
|
import { DropdownItem, DropdownMenu, DropdownToggle, UncontrolledDropdown } from 'reactstrap';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import ServersExporter from './services/ServersExporter';
|
|
|
|
import { isServerWithId, SelectedServer, ServersMap } from './data';
|
|
|
|
|
|
|
|
export interface ServersDropdownProps {
|
|
|
|
servers: ServersMap;
|
|
|
|
selectedServer: SelectedServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ServersDropdown = (serversExporter: ServersExporter) => ({ servers, selectedServer }: ServersDropdownProps) => {
|
|
|
|
const serversList = values(servers);
|
|
|
|
|
|
|
|
const renderServers = () => {
|
|
|
|
if (isEmpty(serversList)) {
|
|
|
|
return <DropdownItem disabled><i>Add a server first...</i></DropdownItem>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-11-14 00:44:26 +03:00
|
|
|
<>
|
2020-08-29 21:20:45 +03:00
|
|
|
{serversList.map(({ name, id }) => (
|
|
|
|
<DropdownItem
|
|
|
|
key={id}
|
|
|
|
tag={Link}
|
2020-12-08 20:27:36 +03:00
|
|
|
to={`/server/${id}`}
|
2020-08-29 21:20:45 +03:00
|
|
|
active={isServerWithId(selectedServer) && selectedServer.id === id}
|
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</DropdownItem>
|
|
|
|
))}
|
|
|
|
<DropdownItem divider />
|
|
|
|
<DropdownItem className="servers-dropdown__export-item" onClick={async () => serversExporter.exportServers()}>
|
|
|
|
Export servers
|
|
|
|
</DropdownItem>
|
2020-11-14 00:44:26 +03:00
|
|
|
</>
|
2020-08-29 21:20:45 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<UncontrolledDropdown nav inNavbar>
|
|
|
|
<DropdownToggle nav caret>Servers</DropdownToggle>
|
|
|
|
<DropdownMenu right>{renderServers()}</DropdownMenu>
|
|
|
|
</UncontrolledDropdown>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ServersDropdown;
|