2020-11-12 12:55:52 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2020-10-07 15:47:03 +00:00
|
|
|
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-11-12 12:55:52 +00:00
|
|
|
import ClientRepresentation from "keycloak-admin/lib/defs/clientRepresentation";
|
2020-09-25 17:11:25 +00:00
|
|
|
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-11-12 12:55:52 +00:00
|
|
|
import { useAdminClient } from "../context/auth/AdminClient";
|
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
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const adminClient = useAdminClient();
|
2020-09-25 17:11:25 +00:00
|
|
|
|
2020-10-07 15:47:03 +00:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
if (filteredData) {
|
|
|
|
return filteredData;
|
|
|
|
}
|
2020-11-12 12:55:52 +00:00
|
|
|
const result = await adminClient.clientScopes.find();
|
|
|
|
setRawData(result);
|
2020-10-07 15:47:03 +00:00
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const filterData = (search: string) => {
|
|
|
|
setFilteredData(
|
|
|
|
rawData!.filter((group) =>
|
2020-11-12 12:55:52 +00:00
|
|
|
group.name!.toLowerCase().includes(search.toLowerCase())
|
2020-10-07 15:47:03 +00:00
|
|
|
)
|
|
|
|
);
|
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={
|
2020-10-21 17:38:11 +00:00
|
|
|
<Button onClick={() => history.push("/client-scopes/new")}>
|
2020-10-07 15:47:03 +00:00
|
|
|
{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
|
|
|
};
|