Remove ability to delete a realm client from the overview (#1278)

This commit is contained in:
Jon Koops 2021-10-01 12:52:24 +02:00 committed by GitHub
parent b5dfcda451
commit e832e2e454
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 18 deletions

View file

@ -52,8 +52,7 @@ import { toClients } from "./routes/Clients";
import { ClientScopes } from "./scopes/ClientScopes"; import { ClientScopes } from "./scopes/ClientScopes";
import { EvaluateScopes } from "./scopes/EvaluateScopes"; import { EvaluateScopes } from "./scopes/EvaluateScopes";
import { ServiceAccount } from "./service-account/ServiceAccount"; import { ServiceAccount } from "./service-account/ServiceAccount";
import { isRealmClient } from "./utils";
const isRealmClient = (client: ClientRepresentation) => !client.protocol;
type ClientDetailHeaderProps = { type ClientDetailHeaderProps = {
onChange: (value: boolean) => void; onChange: (value: boolean) => void;

View file

@ -8,7 +8,7 @@ import {
TabTitleText, TabTitleText,
ToolbarItem, ToolbarItem,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { cellWidth, TableText } from "@patternfly/react-table"; import { cellWidth, IRowData, TableText } from "@patternfly/react-table";
import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation"; import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
import React, { useState } from "react"; import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@ -17,7 +17,10 @@ import { useAlerts } from "../components/alert/Alerts";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import { formattedLinkTableCell } from "../components/external-link/FormattedLink"; import { formattedLinkTableCell } from "../components/external-link/FormattedLink";
import { KeycloakTabs } from "../components/keycloak-tabs/KeycloakTabs"; import { KeycloakTabs } from "../components/keycloak-tabs/KeycloakTabs";
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import {
Action,
KeycloakDataTable,
} from "../components/table-toolbar/KeycloakDataTable";
import { ViewHeader } from "../components/view-header/ViewHeader"; import { ViewHeader } from "../components/view-header/ViewHeader";
import { useAdminClient } from "../context/auth/AdminClient"; import { useAdminClient } from "../context/auth/AdminClient";
import { useRealm } from "../context/realm-context/RealmContext"; import { useRealm } from "../context/realm-context/RealmContext";
@ -26,6 +29,7 @@ import { InitialAccessTokenList } from "./initial-access/InitialAccessTokenList"
import { toAddClient } from "./routes/AddClient"; import { toAddClient } from "./routes/AddClient";
import { toClient } from "./routes/Client"; import { toClient } from "./routes/Client";
import { toImportClient } from "./routes/ImportClient"; import { toImportClient } from "./routes/ImportClient";
import { isRealmClient } from "./utils";
export const ClientsSection = () => { export const ClientsSection = () => {
const { t } = useTranslation("clients"); const { t } = useTranslation("clients");
@ -130,21 +134,29 @@ export const ClientsSection = () => {
</ToolbarItem> </ToolbarItem>
</> </>
} }
actions={[ actionResolver={(rowData: IRowData) => {
{ const client: ClientRepresentation = rowData.data;
title: t("common:export"), const actions: Action<ClientRepresentation>[] = [
onRowClick: (client) => { {
exportClient(client); title: t("common:export"),
onClick() {
exportClient(client);
},
}, },
}, ];
{
title: t("common:delete"), if (!isRealmClient(client)) {
onRowClick: (client) => { actions.push({
setSelectedClient(client); title: t("common:delete"),
toggleDeleteDialog(); onClick() {
}, setSelectedClient(client);
}, toggleDeleteDialog();
]} },
});
}
return actions;
}}
columns={[ columns={[
{ {
name: "clientId", name: "clientId",

6
src/clients/utils.ts Normal file
View file

@ -0,0 +1,6 @@
import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
/**
* Checks if a client is intended to be used for authenticating a to a realm.
*/
export const isRealmClient = (client: ClientRepresentation) => !client.protocol;