8000 BACKPORT: Update react router dependency (#51764) by edewit · Pull Request #52134 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/apps/account-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"react-dom": "^18.3.1",
"react-hook-form": "^7.70.0",
"react-i18next": "^16.5.1",
"react-router-dom": "^6.30.4"
"react-router-dom": "^7.18.2"
},
"devDependencies": {
"@keycloak/keycloak-admin-client": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion js/apps/account-ui/src/root/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function CatchAllRedirect() {
addAlert(t("pageNotFound"), AlertVariant.warning);
}, [addAlert, t]);

return <Navigate to="." replace />;
return <Navigate to=".." replace />;
}

export const Root = () => {
Expand Down
2 changes: 1 addition & 1 deletion js/apps/admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"react-dom": "^18.3.1",
"react-hook-form": "^7.70.0",
"react-i18next": "^16.5.1",
"react-router-dom": "^6.30.4",
"react-router-dom": "^7.18.2",
"reactflow": "^11.11.4",
"use-react-router-breadcrumbs": "^4.0.1",
"yaml": "^2.8.3"
Expand Down
31 changes: 17 additions & 14 deletions js/apps/admin-ui/src/realm-settings/EmailTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const RealmSettingsEmailTab = ({
const { t } = useTranslation();
const { addAlert, addError } = useAlerts();
const currentUser = useCurrentUser();
const canLinkToCurrentUserSettings = !!currentUser.realm && !!currentUser.id;

const form = useForm<FormFields>({ defaultValues: realm });
const { control, handleSubmit, watch, reset: resetForm, getValues } = form;
Expand Down Expand Up @@ -370,20 +371,22 @@ export const RealmSettingsEmailTab = ({
userName: currentUser.username,
})}
actionLinks={
<AlertActionLink
component={(props) => (
<Link
{...props}
to={toUser({
realm: currentUser.realm!,
id: currentUser.id!,
tab: "settings",
})}
/>
)}
>
{t("testConnectionHint.withoutEmailAction")}
</AlertActionLink>
canLinkToCurrentUserSettings ? (
<AlertActionLink
component={(props) => (
<Link
{...props}
to={toUser({
realm: currentUser.realm!,
id: currentUser.id!,
tab: "settings",
})}
/>
)}
>
{t("testConnectionHint.withoutEmailAction")}
</AlertActionLink>
) : undefined
}
/>
)}
Expand Down
14 changes: 4 additions & 10 deletions js/apps/admin-ui/src/utils/generateEncodedPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,8 @@ export function generateEncodedPath<Path extends string>(
originalPath: Path,
params: PathParams<Path>,
): string {
// Clone the params object so we don't mutate the original.
const encodedParams = structuredClone(params);

// Encode each param in the path so that it can be used in a URL.
for (const key in encodedParams) {
const pathKey = key as PathParam<Path>;
encodedParams[pathKey] = encodeURIComponent(encodedParams[pathKey]);
}

return generatePath(originalPath, encodedParams);
return generatePath(
originalPath,
params as Parameters<typeof generatePath<Path>>[1],
);
}
20 changes: 5 additions & 15 deletions js/apps/admin-ui/src/utils/useIsAdminPermissionsClient.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { useState, useEffect } from "react";
import { useRealm } from "../context/realm-context/RealmContext";

export function useIsAdminPermissionsClient(selectedClientId: string) {
export function useIsAdminPermissionsClient(selectedClientId?: string) {
const { realmRepresentation } = useRealm();
const [isAdminPermissionsClient, setIsAdminPermissionsClient] =
useState<boolean>(false);

useEffect(() => {
if (realmRepresentation?.adminPermissionsClient) {
setIsAdminPermissionsClient(
selectedClientId === realmRepresentation.adminPermissionsClient.id,
);
} else {
setIsAdminPermissionsClient(false);
}
}, [selectedClientId, realmRepresentation]);

return isAdminPermissionsClient;
return (
!!selectedClientId &&
selectedClientId === realmRepresentation?.adminPermissionsClient?.id
);
}
14 changes: 10 additions & 4 deletions js/apps/admin-ui/test/clients/registration-policies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ test.describe.serial("Client registration policies tab", () => {
const policyNameUpdated = "policy2";

test("check anonymous clients list is not empty", async ({ page }) => {
const rows = await getTableData(page, tabName);
expect(rows.length).toBeGreaterThan(1);
await expect
.poll(async () => (await getTableData(page, tabName)).length, {
timeout: 15_000,
})
.toBeGreaterThan(1);
});

test("add anonymous client registration policy", async ({ page }) => {
Expand Down Expand Up @@ -95,8 +98,11 @@ test.describe.serial("Client registration policies tab", () => {
});

test("check authenticated clients list is not empty", async ({ page }) => {
const rows = await getTableData(page, tabName);
expect(rows.length).toBeGreaterThan(1);
await expect
.poll(async () => (await getTableData(page, tabName)).length, {
timeout: 15_000,
})
.toBeGreaterThan(1);
});

test("add authenticated client registration policy", async ({ page }) => {
Expand Down
20 changes: 14 additions & 6 deletions js/apps/admin-ui/test/realm-settings/userprofile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { goToLoginTab } from "./login.ts";
import {
clickAddValidator,
clickCancelAttribute,
clickCreateUser,
clickCreateAttribute,
fillEmailAndOptionalUsername,
clickSaveAttribute,
clickSaveValidator,
fillAttributeForm,
Expand Down Expand Up @@ -60,6 +62,8 @@ test.describe.serial("User profile tabs", () => {

test.afterEach(async () => {
await adminClient.deleteUser("testuser7", realmName, true);
await adminClient.deleteUser("testuser8", realmName, true);
await adminClient.deleteUser("testuser8@gmail.com", realmName, true);
await adminClient.deleteUser("testuser9@gmail.com", realmName, true);
await adminClient.deleteUser("testuser10", realmName, true);
await adminClient.deleteUser("testuser11", realmName, true);
Expand Down Expand Up @@ -146,7 +150,7 @@ test.describe.serial("User profile tabs", () => {
await switchOn(page, "#kc-edit-username-switch");

await goToUsers(page);
await page.getByTestId("no-users-found-empty-action").click();
await clickCreateUser(page);
await expect(page.getByTestId(attrName)).toBeHidden();
await page.getByTestId("username").fill("testuser7");
await page.getByTestId("user-creation-save").click();
Expand All @@ -168,8 +172,12 @@ test.describe.serial("User profile tabs", () => {
await switchOn(page, "#kc-email-as-username-switch");

await goToUsers(page);
await page.getByTestId("no-users-found-empty-action").click();
await page.getByTestId("email").fill("testuser8@gmail.com");
await clickCreateUser(page);
await fillEmailAndOptionalUsername(
page,
"testuser8@gmail.com",
"testuser8",
);
await expect(page.getByTestId(attrName)).toBeHidden();
await page.getByTestId("user-creation-save").click();
await assertNotificationMessage(page, "The user has been created");
Expand All @@ -196,7 +204,7 @@ test.describe.serial("User profile tabs", () => {
await switchOffIfOn(page, "#kc-email-as-username-switch");

await goToUsers(page);
await page.getByTestId("no-users-found-empty-action").click();
await clickCreateUser(page);
await expect(page.getByTestId(attrName)).toBeVisible();
await page.getByTestId("username").fill("testuser10");
await page.getByTestId("user-creation-save").click();
Expand All @@ -221,7 +229,7 @@ test.describe.serial("User profile tabs", () => {
await clickSaveAttribute(page);

await goToUsers(page);
await page.getByTestId("no-users-found-empty-action").click();
await clickCreateUser(page);
await expect(page.getByTestId(attrName)).toBeVisible();
await page.getByTestId("username").fill("testuser11");
await page.getByTestId("user-creation-save").click();
Expand Down Expand Up @@ -255,7 +263,7 @@ test.describe.serial("User profile tabs", () => {
);

await goToUsers(page);
await page.getByTestId("no-users-found-empty-action").click();
await clickCreateUser(page);

await expect(page.getByRole("heading", { name: group })).toBeVisible();
});
Expand Down
30 changes: 29 additions & 1 deletion js/apps/admin-ui/test/realm-settings/userprofile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Page } from "@playwright/test";
import { expect, type Page } from "@playwright/test";

export async function goToUserProfileTab(page: Page) {
await page.getByTestId("rs-user-profile-tab").click();
Expand Down Expand Up @@ -51,3 +51,31 @@ export async function switchOffIfOn(page: Page, selector: string) {
await page.locator(selector).click({ force: true });
}
}

export async function clickCreateUser(page: Page) {
const emptyAction = page.getByTestId("no-users-found-empty-action");
const addUser = page.getByTestId("add-user");
await expect(emptyAction.or(addUser).first()).toBeVisible({
timeout: 15_000,
});

if ((await emptyAction.count()) > 0 && (await emptyAction.isVisible())) {
await emptyAction.click();
return;
}

await addUser.click();
}

export async function fillEmailAndOptionalUsername(
page: Page,
email: string,
username: string,
) {
await page.getByTestId("email").fill(email);
const usernameField = page.getByTestId("username");
await expect(
usernameField,
`Expected username field to be hidden when "Email as username" is enabled (fallback username: "${username}")`,
).toBeHidden();
}
1 change: 1 addition & 0 deletions js/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default tseslint.config(
"@typescript-eslint/no-dynamic-delete": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-extraneous-class": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-invalid-void-type": "off",
"@typescript-eslint/no-misused-promises": "off",
Expand Down
Loading
Loading
0