Fix 'Home URL' link in clients overview (#4363)

This commit is contained in:
Jon Koops 2023-02-10 07:31:00 +01:00 committed by GitHub
parent c6e6bceb10
commit ddc0b3ebaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View file

@ -16,7 +16,7 @@ import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
import { useAlerts } from "../components/alert/Alerts";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import { formattedLinkTableCell } from "../components/external-link/FormattedLink";
import { FormattedLink } from "../components/external-link/FormattedLink";
import {
Action,
KeycloakDataTable,
@ -68,6 +68,17 @@ const ClientDescription = (client: ClientRepresentation) => (
</TableText>
);
const ClientHomeLink = (client: ClientRepresentation) => {
const { adminClient } = useAdminClient();
const href = convertClientToUrl(client, adminClient.baseUrl);
if (!href) {
return "—";
}
return <FormattedLink href={href} />;
};
export default function ClientsSection() {
const { t } = useTranslation("clients");
const { addAlert, addError } = useAlerts();
@ -233,9 +244,7 @@ export default function ClientsSection() {
name: "baseUrl",
displayKey: "clients:homeURL",
transforms: [cellWidth(20)],
cellFormatters: [formattedLinkTableCell(), emptyFormatter()],
cellRenderer: (c) =>
convertClientToUrl(c, adminClient.baseUrl) || "",
cellRenderer: ClientHomeLink,
},
]}
/>

View file

@ -1,6 +1,5 @@
import { AnchorHTMLAttributes } from "react";
import { ExternalLinkAltIcon } from "@patternfly/react-icons";
import type { IFormatter, IFormatterValueType } from "@patternfly/react-table";
import { AnchorHTMLAttributes } from "react";
export type FormattedLinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
isInline?: boolean;
@ -25,10 +24,3 @@ export const FormattedLink = ({
</a>
);
};
export const formattedLinkTableCell =
(): IFormatter => (data?: IFormatterValueType) => {
return (
data ? <FormattedLink href={data.toString()} /> : undefined
) as object;
};