8000 make account use the ErrorBoundary by edewit · Pull Request #40141 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Closed
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
12 changes: 6 additions & 6 deletions js/apps/account-ui/src/content/fetchContent.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CallOptions } from "../api/methods";
import { parseResponse } from "../api/parse-response";
import { request } from "../api/request";
import { MenuItem } from "../root/PageNav";
import { joinPath } from "../utils/joinPath";

export default async function fetchContentJson(
opts: CallOptions,
): Promise<MenuItem[]> {
const response = await fetch(
joinPath(opts.context.environment.resourceUrl, "/content.json"),
opts,
);
return await response.json();
const response = await request("/content.json", opts.context, {
signal: opts.signal,
});
return parseResponse<MenuItem[]>(response);
}
9 changes: 7 additions & 2 deletions js/apps/account-ui/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import "@patternfly/patternfly/patternfly-addons.css";
import "@patternfly/react-core/dist/styles/base.css";

import { KeycloakProvider } from "@keycloak/keycloak-ui-shared";
import {
ErrorBoundaryProvider,
KeycloakProvider,
} from "@keycloak/keycloak-ui-shared";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { environment } from "./environment";
Expand All @@ -17,7 +20,9 @@ const root = createRoot(container!);
root.render(
<StrictMode>
<KeycloakProvider environment={environment}>
<Root />
<ErrorBoundaryProvider>
<Root />
</ErrorBoundaryProvider>
</KeycloakProvider>
</StrictMode>,
);
21 changes: 9 additions & 12 deletions js/apps/account-ui/src/organizations/Organizations.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import OrganizationRepresentation from "@keycloak/keycloak-admin-client/lib/defs/organizationRepresentation";
import {
ErrorBoundaryProvider,
KeycloakSpinner,
ListEmptyState,
OrganizationTable,
Expand Down Expand Up @@ -30,17 +29,15 @@ export const Organizations = () => {

return (
<Page title={t("organizations")} description={t("organizationDescription")}>
<ErrorBoundaryProvider>
<OrganizationTable
link={({ children }) => <span>{children}</span>}
loader={userOrgs}
>
<ListEmptyState
message={t("emptyUserOrganizations")}
instructions={t("emptyUserOrganizationsInstructions")}
/>
</OrganizationTable>
</ErrorBoundaryProvider>
<OrganizationTable
link={({ children }) => <span>{children}</span>}
loader={userOrgs}
>
<ListEmptyState
message={t("emptyUserOrganizations")}
instructions={t("emptyUserOrganizationsInstructions")}
/>
</OrganizationTable>
</Page>
);
};
Expand Down
9 changes: 8 additions & 1 deletion js/apps/account-ui/src/root/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ErrorBoundaryFallback,
ErrorPage,
useAlerts,
useEnvironment,
Expand Down Expand Up @@ -91,5 +92,11 @@
if (!content) {
return <Spinner />;
}
return <RouterProvider router={createBrowserRouter(content)} />;
return (
<ErrorBoundaryFallback fallback={ErrorPage}>
<Suspense fallback={<KeycloakSpinner />}>

Check failure on line 97 in js/apps/account-ui/src/root/Root.tsx

View workflow job for this annotation

GitHub Actions / Account UI

'KeycloakSpinner' is not defined
<RouterProvider router={createBrowserRouter(content)} />
</Suspense>
</ErrorBoundaryFallback>
);
};
12 changes: 4 additions & 8 deletions js/apps/account-ui/src/utils/usePromise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useErrorBoundary } from "@keycloak/keycloak-ui-shared";
import type { DependencyList } from "react";
import { useEffect, useState } from "react";
import { useEffect } from "react";

/**
* Function that creates a Promise. Receives an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
Expand Down Expand Up @@ -47,7 +48,7 @@
callback: PromiseResolvedFn<T>,
deps: DependencyList = [],
) {
const [error, setError] = useState<unknown>();
const { showBoundary } = useErrorBoundary();
useEffect(() => {
const controller = new AbortController();
const { signal } = controller;
Expand All @@ -62,7 +63,7 @@
return;
}

setError(error);
showBoundary(error instanceof Error ? error : new Error(String(error)));
}
}

Expand All @@ -70,10 +71,5 @@

// Abort the Promise when the component unmounts, or the dependencies change.
return () => controller.abort();
}, deps);

Check warning on line 74 in js/apps/account-ui/src/utils/usePromise.ts

View workflow job for this annotation

GitHub Actions / Account UI

React Hook useEffect has missing dependencies: 'callback', 'factory', and 'showBoundary'. Either include them or remove the dependency array. If 'callback' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 74 in js/apps/account-ui/src/utils/usePromise.ts

View workflow job for this annotation

GitHub Actions / Account UI

React Hook useEffect was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies

// Rethrow other errors.
if (error) {
throw error;
}
}
Loading
0