Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CustomTooltip } from '@rentnerkev/tooltips/tooltip'
import { useId } from 'react'
import { useContext, useId } from 'react'
import { AppHostTableContext } from '@/features/AppUi/appHostTableContext.ts'

import ManagedDomainLink from '@/shared/Domain/ManagedDomainLink.tsx'
import ManagedDomainOverflow from '@/shared/Domain/ManagedDomainOverflow.tsx'
Expand Down Expand Up @@ -56,9 +57,12 @@ export function ProxyHostDomainsCell({
certificateId,
allowLinks = true,
discovery,
appManagedHostId,
enabled,
}: ProxyHostDomainsCellProps) {
const { t } = useTranslationStore()
const appTable = useContext(AppHostTableContext)
const ownerName = appManagedHostId && appTable?.view.ownerNames.get(appManagedHostId)
const descriptionId = useId()
const status = enabled === undefined ? undefined : enabled ? 'enabled' : 'disabled'
const visibleDomains = domains.slice(0, 2)
Expand Down Expand Up @@ -109,6 +113,12 @@ export function ProxyHostDomainsCell({
: 'admin.dockerDiscovery.host.managed',
)}
</span>
) : appManagedHostId ? (
<span className="text-xs font-bold text-muted">
{ownerName
? t('admin.proxyHosts.managedByApp', { name: ownerName })
: t('admin.proxyHosts.appManaged')}
</span>
) : null}
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default function useProxyHostsTableColumns(
certificateId: row.original.certificateId,
enabled: row.original.enabled,
discovery: row.original.discovery,
appManagedHostId: row.original.appManaged ? row.original.id : undefined,
}),
},
tagsColumn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface ProxyHostDomainsCellProps {
readonly allowLinks?: boolean
readonly enabled?: boolean
readonly discovery?: ProxyHostSummary['discovery']
readonly appManagedHostId?: string | undefined
}

export interface ProxyHostDomainChipProps {
Expand Down
30 changes: 23 additions & 7 deletions web/src/features/AppUi/Hooks/useAppHostTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,39 @@ import type {
export default function useAppHostTable(hosts: readonly ProxyHostSummary[]): AppHostTableView {
const appUi = useAppUi()
const { locale } = useTranslationStore()
const includeOwners = hosts.some((host) => host.appManaged)
const apps = useMemo(
() =>
(appUi?.apps ?? []).filter(
(app) => app.hostColumns.length > 0 || app.hostActions.length > 0,
(app) => includeOwners || app.hostColumns.length > 0 || app.hostActions.length > 0,
),
[appUi?.apps],
[appUi?.apps, includeOwners],
)
const ids = useMemo(
() => hosts.map((host) => host.id).slice(0, APP_HOST_TABLE.maxHosts),
[hosts],
)
const sessionId = appUi?.sessionId ?? null
const active = sessionId !== null && apps.length > 0 && ids.length > 0
const query = useQuery({
const {
data: hostTables,
isError,
isPending,
} = useQuery({
queryKey: [
'app-host-table',
sessionId,
apps.map((app) => `${app.installationId}:${app.generation}`),
ids.toSorted(),
includeOwners,
],
queryFn: ({ signal }) =>
readAppHostTablesHandler({
data: { sessionId: sessionId!, proxyHostIds: ids },
data: {
sessionId: sessionId!,
proxyHostIds: ids,
...(includeOwners && { includeOwners: true as const }),
},
signal,
}),
enabled: active,
Expand All @@ -63,7 +73,7 @@ export default function useAppHostTable(hosts: readonly ProxyHostSummary[]): App

return useMemo(() => {
// A failed refetch keeps old data in the query; it never counts as current.
const answer = query.isError ? undefined : query.data
const answer = isError ? undefined : hostTables
const tables = new Map(
(answer ?? []).flatMap((table) => {
const app = apps.find((entry) => entry.installationId === table.installationId)
Expand All @@ -73,6 +83,11 @@ export default function useAppHostTable(hosts: readonly ProxyHostSummary[]): App
: []
}),
)
const ownerNames = new Map<string, string>()
for (const app of apps) {
for (const id of tables.get(app.installationId)?.ownedHostIds ?? [])
ownerNames.set(id, app.name)
}
const actions = apps.flatMap((app) =>
app.hostActions.map((action): AppHostTableAction => ({
key: `${app.installationId}:${action.id}`,
Expand Down Expand Up @@ -112,8 +127,9 @@ export default function useAppHostTable(hosts: readonly ProxyHostSummary[]): App
return {
columns,
actions,
ownerNames,
cell(column, hostId) {
if (query.isPending) return { state: 'loading' }
if (isPending) return { state: 'loading' }
const data = tables
.get(column.installationId)
?.columns.find(({ id }) => id === column.columnId)
Expand All @@ -127,5 +143,5 @@ export default function useAppHostTable(hosts: readonly ProxyHostSummary[]): App
)
},
}
}, [apps, locale, query.data, query.isError, query.isPending, timeFormatter])
}, [apps, locale, hostTables, isError, isPending, timeFormatter])
}
1 change: 1 addition & 0 deletions web/src/features/AppUi/Types/app-host-table.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type AppHostCellView =
}

export interface AppHostTableView {
readonly ownerNames: ReadonlyMap<string, string>
readonly columns: readonly AppHostTableColumn[]
readonly actions: readonly AppHostTableAction[]
readonly cell: (column: AppHostTableColumn, hostId: string) => AppHostCellView
Expand Down
6 changes: 3 additions & 3 deletions web/src/features/AppUi/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export const readAppHostTablesHandler = createServerFn({ method: 'POST' })
if (!appUiEnabled() || !origin || request.headers.get('origin') !== origin) return []
const session = await getCurrentSessionService().catch(() => null)
if (session?.id !== data.sessionId) return []
return readAppHostTables(session.id, data.proxyHostIds, appUiSignal(request)).catch(
() => [],
)
return readAppHostTables(session.id, data.proxyHostIds, appUiSignal(request), {
includeOwners: data.includeOwners,
}).catch(() => [])
})

export const listAppUisHandler = createServerFn({ method: 'GET' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface ProxyHostSummary {
readonly responseCache?: ResponseCacheSettings | null | undefined
readonly tags?: readonly HostTag[]
readonly discovery?: { readonly state: 'managed' | 'orphaned' } | null
/** Ownership on the platform. This listing never includes a private installation ID. */
readonly appManaged?: true
readonly certificateJob?: CertificateJobSummary | null
readonly id: string
readonly domains: Array<string>
Expand Down
1 change: 1 addition & 0 deletions web/src/lib/AppUi/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type AppUiHostTable = {
installationId: string
generation: number
coveredHostIds: string[]
ownedHostIds?: string[]
columns: AppUiHostColumnData[]
}

Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/Language/Locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,8 @@
}
},
"proxyHosts": {
"appManaged": "App-verwaltet",
"managedByApp": "Verwaltet von {{name}}",
"page": {
"eyebrow": "Proxy-Verwaltung",
"title": "Proxy-Hosts",
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/Language/Locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,8 @@
}
},
"proxyHosts": {
"appManaged": "App-managed",
"managedByApp": "Managed by {{name}}",
"page": {
"eyebrow": "Proxy management",
"title": "Proxy hosts",
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/Language/Locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,8 @@
}
},
"proxyHosts": {
"appManaged": "Gestionado por una aplicación",
"managedByApp": "Gestionado por {{name}}",
"page": {
"eyebrow": "Gestión de proxy",
"title": "Hosts proxy",
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/Language/Locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,8 @@
}
},
"proxyHosts": {
"appManaged": "Géré par une application",
"managedByApp": "Géré par {{name}}",
"page": {
"eyebrow": "Gestion des proxys",
"title": "Hôtes proxy",
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/Language/Locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,8 @@
}
},
"proxyHosts": {
"appManaged": "Gestito da un’app",
"managedByApp": "Gestito da {{name}}",
"page": {
"eyebrow": "Gestione proxy",
"title": "Host proxy",
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/Language/Locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,8 @@
}
},
"proxyHosts": {
"appManaged": "Beheerd door een app",
"managedByApp": "Beheerd door {{name}}",
"page": {
"eyebrow": "Proxybeheer",
"title": "Proxyhosts",
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/Language/Locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,8 @@
}
},
"proxyHosts": {
"appManaged": "Zarządzany przez aplikację",
"managedByApp": "Zarządzany przez {{name}}",
"page": {
"eyebrow": "Zarządzanie proxy",
"title": "Hosty proxy",
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/Language/Locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,8 @@
}
},
"proxyHosts": {
"appManaged": "Gerido por uma aplicação",
"managedByApp": "Gerido por {{name}}",
"page": {
"eyebrow": "Gestão de proxy",
"title": "Hosts proxy",
Expand Down
20 changes: 16 additions & 4 deletions web/src/server/Admin/ProxyHostManagement/proxy-hosts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { AuthDomainError } from '@/server/Auth/Core/errors.server.ts'
import { asc, desc, eq, inArray, sql } from 'drizzle-orm'

import { PERMISSIONS } from '@/config/permissions.config.ts'
import { certificateJobs, hostDomains, proxyHosts } from '@/db/schema.ts'
import { appRuntimeOwnedProxyHosts, certificateJobs, hostDomains, proxyHosts } from '@/db/schema.ts'
import type { ProxyHostSummary } from '@/lib/Admin/ProxyHostManagement/Types/proxy-hosts.types.ts'
import type { ProxyRuntimeMutationStatus } from '@/lib/ProxyRuntime/Types/proxy-runtime.types.ts'
import { reconcileProxyConfigurationWithAudit } from '@/server/ProxyRuntime/proxy-runtime.service.ts'
Expand Down Expand Up @@ -88,9 +88,17 @@ export async function readProxyHostSummariesInTransaction(
): Promise<Array<ProxyHostSummary>> {
if (ids?.length === 0) return []
const rows = await transaction
.select({ ...proxyHostSummaryColumns, domain: hostDomains.domain })
.select({
...proxyHostSummaryColumns,
domain: hostDomains.domain,
appManaged: sql<boolean>`${appRuntimeOwnedProxyHosts.proxyHostId} is not null`,
})
.from(proxyHosts)
.leftJoin(hostDomains, eq(hostDomains.proxyHostId, proxyHosts.id))
.leftJoin(
appRuntimeOwnedProxyHosts,
eq(appRuntimeOwnedProxyHosts.proxyHostId, proxyHosts.id),
)
.where(ids ? inArray(proxyHosts.id, [...ids]) : undefined)
.orderBy(asc(proxyHosts.id), asc(hostDomains.domain))
const summaries = new Map<string, ProxyHostSummary>()
Expand All @@ -105,7 +113,10 @@ export async function readProxyHostSummariesInTransaction(
continue
}

summaries.set(row.id, toProxyHostSummary(row, row.domain ? [row.domain] : []))
summaries.set(row.id, {
...toProxyHostSummary(row, row.domain ? [row.domain] : []),
...(row.appManaged && { appManaged: true }),
})
}

const result: Array<ProxyHostSummary> = []
Expand Down Expand Up @@ -140,7 +151,8 @@ export async function readProxyHostSummariesInTransaction(
for (const summary of summaries.values()) {
const owner = ownersByHost.get(summary.id)
result.push({
...toProxyHostSummary(summary, summary.domains),
...summary,
domains: summary.domains.toSorted(),
responseCompression: httpSettings.get(summary.id)?.responseCompression ?? null,
browserCache: httpSettings.get(summary.id)?.browserCache,
...(responseCacheSettings.has(summary.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@tanstack/react-start/server-only'

import { inArray } from 'drizzle-orm'
import { proxyHosts } from '@/db/schema.ts'
import { appRuntimeOwnedProxyHosts, proxyHosts } from '@/db/schema.ts'
import type { AuthTransaction } from '@/server/Auth/Core/Types/database.types.ts'

export const proxyHostRoutingColumns = {
Expand Down Expand Up @@ -37,3 +37,18 @@ export async function readExistingProxyHostIdsInTransaction(
.where(inArray(proxyHosts.id, [...ids]))
return rows.map(({ id }) => id)
}

/** Only project the platform host and owning installation for this page. */
export async function readProxyHostOwnersInTransaction(
transaction: AuthTransaction,
ids: readonly string[],
) {
if (ids.length === 0) return []
return transaction
.select({
proxyHostId: appRuntimeOwnedProxyHosts.proxyHostId,
installationId: appRuntimeOwnedProxyHosts.installationId,
})
.from(appRuntimeOwnedProxyHosts)
.where(inArray(appRuntimeOwnedProxyHosts.proxyHostId, [...ids]))
}
Loading