Add an "Open admin" button to the integration pages
Each integration page now has a button next to its title that opens the product's own admin panel in a new tab, using the address entered on the integration. Tailscale links to its admin console. Only http(s) addresses become links. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
51ad309e35
commit
75f0a3d881
9 files changed
+64
-8
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import type { IntegrationSummary } from "../api/client";
|
||||
|
||||
/** Only http(s) addresses become links, so a stored value can never turn into a javascript: link. */
|
||||
function webAddress(value: string | undefined): string | null {
|
||||
if (!value) return null;
|
||||
try {
|
||||
const url = new URL(value);
|
||||
return url.protocol === "http:" || url.protocol === "https:" ? url.href : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Page heading for an integration page, with a button that opens the product's own admin panel
|
||||
* in a new tab. The address is the one entered on the integration (its URL field); `url` overrides
|
||||
* it for products with no address of their own (Tailscale).
|
||||
*/
|
||||
export default function IntegrationPageTitle({
|
||||
title,
|
||||
adminName,
|
||||
integration,
|
||||
url,
|
||||
}: {
|
||||
title: string;
|
||||
/** Product name for the button when the page title is not it (the Docker page is Dockhand). */
|
||||
adminName?: string;
|
||||
integration: IntegrationSummary | null;
|
||||
url?: string;
|
||||
}) {
|
||||
const href = webAddress(url ?? integration?.baseUrl);
|
||||
return (
|
||||
<div className="d-flex flex-wrap align-items-center gap-3 mb-3">
|
||||
<h2 className="page-title mb-0">{title}</h2>
|
||||
{href && (
|
||||
<a
|
||||
className="btn btn-sm btn-outline-secondary"
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
title={href}
|
||||
>
|
||||
Open {adminName ?? title} admin ↗
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user