9e5f711bea
* add create client policy form; WIP add client policy tests checkout realm settings test from master RealmSettingsPage.ts master remove comment and add missing translation fix tests PR feedback from Jon and Erik rebase editClientPolicy edit client policy add client policy conditions form fix bug in create form remove comment update help text fixes breadcrumbs add support for adding multiple conditions, deleting conditions, and list conditions in data table clean up names add delete functionality to conditions form PR feedback from Jon useMemo for conditions remove comments and logs remove unused hook add profiles modal wip addprofiles wip profiles wip help text wip add help text remove comments remove duplicate message update data test id PR feedback from Jon 1 Apply suggestions from code review Co-authored-by: Jon Koops <jonkoops@gmail.com> remove fragment create policy detail attribute type * PR feedback from Jon 1 * PR feedback from Jon 2 * add spinner to prevent loader from being called * remove duplicate identifier * fix and rename route * rename route
137 lines
3.6 KiB
TypeScript
137 lines
3.6 KiB
TypeScript
import React, { useState } from "react";
|
|
import {
|
|
Button,
|
|
Label,
|
|
Modal,
|
|
ModalVariant,
|
|
Spinner,
|
|
} from "@patternfly/react-core";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useFetch, useAdminClient } from "../context/auth/AdminClient";
|
|
import type RoleRepresentation from "@keycloak/keycloak-admin-client/lib/defs/roleRepresentation";
|
|
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
|
|
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
|
|
import type ClientProfileRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientProfileRepresentation";
|
|
|
|
type ClientProfile = ClientProfileRepresentation & {
|
|
global: boolean;
|
|
};
|
|
|
|
export type AddClientProfileModalProps = {
|
|
open: boolean;
|
|
toggleDialog: () => void;
|
|
onConfirm: (newReps: RoleRepresentation[]) => void;
|
|
allProfiles: string[];
|
|
};
|
|
|
|
export const AddClientProfileModal = (props: AddClientProfileModalProps) => {
|
|
const { t } = useTranslation("roles");
|
|
const adminClient = useAdminClient();
|
|
const [selectedRows, setSelectedRows] = useState<RoleRepresentation[]>([]);
|
|
|
|
const [tableProfiles, setTableProfiles] = useState<ClientProfile[]>();
|
|
|
|
useFetch(
|
|
() =>
|
|
adminClient.clientPolicies.listProfiles({
|
|
includeGlobalProfiles: true,
|
|
}),
|
|
(allProfiles) => {
|
|
const globalProfiles = allProfiles.globalProfiles?.map(
|
|
(globalProfiles) => ({
|
|
...globalProfiles,
|
|
global: true,
|
|
})
|
|
);
|
|
|
|
const profiles = allProfiles.profiles?.map((profiles) => ({
|
|
...profiles,
|
|
global: false,
|
|
}));
|
|
|
|
setTableProfiles([...(globalProfiles ?? []), ...(profiles ?? [])]);
|
|
},
|
|
[]
|
|
);
|
|
|
|
const loader = async () => tableProfiles ?? [];
|
|
|
|
if (!tableProfiles) {
|
|
return (
|
|
<div className="pf-u-text-align-center">
|
|
<Spinner />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const AliasRenderer = ({ name }: ClientProfile) => (
|
|
<>
|
|
{name && <Label color="blue">{name}</Label>} {name}
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<Modal
|
|
data-testid="addClientProfile"
|
|
title={t("realm-settings:addClientProfile")}
|
|
isOpen={props.open}
|
|
onClose={props.toggleDialog}
|
|
variant={ModalVariant.large}
|
|
actions={[
|
|
<Button
|
|
key="add"
|
|
data-testid="add-client-profile-button"
|
|
variant="primary"
|
|
isDisabled={!selectedRows.length}
|
|
onClick={() => {
|
|
props.toggleDialog();
|
|
props.onConfirm(selectedRows);
|
|
}}
|
|
>
|
|
{t("common:add")}
|
|
</Button>,
|
|
<Button
|
|
key="cancel"
|
|
variant="link"
|
|
onClick={() => {
|
|
props.toggleDialog();
|
|
}}
|
|
>
|
|
{t("common:cancel")}
|
|
</Button>,
|
|
]}
|
|
>
|
|
<KeycloakDataTable
|
|
loader={loader}
|
|
isRowDisabled={(value) =>
|
|
props.allProfiles.includes(value.name!) || false
|
|
}
|
|
ariaLabelKey="realm-settings:profilesList"
|
|
searchPlaceholderKey="realm-settings:searchProfile"
|
|
canSelectAll
|
|
onSelect={(rows) => {
|
|
setSelectedRows([...rows]);
|
|
}}
|
|
columns={[
|
|
{
|
|
name: "name",
|
|
displayKey: "realm-settings:clientProfileName",
|
|
cellRenderer: AliasRenderer,
|
|
},
|
|
{
|
|
name: "description",
|
|
displayKey: "common:description",
|
|
},
|
|
]}
|
|
emptyState={
|
|
<ListEmptyState
|
|
hasIcon
|
|
message={t("noRoles")}
|
|
instructions={t("noRolesInstructions")}
|
|
primaryActionText={t("createRole")}
|
|
/>
|
|
}
|
|
/>
|
|
</Modal>
|
|
);
|
|
};
|