2020-09-04 18:16:11 +00:00
|
|
|
import React, { useState, useContext, useEffect } from "react";
|
2020-09-01 14:51:59 +00:00
|
|
|
import { useHistory } from "react-router-dom";
|
2020-09-10 18:04:03 +00:00
|
|
|
import { Realm } from "../../realm/models/Realm";
|
2020-09-04 18:16:11 +00:00
|
|
|
|
2020-08-04 12:59:41 +00:00
|
|
|
import {
|
|
|
|
Dropdown,
|
|
|
|
DropdownToggle,
|
|
|
|
DropdownItem,
|
|
|
|
Button,
|
2020-09-04 18:16:11 +00:00
|
|
|
Divider,
|
2020-09-01 14:51:59 +00:00
|
|
|
} from "@patternfly/react-core";
|
2020-08-04 12:59:41 +00:00
|
|
|
|
2020-09-14 18:10:54 +00:00
|
|
|
import "./realm-selector.css";
|
2020-08-04 12:59:41 +00:00
|
|
|
|
2020-09-08 17:20:29 +00:00
|
|
|
type RealmSelectorProps = {
|
|
|
|
realm: string;
|
|
|
|
realmList: Realm[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const RealmSelector = ({ realm, realmList }: RealmSelectorProps) => {
|
2020-08-04 12:59:41 +00:00
|
|
|
const [open, setOpen] = useState(false);
|
2020-08-27 12:09:36 +00:00
|
|
|
const history = useHistory();
|
2020-09-08 17:20:29 +00:00
|
|
|
const [currentRealm, setCurrentRealm] = useState(realm);
|
2020-09-04 18:16:11 +00:00
|
|
|
|
2020-09-08 17:20:29 +00:00
|
|
|
const dropdownItems = realmList.map((r) => (
|
2020-09-04 18:16:11 +00:00
|
|
|
<DropdownItem
|
|
|
|
key={r.id}
|
2020-09-08 17:20:29 +00:00
|
|
|
onClick={() => {
|
|
|
|
setCurrentRealm(r.realm);
|
|
|
|
setOpen(!open);
|
|
|
|
}}
|
2020-09-04 18:16:11 +00:00
|
|
|
>
|
|
|
|
{r.realm.charAt(0).toUpperCase() + r.realm.slice(1)}
|
2020-08-27 12:09:36 +00:00
|
|
|
</DropdownItem>
|
2020-08-04 12:59:41 +00:00
|
|
|
));
|
2020-09-04 18:16:11 +00:00
|
|
|
|
2020-08-04 12:59:41 +00:00
|
|
|
return (
|
|
|
|
<Dropdown
|
|
|
|
id="realm-select"
|
2020-09-14 18:10:54 +00:00
|
|
|
className="keycloak__realm_selector__dropdown"
|
2020-08-04 12:59:41 +00:00
|
|
|
isOpen={open}
|
|
|
|
toggle={
|
|
|
|
<DropdownToggle
|
|
|
|
id="realm-select-toggle"
|
|
|
|
onToggle={() => setOpen(!open)}
|
2020-09-14 18:10:54 +00:00
|
|
|
className="keycloak__realm_selector_dropdown__toggle"
|
2020-08-04 12:59:41 +00:00
|
|
|
>
|
2020-09-04 18:16:11 +00:00
|
|
|
{currentRealm}
|
2020-08-04 12:59:41 +00:00
|
|
|
</DropdownToggle>
|
|
|
|
}
|
|
|
|
dropdownItems={[
|
|
|
|
...dropdownItems,
|
2020-09-04 18:16:11 +00:00
|
|
|
<Divider key={1} />,
|
2020-08-27 12:09:36 +00:00
|
|
|
<DropdownItem component="div" key="add">
|
2020-09-05 19:37:42 +00:00
|
|
|
<Button isBlock onClick={() => history.push("/add-realm")}>
|
2020-09-04 18:16:11 +00:00
|
|
|
Create Realm
|
|
|
|
</Button>
|
2020-08-04 12:59:41 +00:00
|
|
|
</DropdownItem>,
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|