Fix homepage URL rendering in client list (#3057) (#3058)

Signed-off-by: Thomas Darimont <thomas.darimont@googlemail.com>

Signed-off-by: Thomas Darimont <thomas.darimont@googlemail.com>
This commit is contained in:
Thomas Darimont 2022-08-16 14:18:26 +02:00 committed by GitHub
parent 7cd7d0b251
commit 2da5be3907
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -103,6 +103,40 @@ export default function ClientsSection() {
</TableText> </TableText>
); );
const ClientHomePage = (client: ClientRepresentation) => {
const rootUrl = client.rootUrl;
const baseUrl = client.baseUrl;
// absolute base url configured, use base url is
if (baseUrl?.startsWith("http")) {
return baseUrl;
}
if (rootUrl === "${authBaseUrl}" && baseUrl) {
// eslint-disable-next-line prettier/prettier
return rootUrl.replace("${authBaseUrl}", addTrailingSlash(adminClient.baseUrl)) + baseUrl.substring(1);
}
if (rootUrl === "${authAdminUrl}" && baseUrl) {
// eslint-disable-next-line prettier/prettier
return rootUrl.replace("${authAdminUrl}", addTrailingSlash(adminClient.baseUrl)) + baseUrl.substring(1);
}
if (!rootUrl) {
return baseUrl;
}
if (rootUrl.startsWith("http")) {
let targetUrl = rootUrl;
if (baseUrl) {
targetUrl = addTrailingSlash(targetUrl) + baseUrl.substring(1);
}
return targetUrl;
}
return baseUrl;
};
const ToolbarItems = () => { const ToolbarItems = () => {
if (!isManager) return <span />; if (!isManager) return <span />;
@ -215,28 +249,7 @@ export default function ClientsSection() {
name: "baseUrl", name: "baseUrl",
displayKey: "clients:homeURL", displayKey: "clients:homeURL",
cellFormatters: [formattedLinkTableCell(), emptyFormatter()], cellFormatters: [formattedLinkTableCell(), emptyFormatter()],
cellRenderer: (client) => { cellRenderer: ClientHomePage,
if (client.rootUrl) {
if (
!client.rootUrl.startsWith("http") ||
client.rootUrl.includes("$")
) {
return (
client.rootUrl
.replace(
"${authBaseUrl}",
addTrailingSlash(adminClient.baseUrl)
)
.replace(
"${authAdminUrl}",
addTrailingSlash(adminClient.baseUrl)
) +
(client.baseUrl ? client.baseUrl.substring(1) : "")
);
}
}
return client.baseUrl;
},
}, },
]} ]}
/> />