Set default certificates for private resources

This commit is contained in:
Fred KISSIE
2026-07-29 19:11:03 +01:00
parent ac79621cae
commit 5cbb767e5f
2 changed files with 48 additions and 2 deletions
@@ -6,6 +6,8 @@ import { internal } from "@app/lib/api";
import { authCookieHeader } from "@app/lib/api/cookies"; import { authCookieHeader } from "@app/lib/api/cookies";
import { getCachedOrg } from "@app/lib/api/getCachedOrg"; import { getCachedOrg } from "@app/lib/api/getCachedOrg";
import OrgProvider from "@app/providers/OrgProvider"; import OrgProvider from "@app/providers/OrgProvider";
import { build } from "@server/build";
import type { GetBatchedCertificateResponse } from "@server/routers/certificates/types";
import type { ListAllSiteResourcesByOrgResponse } from "@server/routers/siteResource"; import type { ListAllSiteResourcesByOrgResponse } from "@server/routers/siteResource";
import type { AxiosResponse } from "axios"; import type { AxiosResponse } from "axios";
import type { Metadata } from "next"; import type { Metadata } from "next";
@@ -99,6 +101,42 @@ export default async function ClientResourcesPage(
}; };
} }
); );
// Prefetched in one batched call so the table doesn't fire a separate
// certificate request per visible row once it mounts on the client.
const certDomains = Array.from(
new Set(
internalResourceRows
.filter(
(r) =>
r.mode === "http" &&
!r.alias &&
r.ssl &&
r.domainId &&
r.fullDomain
)
.map((r) => r.fullDomain as string)
)
);
let initialCertificates: GetBatchedCertificateResponse | undefined;
if (build !== "oss" && certDomains.length > 0) {
try {
const certSearchParams = new URLSearchParams(
certDomains.map((domain) => ["domains", domain])
);
const certRes = await internal.get<
AxiosResponse<GetBatchedCertificateResponse>
>(
`/org/${params.orgId}/batched-certificates?${certSearchParams.toString()}`,
await authCookieHeader()
);
initialCertificates = certRes.data.data;
} catch {
// leave undefined so each row falls back to fetching its own
}
}
return ( return (
<> <>
<SettingsSectionTitle <SettingsSectionTitle
@@ -117,6 +155,7 @@ export default async function ClientResourcesPage(
pageIndex: pagination.page - 1, pageIndex: pagination.page - 1,
pageSize: pagination.pageSize pageSize: pagination.pageSize
}} }}
initialCertificates={initialCertificates}
/> />
</OrgProvider> </OrgProvider>
</> </>
+9 -2
View File
@@ -37,6 +37,7 @@ import { getPrivateResourceSettingsHref } from "@app/lib/launcherResourceAdminHr
import { getNextSortOrder, getSortDirection } from "@app/lib/sortColumn"; import { getNextSortOrder, getSortDirection } from "@app/lib/sortColumn";
import { build } from "@server/build"; import { build } from "@server/build";
import { tierMatrix } from "@server/lib/billing/tierMatrix"; import { tierMatrix } from "@server/lib/billing/tierMatrix";
import type { GetBatchedCertificateResponse } from "@server/routers/certificates/types";
import { UpdateSiteResourceResponse } from "@server/routers/siteResource"; import { UpdateSiteResourceResponse } from "@server/routers/siteResource";
import type { PaginationState } from "@tanstack/react-table"; import type { PaginationState } from "@tanstack/react-table";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
@@ -136,13 +137,16 @@ type ClientResourcesTableProps = {
orgId: string; orgId: string;
pagination: PaginationState; pagination: PaginationState;
rowCount: number; rowCount: number;
/** Certificates prefetched on the server, keyed by full domain. */
initialCertificates?: GetBatchedCertificateResponse;
}; };
export default function PrivateResourcesTable({ export default function PrivateResourcesTable({
internalResources, internalResources,
orgId, orgId,
pagination, pagination,
rowCount rowCount,
initialCertificates
}: ClientResourcesTableProps) { }: ClientResourcesTableProps) {
const router = useRouter(); const router = useRouter();
const { const {
@@ -432,6 +436,9 @@ export default function PrivateResourcesTable({
orgId={resourceRow.orgId} orgId={resourceRow.orgId}
domainId={domainId} domainId={domainId}
fullDomain={fullDomain} fullDomain={fullDomain}
initialCertValue={
initialCertificates?.[fullDomain]
}
/> />
) : null} ) : null}
<div className=""> <div className="">
@@ -585,7 +592,7 @@ export default function PrivateResourcesTable({
]; ];
return cols; return cols;
}, [orgId, t, searchParams]); }, [orgId, t, searchParams, initialCertificates]);
function handleFilterChange( function handleFilterChange(
column: string, column: string,