+
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: 3 additions & 8 deletions js/apps/admin-ui/src/context/realm-context/RealmContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
useRequiredContext,
} from "@keycloak/keycloak-ui-shared";
import { PropsWithChildren, useEffect, useState } from "react";
import { useMatch } from "react-router-dom";
import { useAdminClient } from "../../admin-client";
import { DashboardRouteWithRealm } from "../../dashboard/routes/Dashboard";
import { i18n } from "../../i18n/i18n";
import { useHash } from "./useHash";

type RealmContextType = {
realm: string;
Expand All @@ -30,12 +29,8 @@ export const RealmContextProvider = ({ children }: PropsWithChildren) => {
const [realmRepresentation, setRealmRepresentation] =
useState<RealmRepresentation>();

const routeMatch = useMatch({
path: DashboardRouteWithRealm.path,
end: false,
});

const realm = routeMatch?.params.realm ?? environment.realm;
const locationRealm = useHash();
const realm = locationRealm?.split("/")[1] ?? environment.realm;

// Configure admin client to use selected realm when it changes.
useEffect(() => {
Expand Down
19 changes: 19 additions & 0 deletions js/apps/admin-ui/src/context/realm-context/useHash.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect, useState } from "react";

export const useHash = () => {
const [hash, setHash] = useState(location.hash);

useEffect(() => {
const orgPushState = window.history.pushState;
window.history.pushState = new Proxy(window.history.pushState, {
apply: (func, target, args) => {
setHash(args[2].substring(1));
return Reflect.apply(func, target, args);
},
});
return () => {
window.history.pushState = orgPushState;
};
}, []);
return decodeURIComponent(hash);
};
2 changes: 1 addition & 1 deletion js/apps/admin-ui/test/masthead/realm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test.describe("Realm tests", () => {

await assertNotificationMessage(
page,
"Could not create realm Conflict detected. See logs for details",
"Could not create realm Realm master already exists",
);
});

Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载