2020-08-04 12:59:41 +00:00
|
|
|
import React, { useState } from 'react';
|
2020-08-27 12:09:36 +00:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2020-08-04 12:59:41 +00:00
|
|
|
import {
|
|
|
|
Dropdown,
|
|
|
|
DropdownToggle,
|
|
|
|
DropdownItem,
|
|
|
|
Button,
|
|
|
|
} from '@patternfly/react-core';
|
|
|
|
|
|
|
|
import style from './realm-selector.module.css';
|
|
|
|
|
|
|
|
type RealmSelectorProps = {
|
|
|
|
realm: string;
|
|
|
|
realmList: string[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const RealmSelector = ({ realm, realmList }: RealmSelectorProps) => {
|
|
|
|
const [open, setOpen] = useState(false);
|
2020-08-27 12:09:36 +00:00
|
|
|
const history = useHistory();
|
2020-08-04 12:59:41 +00:00
|
|
|
const dropdownItems = realmList.map((r) => (
|
2020-08-27 12:09:36 +00:00
|
|
|
<DropdownItem component="a" href="/" key={r}>
|
|
|
|
{r}
|
|
|
|
</DropdownItem>
|
2020-08-04 12:59:41 +00:00
|
|
|
));
|
|
|
|
return (
|
|
|
|
<Dropdown
|
|
|
|
id="realm-select"
|
|
|
|
className={style.dropdown}
|
|
|
|
isOpen={open}
|
|
|
|
toggle={
|
|
|
|
<DropdownToggle
|
|
|
|
id="realm-select-toggle"
|
|
|
|
onToggle={() => setOpen(!open)}
|
|
|
|
className={style.toggle}
|
|
|
|
>
|
|
|
|
{realm}
|
|
|
|
</DropdownToggle>
|
|
|
|
}
|
|
|
|
dropdownItems={[
|
|
|
|
...dropdownItems,
|
2020-08-27 12:09:36 +00:00
|
|
|
<DropdownItem component="div" key="add">
|
|
|
|
<Button onClick={() => history.push('/add-realm')}>Add Realm</Button>
|
2020-08-04 12:59:41 +00:00
|
|
|
</DropdownItem>,
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|