import React, { useState, useContext, useEffect } from "react"; import { useHistory } from "react-router-dom"; import { Realm } from "../../models/Realm"; import { Dropdown, DropdownToggle, DropdownItem, Button, Divider, } from "@patternfly/react-core"; import style from "./realm-selector.module.css"; import { HttpClientContext } from "../../http-service/HttpClientContext"; export const RealmSelector = () => { const [open, setOpen] = useState(false); const history = useHistory(); const httpClient = useContext(HttpClientContext); const [realms, setRealms] = useState([] as Realm[]); const [currentRealm, setCurrentRealm] = useState("Master"); const getRealms = async () => { return await httpClient ?.doGet("/admin/realms") .then((r) => r.data as Realm[]); }; useEffect(() => { getRealms().then((result) => { setRealms(result || []); }); }, []); const dropdownItems = realms.map((r) => ( setCurrentRealm(r.realm)} > {r.realm.charAt(0).toUpperCase() + r.realm.slice(1)} )); return ( setOpen(!open)} className={style.toggle} > {currentRealm} } dropdownItems={[ ...dropdownItems, , , ]} /> ); };