2020-12-07 19:23:18 +00:00
|
|
|
import React from "react";
|
2020-09-25 17:11:25 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2021-01-05 19:49:33 +00:00
|
|
|
import { Link, useHistory, useRouteMatch } from "react-router-dom";
|
2021-01-07 18:34:59 +00:00
|
|
|
import { AlertVariant, Button, PageSection } from "@patternfly/react-core";
|
2020-12-07 19:23:18 +00:00
|
|
|
import ClientScopeRepresentation from "keycloak-admin/lib/defs/clientScopeRepresentation";
|
2020-09-25 17:11:25 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
import { useAdminClient } from "../context/auth/AdminClient";
|
2020-12-07 19:23:18 +00:00
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
2021-01-07 18:34:59 +00:00
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
2020-12-11 10:28:38 +00:00
|
|
|
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
|
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();
|
2021-01-05 19:49:33 +00:00
|
|
|
const { url } = useRouteMatch();
|
2020-09-25 17:11:25 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const adminClient = useAdminClient();
|
2021-01-07 18:34:59 +00:00
|
|
|
const { addAlert } = useAlerts();
|
2020-09-25 17:11:25 +00:00
|
|
|
|
2020-12-07 19:23:18 +00:00
|
|
|
const loader = async () => await adminClient.clientScopes.find();
|
2020-10-07 15:47:03 +00:00
|
|
|
|
2020-12-07 19:23:18 +00:00
|
|
|
const ClientScopeDetailLink = (clientScope: ClientScopeRepresentation) => (
|
|
|
|
<>
|
2021-01-05 19:49:33 +00:00
|
|
|
<Link key={clientScope.id} to={`${url}/${clientScope.id}`}>
|
2020-12-07 19:23:18 +00:00
|
|
|
{clientScope.name}
|
|
|
|
</Link>
|
|
|
|
</>
|
|
|
|
);
|
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-12-11 10:18:29 +00:00
|
|
|
<KeycloakDataTable
|
2020-12-07 19:23:18 +00:00
|
|
|
loader={loader}
|
|
|
|
ariaLabelKey="client-scopes:clientScopeList"
|
|
|
|
searchPlaceholderKey="client-scopes:searchFor"
|
|
|
|
toolbarItem={
|
2021-01-05 19:49:33 +00:00
|
|
|
<Button onClick={() => history.push(`${url}/new`)}>
|
2020-12-07 19:23:18 +00:00
|
|
|
{t("createClientScope")}
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
title: t("common:export"),
|
|
|
|
onRowClick: () => {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("common:delete"),
|
2021-01-07 18:34:59 +00:00
|
|
|
onRowClick: async (clientScope) => {
|
|
|
|
try {
|
|
|
|
await adminClient.clientScopes.del({ id: clientScope.id! });
|
|
|
|
addAlert(t("deletedSuccess"), AlertVariant.success);
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
addAlert(
|
|
|
|
t("deleteError", {
|
|
|
|
error: error.response.data?.errorMessage || error,
|
|
|
|
}),
|
|
|
|
AlertVariant.danger
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
2020-12-07 19:23:18 +00:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
columns={[
|
|
|
|
{
|
2021-01-13 20:48:16 +00:00
|
|
|
name: t("common:name"),
|
2020-12-07 19:23:18 +00:00
|
|
|
cellRenderer: ClientScopeDetailLink,
|
|
|
|
},
|
2021-01-13 20:48:16 +00:00
|
|
|
{ name: t("common:description") },
|
2020-12-07 19:23:18 +00:00
|
|
|
{
|
2021-01-13 20:48:16 +00:00
|
|
|
name: t("protocol"),
|
2020-12-07 19:23:18 +00:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
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
|
|
|
};
|