2020-10-07 15:47:03 +00:00
|
|
|
import React, { useContext, useEffect, useState } from "react";
|
|
|
|
import { Button, PageSection, Spinner } from "@patternfly/react-core";
|
2020-09-25 17:11:25 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { useHistory } from "react-router-dom";
|
|
|
|
|
2020-10-06 08:25:38 +00:00
|
|
|
import { RealmContext } from "../context/realm-context/RealmContext";
|
|
|
|
import { HttpClientContext } from "../context/http-service/HttpClientContext";
|
2020-09-25 17:11:25 +00:00
|
|
|
import { ClientRepresentation } from "../realm/models/Realm";
|
|
|
|
import { TableToolbar } from "../components/table-toolbar/TableToolbar";
|
|
|
|
import { ClientScopeList } from "./ClientScopesList";
|
2020-10-02 13:56:46 +00:00
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
2020-09-09 09:07:17 +00:00
|
|
|
|
2020-09-10 18:04:03 +00:00
|
|
|
export const ClientScopesSection = () => {
|
2020-09-25 17:11:25 +00:00
|
|
|
const { t } = useTranslation("client-scopes");
|
|
|
|
const history = useHistory();
|
2020-10-07 15:47:03 +00:00
|
|
|
const [rawData, setRawData] = useState<ClientRepresentation[]>();
|
|
|
|
const [filteredData, setFilteredData] = useState<ClientRepresentation[]>();
|
2020-09-25 17:11:25 +00:00
|
|
|
|
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
|
|
|
const { realm } = useContext(RealmContext);
|
|
|
|
|
2020-10-07 15:47:03 +00:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
if (filteredData) {
|
|
|
|
return filteredData;
|
|
|
|
}
|
|
|
|
const result = await httpClient.doGet<ClientRepresentation[]>(
|
|
|
|
`/admin/realms/${realm}/client-scopes`
|
|
|
|
);
|
|
|
|
setRawData(result.data!);
|
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const filterData = (search: string) => {
|
|
|
|
setFilteredData(
|
|
|
|
rawData!.filter((group) =>
|
|
|
|
group.name.toLowerCase().includes(search.toLowerCase())
|
|
|
|
)
|
|
|
|
);
|
2020-09-25 17:11:25 +00:00
|
|
|
};
|
2020-09-18 08:04:55 +00:00
|
|
|
return (
|
2020-10-02 13:56:46 +00:00
|
|
|
<>
|
|
|
|
<ViewHeader
|
|
|
|
titleKey="clientScopes"
|
|
|
|
subKey="client-scopes:clientScopeExplain"
|
|
|
|
/>
|
|
|
|
<PageSection variant="light">
|
2020-10-07 15:47:03 +00:00
|
|
|
{!rawData && (
|
|
|
|
<div className="pf-u-text-align-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{rawData && (
|
|
|
|
<TableToolbar
|
|
|
|
inputGroupName="clientsScopeToolbarTextInput"
|
|
|
|
inputGroupPlaceholder={t("searchFor")}
|
|
|
|
inputGroupOnChange={filterData}
|
|
|
|
toolbarItem={
|
|
|
|
<Button onClick={() => history.push("/add-client-scopes")}>
|
|
|
|
{t("createClientScope")}
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ClientScopeList clientScopes={filteredData || rawData} />
|
|
|
|
</TableToolbar>
|
|
|
|
)}
|
2020-10-02 13:56:46 +00:00
|
|
|
</PageSection>
|
|
|
|
</>
|
2020-09-18 08:04:55 +00:00
|
|
|
);
|
2020-09-09 09:07:17 +00:00
|
|
|
};
|