8000 do not filter the realm list on recent used as it might be on the next page by edewit · Pull Request #34510 · 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
11 changes: 8 additions & 3 deletions js/apps/admin-ui/src/components/error/ErrorRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ export const ErrorRenderer = ({ error }: FallbackProps) => {
<AlertActionCloseButton title={error.message} />
}
actionLinks={
<AlertActionLink => showBoundary()}>
{t("retry")}
</AlertActionLink>
<>
<AlertActionLink => showBoundary()}>
{t("retry")}
</AlertActionLink>
<AlertActionLink => (location.href = "/")}>
{t("home")}
</AlertActionLink>
</>
}
></Alert>
</PageSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,9 @@ export const RealmSelector = () => {
const sortedRealms = useMemo(
() => [
...(first === 0 && !search
? recentRealms.reduce((acc, name) => {
const realm = realms.find((r) => r.name === name);
if (realm) {
acc.push(realm);
}
return acc;
}, [] as RealmNameRepresentation[])
? (recentRealms || []).map((name) => ({ name }))
: []),
...realms.filter((r) => !recentRealms.includes(r.name)),
...realms.filter((r) => !(recentRealms || []).includes(r.name)),
],
[recentRealms, realms, first, search],
);
Expand Down Expand Up @@ -223,7 +217,7 @@ export const RealmSelector = () => {
<RealmText
{...realm}
showIsRecent={
realms.length > 5 && recentRealms.includes(realm.name)
realms.length > 5 && recentRealms?.includes(realm.name)
}
/>
</DropdownItem>
Expand Down
31 changes: 26 additions & 5 deletions js/apps/admin-ui/src/context/RecentRealms.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { PropsWithChildren, useEffect } from "react";
import { PropsWithChildren } from "react";

import {
createNamedContext,
useFetch,
useRequiredContext,
useStoredState,
} from "@keycloak/keycloak-ui-shared";
import { useAdminClient } from "../admin-client";
import { useRealm } from "./realm-context/RealmContext";

const MAX_REALMS = 4;
Expand All @@ -16,16 +18,35 @@ export const RecentRealmsContext = createNamedContext<string[] | undefined>(

export const RecentRealmsProvider = ({ children }: PropsWithChildren) => {
const { realm } = useRealm();
const { adminClient } = useAdminClient();

const [storedRealms, setStoredRealms] = useStoredState(
localStorage,
"recentRealms",
[realm],
);

useEffect(() => {
const newRealms = [...new Set([realm, ...storedRealms])];
setStoredRealms(newRealms.slice(0, MAX_REALMS));
}, [realm]);
useFetch(
() => {
return Promise.all(
[...new Set([realm, ...storedRealms])].map(async (realm) => {
try {
const response = await adminClient.realms.findOne({ realm });
if (response) {
return response.realm;
}
} catch {
return undefined;
}
}),
);
},
(realms) => {
const newRealms = realms.filter((r) => r) as string[];
setStoredRealms(newRealms.slice(0, MAX_REALMS));
},
[realm],
);

return (
<RecentRealmsContext.Provider value={storedRealms}>
Expand Down
4 changes: 1 addition & 3 deletions js/apps/admin-ui/src/realm-settings/RealmSettingsTabs.tsx
79A4
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fetchWithError } from "@keycloak/keycloak-admin-client";
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
import { UserProfileConfig } from "@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata";
import { useEnvironment } from "@keycloak/keycloak-ui-shared";
import { useAlerts, useEnvironment } from "@keycloak/keycloak-ui-shared";
import {
AlertVariant,
ButtonVariant,
Expand All @@ -16,9 +16,7 @@ import { useEffect, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";

import { useAdminClient } from "../admin-client";
import { useAlerts } from "@keycloak/keycloak-ui-shared";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import type { KeyValueType } from "../components/key-value-form/key-value-convert";
import {
Expand Down
0