Realm settings: Return user to Policies subtab (#1823)

* add function to go to policies subtab

* use routable tabs

* use new defaultLocation prop

* rebase, lint, and tests

* unskip

* fix cancel test
This commit is contained in:
Jenny 2022-01-20 10:34:58 -05:00 committed by GitHub
parent bd28a912dd
commit 3f7a912c2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 84 additions and 29 deletions

View file

@ -625,15 +625,15 @@ export default class RealmSettingsPage {
} }
shouldDisplayDeleteClientPolicyDialog() { shouldDisplayDeleteClientPolicyDialog() {
cy.get(this.moreDrpDwn).last().click(); this.listingPage.searchItem("Test", false);
cy.get(this.moreDrpDwnItems).click(); this.listingPage.clickRowDetails("Test").clickDetailMenu("Delete");
cy.get(this.deleteDialogTitle).contains("Delete policy?"); cy.get(this.deleteDialogTitle).contains("Delete policy?");
cy.get(this.deleteDialogBodyText).contains( cy.get(this.deleteDialogBodyText).contains(
"This action will permanently delete the policy Test. This cannot be undone." "This action will permanently delete the policy Test. This cannot be undone."
); );
cy.findByTestId("modalConfirm").contains("Delete"); cy.findByTestId("modalConfirm").contains("Delete");
cy.get(this.deleteDialogCancelBtn).contains("Cancel").click(); cy.get(this.deleteDialogCancelBtn).contains("Cancel").click();
cy.get("table").should("not.have.text", "Test"); cy.get("table").should("be.visible").contains("td", "Test");
} }
shouldDeleteClientProfileDialog() { shouldDeleteClientProfileDialog() {
@ -914,7 +914,7 @@ export default class RealmSettingsPage {
"Test Description" "Test Description"
); );
cy.findByTestId(this.cancelNewClientPolicyBtn).click(); cy.findByTestId(this.cancelNewClientPolicyBtn).click();
cy.get("table").should("not.have.text", "Test"); cy.findByTestId(this.createPolicyEmptyStateBtn).should("exist");
} }
shouldCompleteAndCreateNewClientPolicy() { shouldCompleteAndCreateNewClientPolicy() {
@ -1119,12 +1119,12 @@ export default class RealmSettingsPage {
); );
cy.findByTestId(this.saveNewClientPolicyBtn).click(); cy.findByTestId(this.saveNewClientPolicyBtn).click();
cy.get(this.alertMessage).should("be.visible", "New client policy created"); cy.get(this.alertMessage).should("be.visible", "New client policy created");
cy.wait(200); cy.wait(500);
cy.findByTestId(this.clientPolicyDrpDwn).contains("Action").click(); cy.findByTestId(this.clientPolicyDrpDwn).contains("Action").click();
cy.findByTestId("deleteClientPolicyDropdown").click(); cy.findByTestId("deleteClientPolicyDropdown").click();
cy.findByTestId("modalConfirm").contains("Delete").click(); cy.findByTestId("modalConfirm").contains("Delete").click();
cy.get(this.alertMessage).should("be.visible", "Client profile deleted"); cy.get(this.alertMessage).should("be.visible", "Client profile deleted");
cy.get("table").should("not.have.text", "Test Again Description"); cy.findByTestId(this.createPolicyEmptyStateBtn).should("exist");
} }
shouldReloadJSONPolicies() { shouldReloadJSONPolicies() {

View file

@ -176,7 +176,7 @@ export default function ClientProfileForm() {
globalProfiles, globalProfiles,
}); });
addAlert(t("deleteClientSuccess"), AlertVariant.success); addAlert(t("deleteClientSuccess"), AlertVariant.success);
history.push(toClientPolicies({ realm })); history.push(toClientPolicies({ realm, tab: "profiles" }));
} catch (error) { } catch (error) {
addError(t("deleteClientError"), error); addError(t("deleteClientError"), error);
} }

View file

@ -34,13 +34,13 @@ import { PlusCircleIcon, TrashIcon } from "@patternfly/react-icons";
import "./RealmSettingsSection.css"; import "./RealmSettingsSection.css";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import type ClientPolicyRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientPolicyRepresentation"; import type ClientPolicyRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientPolicyRepresentation";
import { toClientPolicies } from "./routes/ClientPolicies";
import { toNewClientPolicyCondition } from "./routes/AddCondition"; import { toNewClientPolicyCondition } from "./routes/AddCondition";
import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { useServerInfo } from "../context/server-info/ServerInfoProvider";
import { toEditClientPolicyCondition } from "./routes/EditCondition"; import { toEditClientPolicyCondition } from "./routes/EditCondition";
import type { EditClientPolicyParams } from "./routes/EditClientPolicy"; import type { EditClientPolicyParams } from "./routes/EditClientPolicy";
import { AddClientProfileModal } from "./AddClientProfileModal"; import { AddClientProfileModal } from "./AddClientProfileModal";
import type ClientProfileRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientProfileRepresentation"; import type ClientProfileRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientProfileRepresentation";
import { toRealmSettings } from "./routes/RealmSettings";
type NewClientPolicyForm = Required<ClientPolicyRepresentation>; type NewClientPolicyForm = Required<ClientPolicyRepresentation>;
@ -274,7 +274,13 @@ export default function NewClientPolicyForm() {
policies: updatedPolicies, policies: updatedPolicies,
}); });
addAlert(t("deleteClientPolicySuccess"), AlertVariant.success); addAlert(t("deleteClientPolicySuccess"), AlertVariant.success);
history.push(toClientPolicies({ realm })); history.push(
toRealmSettings({
realm,
tab: "clientPolicies",
subTab: "policies",
})
);
} catch (error) { } catch (error) {
addError(t("deleteClientPolicyError"), error); addError(t("deleteClientPolicyError"), error);
} }
@ -314,7 +320,13 @@ export default function NewClientPolicyForm() {
policies: updatedPolicies, policies: updatedPolicies,
}); });
addAlert(t("deleteClientSuccess"), AlertVariant.success); addAlert(t("deleteClientSuccess"), AlertVariant.success);
history.push(toClientPolicies({ realm })); history.push(
toRealmSettings({
realm,
tab: "clientPolicies",
subTab: "policies",
})
);
} catch (error) { } catch (error) {
addError(t("deleteClientError"), error); addError(t("deleteClientError"), error);
} }
@ -354,7 +366,13 @@ export default function NewClientPolicyForm() {
policies: updatedPolicies, policies: updatedPolicies,
}); });
addAlert(t("deleteClientSuccess"), AlertVariant.success); addAlert(t("deleteClientSuccess"), AlertVariant.success);
history.push(toClientPolicies({ realm })); history.push(
toRealmSettings({
realm,
tab: "clientPolicies",
subTab: "policies",
})
);
} catch (error) { } catch (error) {
addError(t("deleteClientError"), error); addError(t("deleteClientError"), error);
} }
@ -488,7 +506,13 @@ export default function NewClientPolicyForm() {
onClick={() => onClick={() =>
showAddConditionsAndProfilesForm || policyName showAddConditionsAndProfilesForm || policyName
? reset() ? reset()
: history.push(toClientPolicies({ realm })) : history.push(
toRealmSettings({
realm,
tab: "clientPolicies",
subTab: "policies",
})
)
} }
data-testid="cancelCreatePolicy" data-testid="cancelCreatePolicy"
> >

View file

@ -79,7 +79,7 @@ export const PoliciesTab = () => {
await adminClient.clientPolicies.updatePolicy({ await adminClient.clientPolicies.updatePolicy({
policies: updatedPolicies, policies: updatedPolicies,
}); });
history.push(toClientPolicies({ realm })); history.push(toClientPolicies({ realm, tab: "policies" }));
addAlert( addAlert(
t("realm-settings:updateClientPolicySuccess"), t("realm-settings:updateClientPolicySuccess"),
AlertVariant.success AlertVariant.success

View file

@ -202,7 +202,10 @@ export default function ProfilesTab() {
<Button <Button
id="createProfile" id="createProfile"
component={(props) => ( component={(props) => (
<Link {...props} to={toAddClientProfile({ realm })} /> <Link
{...props}
to={toAddClientProfile({ realm, tab: "profiles" })}
/>
)} )}
data-testid="createProfile" data-testid="createProfile"
> >

View file

@ -39,7 +39,14 @@ export const ToClientPolicies = () => {
return ( return (
<BreadcrumbItem <BreadcrumbItem
render={(props) => ( render={(props) => (
<Link {...props} to={toClientPolicies({ realm })}> <Link
{...props}
to={toRealmSettings({
realm,
tab: "clientPolicies",
subTab: "policies",
})}
>
{t("clientPolicies")} {t("clientPolicies")}
</Link> </Link>
)} )}
@ -66,7 +73,7 @@ export const EditProfileCrumb = () => {
<Breadcrumb> <Breadcrumb>
<BreadcrumbItem <BreadcrumbItem
render={(props) => ( render={(props) => (
<Link {...props} to={toClientPolicies({ realm })}> <Link {...props} to={toClientPolicies({ realm, tab: "profiles" })}>
{t("clientPolicies")} {t("clientPolicies")}
</Link> </Link>
)} )}
@ -84,7 +91,7 @@ export const EditExecutorCrumb = () => {
<Breadcrumb> <Breadcrumb>
<BreadcrumbItem <BreadcrumbItem
render={(props) => ( render={(props) => (
<Link {...props} to={toClientPolicies({ realm })}> <Link {...props} to={toClientPolicies({ realm, tab: "profiles" })}>
{t("clientPolicies")} {t("clientPolicies")}
</Link> </Link>
)} )}
@ -102,7 +109,7 @@ export const NewPolicyCrumb = () => {
<Breadcrumb> <Breadcrumb>
<BreadcrumbItem <BreadcrumbItem
render={(props) => ( render={(props) => (
<Link {...props} to={toClientPolicies({ realm })}> <Link {...props} to={toClientPolicies({ realm, tab: "policy" })}>
{t("clientPolicies")} {t("clientPolicies")}
</Link> </Link>
)} )}

View file

@ -57,6 +57,7 @@ import environment from "../environment";
import helpUrls from "../help-urls"; import helpUrls from "../help-urls";
import { UserProfileTab } from "./user-profile/UserProfileTab"; import { UserProfileTab } from "./user-profile/UserProfileTab";
import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled"; import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled";
import { toClientPolicies } from "./routes/ClientPolicies";
type RealmSettingsHeaderProps = { type RealmSettingsHeaderProps = {
onChange: (value: boolean) => void; onChange: (value: boolean) => void;
@ -423,13 +424,14 @@ export const RealmSettingsTabs = ({
history, history,
})} })}
> >
<Tabs <RoutableTabs
activeKey={activeTab} mountOnEnter
onSelect={(_, key) => setActiveTab(Number(key))} defaultLocation={toClientPolicies({
realm: realmName,
tab: "profiles",
})}
> >
<Tab <Tab
id="profiles"
eventKey={0}
data-testid="rs-policies-clientProfiles-tab" data-testid="rs-policies-clientProfiles-tab"
aria-label={t("clientProfilesSubTab")} aria-label={t("clientProfilesSubTab")}
title={ title={
@ -443,6 +445,13 @@ export const RealmSettingsTabs = ({
</span> </span>
</TabTitleText> </TabTitleText>
} }
{...routableTab({
to: toClientPolicies({
realm: realmName,
tab: "profiles",
}),
history,
})}
> >
<ProfilesTab /> <ProfilesTab />
</Tab> </Tab>
@ -450,7 +459,13 @@ export const RealmSettingsTabs = ({
id="policies" id="policies"
data-testid="rs-policies-clientPolicies-tab" data-testid="rs-policies-clientPolicies-tab"
aria-label={t("clientPoliciesSubTab")} aria-label={t("clientPoliciesSubTab")}
eventKey={1} {...routableTab({
to: toClientPolicies({
realm: realmName,
tab: "policies",
}),
history,
})}
title={ title={
<TabTitleText> <TabTitleText>
{t("policies")} {t("policies")}
@ -465,7 +480,7 @@ export const RealmSettingsTabs = ({
> >
<PoliciesTab /> <PoliciesTab />
</Tab> </Tab>
</Tabs> </RoutableTabs>
</Tab> </Tab>
{isFeatureEnabled(Feature.DeclarativeUserProfile) && {isFeatureEnabled(Feature.DeclarativeUserProfile) &&
userProfileEnabled === "true" && ( userProfileEnabled === "true" && (

View file

@ -7,7 +7,7 @@ import { NewPolicyCrumb } from "../RealmSettingsSection";
export type AddClientPolicyParams = { realm: string }; export type AddClientPolicyParams = { realm: string };
export const AddClientPolicyRoute: RouteDef = { export const AddClientPolicyRoute: RouteDef = {
path: "/:realm/realm-settings/clientPolicies/add-client-policy", path: "/:realm/realm-settings/clientPolicies/policies/add-client-policy",
component: lazy(() => import("../NewClientPolicyForm")), component: lazy(() => import("../NewClientPolicyForm")),
breadcrumb: () => NewPolicyCrumb, breadcrumb: () => NewPolicyCrumb,
access: "manage-clients", access: "manage-clients",

View file

@ -5,10 +5,11 @@ import type { RouteDef } from "../../route-config";
export type AddClientProfileParams = { export type AddClientProfileParams = {
realm: string; realm: string;
tab: string;
}; };
export const AddClientProfileRoute: RouteDef = { export const AddClientProfileRoute: RouteDef = {
path: "/:realm/realm-settings/clientPolicies/add-profile", path: "/:realm/realm-settings/clientPolicies/:tab/add-profile",
component: lazy(() => import("../ClientProfileForm")), component: lazy(() => import("../ClientProfileForm")),
breadcrumb: (t) => t("realm-settings:newClientProfile"), breadcrumb: (t) => t("realm-settings:newClientProfile"),
access: "manage-realm", access: "manage-realm",

View file

@ -3,12 +3,15 @@ import { lazy } from "react";
import { generatePath } from "react-router-dom"; import { generatePath } from "react-router-dom";
import type { RouteDef } from "../../route-config"; import type { RouteDef } from "../../route-config";
export type UserProfileTab = "profiles" | "policies";
export type ClientPoliciesParams = { export type ClientPoliciesParams = {
realm: string; realm: string;
tab: string;
}; };
export const ClientPoliciesRoute: RouteDef = { export const ClientPoliciesRoute: RouteDef = {
path: "/:realm/realm-settings/clientPolicies", path: "/:realm/realm-settings/clientPolicies/:tab",
component: lazy(() => import("../ProfilesTab")), component: lazy(() => import("../ProfilesTab")),
breadcrumb: (t) => t("realm-settings:allClientPolicies"), breadcrumb: (t) => t("realm-settings:allClientPolicies"),
access: "view-realm", access: "view-realm",

View file

@ -4,6 +4,7 @@ import { generatePath } from "react-router-dom";
import type { RouteDef } from "../../route-config"; import type { RouteDef } from "../../route-config";
export type RealmSettingsTab = export type RealmSettingsTab =
| "general"
| "login" | "login"
| "email" | "email"
| "themes" | "themes"
@ -20,10 +21,11 @@ export type RealmSettingsTab =
export type RealmSettingsParams = { export type RealmSettingsParams = {
realm: string; realm: string;
tab?: RealmSettingsTab; tab?: RealmSettingsTab;
subTab?: string;
}; };
export const RealmSettingsRoute: RouteDef = { export const RealmSettingsRoute: RouteDef = {
path: "/:realm/realm-settings/:tab?", path: "/:realm/realm-settings/:tab?/:subTab?",
component: lazy(() => import("../RealmSettingsSection")), component: lazy(() => import("../RealmSettingsSection")),
breadcrumb: (t) => t("realmSettings"), breadcrumb: (t) => t("realmSettings"),
access: "view-realm", access: "view-realm",