Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
import { Fragment, ReactNode, useEffect, useRef, useState } from "react";
import { Control, Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useQueryClient } from "@tanstack/react-query";
import { Link } from "@tanstack/react-router";
import { format } from "date-fns";
import { Play, Radar, Search, TriangleAlert } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import { HighlightText } from "@app/components/utilities/HighlightText";
import {
Badge,
Button,
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
Empty,
EmptyHeader,
EmptyTitle,
Field,
FieldContent,
FieldError,
FieldLabel,
GatewayPicker,
Input,
InputGroup,
InputGroupAddon,
InputGroupInput,
Pagination,
ProviderIcon,
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow
} from "@app/components/v3";
import { Checkbox } from "@app/components/v3/generic/Checkbox";
import { useOrganization } from "@app/context";
import {
getUserTablePreference,
PreferenceKey,
setUserTablePreference
} from "@app/helpers/userTablePreferences";
import {
PamAccountType,
PamDiscoverySchedule,
PamDiscoveryType,
pamKeys,
TPamDiscoveredAccount,
TPamDiscoverySource,
useListPamAccounts,
useListPamDiscoveredAccounts,
useListPamDiscoveryRuns,
useListPamDiscoverySources,
useListPamDiscoveryTypes,
useListPamStaleAccounts,
usePamAccountTypeMap,
useTriggerPamDiscoveryScan,
useUpdatePamDiscoverySource
} from "@app/hooks/api/pam";
import { useDebounce } from "@app/hooks/useDebounce";
import { PamSheetTab, usePamSheetState } from "@app/hooks/usePamSheetState";
import { PamDetailSheet, PamDetailSheetTab } from "../../components/PamDetailSheet";
import { PAM_DISCOVERY_TABS } from "../../components/pamResourceTabs";
import { SheetSaveBar } from "../../components/SheetSaveBar";
import {
buildDiscoveryConfiguration,
buildHostRangeDiscoveryConfiguration,
CredentialAccountField,
CredentialAccountsField,
DiscoveryConfigFields,
discoveryConfigFormShape,
discoveryConfigFromSource,
HOST_RANGE_SOURCES,
HostRangeDiscoveryConfigFields,
hostRangeDiscoveryConfigFormShape,
hostRangeDiscoveryConfigFromSource,
isHostRangeDiscoveryType,
ScheduleField,
TDiscoveryConfigFields,
THostRangeDiscoveryConfigFields,
THostRangeDiscoveryType
} from "./DiscoveryConfigFields";
import { DiscoveryStatusBadge } from "./DiscoveryStatusBadge";
import { ImportDiscoveredModal } from "./ImportDiscoveredModal";
const STATUS_VARIANT: Record<string, "info" | "success" | "danger" | "neutral"> = {
running: "info",
completed: "success",
failed: "danger"
};
const RunStatusBadge = ({ status }: { status: string }) => (
<Badge variant={STATUS_VARIANT[status] ?? "neutral"}>{status}</Badge>
);
const NameField = ({ control }: { control: Control<{ name: string }> }) => (
<Controller
control={control}
name="name"
render={({ field, fieldState }) => (
<Field>
<FieldLabel>Name</FieldLabel>
<FieldContent>
<Input
{...field}
isError={!!fieldState.error}
autoComplete="off"
name="pam-discovery-source-name"
/>
<FieldError>{fieldState.error?.message}</FieldError>
</FieldContent>
</Field>
)}
/>
);
const GatewayField = ({
gatewayId,
gatewayPoolId,
onChange
}: {
gatewayId: string | null;
gatewayPoolId: string | null;
onChange: (value: { gatewayId: string | null; gatewayPoolId: string | null }) => void;
}) => (
<Field>
<FieldLabel>Gateway</FieldLabel>
<FieldContent>
<GatewayPicker isRequired value={{ gatewayId, gatewayPoolId }} onChange={onChange} />
</FieldContent>
</Field>
);
const ConfigCard = ({ children }: { children: ReactNode }) => (
<Card>
<CardHeader className="border-b">
<CardTitle className="text-base">Configuration</CardTitle>
<CardDescription>
Edit the source name, credential accounts, gateway, schedule, and account discovery.
</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-4">{children}</CardContent>
</Card>
);
const activeDirectoryConfigSchema = z.object({
name: z.string().min(1, "Name is required").max(64),
credentialAccountId: z.string().uuid("Select a credential account"),
schedule: z.nativeEnum(PamDiscoverySchedule),
gatewayId: z.string().nullable(),
gatewayPoolId: z.string().nullable(),
...discoveryConfigFormShape
});
const ActiveDirectoryConfigForm = ({
source,
onDirtyChange
}: {
source: TPamDiscoverySource;
onDirtyChange: (isDirty: boolean) => void;
}) => {
const updateSource = useUpdatePamDiscoverySource();
const defaults: z.infer<typeof activeDirectoryConfigSchema> = {
name: source.name,
credentialAccountId: source.credentialAccountId,
schedule: source.schedule,
gatewayId: source.gatewayId ?? null,
gatewayPoolId: source.gatewayPoolId ?? null,
...discoveryConfigFromSource(source.discoveryConfiguration)
};
const {
control,
handleSubmit,
reset,
watch,
setValue,
formState: { isDirty }
} = useForm({ resolver: zodResolver(activeDirectoryConfigSchema), defaultValues: defaults });
useEffect(() => {
onDirtyChange(isDirty);
return () => onDirtyChange(false);
}, [isDirty, onDirtyChange]);
useEffect(() => {
reset(defaults);
}, [source, reset]);
const onSubmit = (data: z.infer<typeof activeDirectoryConfigSchema>) => {
updateSource.mutate(
{
sourceId: source.id,
discoveryType: source.discoveryType,
name: data.name,
credentialAccountId: data.credentialAccountId,
schedule: data.schedule,
gatewayId: data.gatewayId,
gatewayPoolId: data.gatewayPoolId,
configuration: buildDiscoveryConfiguration(data)
},
{ onSuccess: () => createNotification({ type: "success", text: "Discovery source updated" }) }
);
};
return (
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-1 flex-col gap-4 p-4">
<ConfigCard>
<NameField control={control as unknown as Control<{ name: string }>} />
<CredentialAccountField
control={control as unknown as Control<{ credentialAccountId: string }>}
/>
<GatewayField
gatewayId={watch("gatewayId")}
gatewayPoolId={watch("gatewayPoolId")}
onChange={(value) => {
setValue("gatewayId", value.gatewayId, { shouldDirty: true });
setValue("gatewayPoolId", value.gatewayPoolId, { shouldDirty: true });
}}
/>
<ScheduleField
control={control as unknown as Control<{ schedule: PamDiscoverySchedule }>}
/>
<DiscoveryConfigFields control={control as unknown as Control<TDiscoveryConfigFields>} />
</ConfigCard>
<div aria-hidden className="h-8 shrink-0" />
{isDirty && <SheetSaveBar isPending={updateSource.isPending} onDiscard={() => reset()} />}
</form>
);
};
const hostRangeConfigSchema = z.object({
name: z.string().min(1, "Name is required").max(64),
schedule: z.nativeEnum(PamDiscoverySchedule),
gatewayId: z.string().nullable(),
gatewayPoolId: z.string().nullable(),
...hostRangeDiscoveryConfigFormShape
});
const HostRangeConfigForm = ({
source,
discoveryType,
onDirtyChange
}: {
source: TPamDiscoverySource;
discoveryType: THostRangeDiscoveryType;
onDirtyChange: (isDirty: boolean) => void;
}) => {
const updateSource = useUpdatePamDiscoverySource();
const sourceMeta = HOST_RANGE_SOURCES[discoveryType];
const defaults: z.infer<typeof hostRangeConfigSchema> = {
name: source.name,
schedule: source.schedule,
gatewayId: source.gatewayId ?? null,
gatewayPoolId: source.gatewayPoolId ?? null,
...hostRangeDiscoveryConfigFromSource(discoveryType, source.discoveryConfiguration)
};
const {
control,
handleSubmit,
reset,
watch,
setValue,
formState: { isDirty }
} = useForm({ resolver: zodResolver(hostRangeConfigSchema), defaultValues: defaults });
useEffect(() => {
onDirtyChange(isDirty);
return () => onDirtyChange(false);
}, [isDirty, onDirtyChange]);
useEffect(() => {
reset(defaults);
}, [source, reset]);
const onSubmit = (data: z.infer<typeof hostRangeConfigSchema>) => {
updateSource.mutate(
{
sourceId: source.id,
discoveryType: source.discoveryType,
name: data.name,
credentialAccountId: data.credentialAccountIds[0],
schedule: data.schedule,
gatewayId: data.gatewayId,
gatewayPoolId: data.gatewayPoolId,
configuration: buildHostRangeDiscoveryConfiguration(discoveryType, data)
},
{ onSuccess: () => createNotification({ type: "success", text: "Discovery source updated" }) }
);
};
return (
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-1 flex-col gap-4 p-4">
<ConfigCard>
<NameField control={control as unknown as Control<{ name: string }>} />
<CredentialAccountsField
control={control as unknown as Control<{ credentialAccountIds: string[] }>}
accountType={sourceMeta.accountType}
placeholder={sourceMeta.placeholder}
description={sourceMeta.description}
warning={sourceMeta.warning}
/>
<GatewayField
gatewayId={watch("gatewayId")}
gatewayPoolId={watch("gatewayPoolId")}
onChange={(value) => {
setValue("gatewayId", value.gatewayId, { shouldDirty: true });
setValue("gatewayPoolId", value.gatewayPoolId, { shouldDirty: true });
}}
/>
<ScheduleField
control={control as unknown as Control<{ schedule: PamDiscoverySchedule }>}
/>
<HostRangeDiscoveryConfigFields
control={control as unknown as Control<THostRangeDiscoveryConfigFields>}
discoveryType={discoveryType}
/>
</ConfigCard>
<div aria-hidden className="h-8 shrink-0" />
{isDirty && <SheetSaveBar isPending={updateSource.isPending} onDiscard={() => reset()} />}
</form>
);
};
const ConfigurationTab = ({
source,
onDirtyChange
}: {
source: TPamDiscoverySource;
onDirtyChange: (isDirty: boolean) => void;
}) =>
isHostRangeDiscoveryType(source.discoveryType) ? (
<HostRangeConfigForm
source={source}
discoveryType={source.discoveryType}
onDirtyChange={onDirtyChange}
/>
) : (
<ActiveDirectoryConfigForm source={source} onDirtyChange={onDirtyChange} />
);
type Props = {
isOpen: boolean;
sourceId?: string;
onOpenChange: (open: boolean) => void;
};
export const DiscoverySourceDetailSheet = ({ isOpen, sourceId, onOpenChange }: Props) => {
const [selected, setSelected] = useState<Record<string, TPamDiscoveredAccount>>({});
const [isImportOpen, setIsImportOpen] = useState(false);
const [isFormDirty, setIsFormDirty] = useState(false);
const [search, setSearch] = useState("");
const [debouncedSearch] = useDebounce(search);
const [page, setPage] = useState(1);
const [perPage, setPerPage] = useState(() =>
getUserTablePreference("pamDiscoveredAccountsTable", PreferenceKey.PerPage, 20)
);
const { currentOrg } = useOrganization();
const { tab, setTab } = usePamSheetState("discoverySourceId");
const { data: sources = [] } = useListPamDiscoverySources();
const { data: discoveryTypes = [] } = useListPamDiscoveryTypes();
const { data: adminAccounts = [] } = useListPamAccounts();
const { map: accountTypeMap } = usePamAccountTypeMap();
const source = sources.find((s) => s.id === sourceId);
const typeMeta = discoveryTypes.find((t) => t.type === source?.discoveryType);
const showDependencies =
source?.discoveryType !== PamDiscoveryType.Postgres &&
source?.discoveryType !== PamDiscoveryType.MsSQL;
const credentialAccount = adminAccounts.find((a) => a.id === source?.credentialAccountId);
const credentialAccountLabel = (() => {
if (!credentialAccount) return "View account";
return credentialAccount.folderName
? `${credentialAccount.folderName} / ${credentialAccount.name}`
: credentialAccount.name;
})();
const { data: runs = [] } = useListPamDiscoveryRuns(sourceId ?? "", {
refetchInterval: isOpen ? 5000 : undefined
});
const offset = (page - 1) * perPage;
const { data: { discoveredAccounts: staged = [], totalCount = 0 } = {} } =
useListPamDiscoveredAccounts(sourceId ?? "", {
search: debouncedSearch,
offset,
limit: perPage
});
const triggerScan = useTriggerPamDiscoveryScan();
const [staleSearch, setStaleSearch] = useState("");
const [debouncedStaleSearch] = useDebounce(staleSearch);
const [stalePage, setStalePage] = useState(1);
const [stalePerPage, setStalePerPage] = useState(() =>
getUserTablePreference("pamStaleAccountsTable", PreferenceKey.PerPage, 20)
);
const staleOffset = (stalePage - 1) * stalePerPage;
const { data: { accounts: stale = [], totalCount: staleTotal = 0 } = {} } =
useListPamStaleAccounts(sourceId ?? "", {
search: debouncedStaleSearch,
offset: staleOffset,
limit: stalePerPage
});
useEffect(() => {
setPage(1);
}, [debouncedSearch]);
useEffect(() => {
setStalePage(1);
}, [debouncedStaleSearch]);
const queryClient = useQueryClient();
const latestRunStatus = runs[0]?.status;
const prevRunStatus = useRef(latestRunStatus);
useEffect(() => {
if (prevRunStatus.current === "running" && latestRunStatus && latestRunStatus !== "running") {
queryClient.invalidateQueries({
queryKey: [...pamKeys.discovery(), "discovered", sourceId ?? ""]
});
queryClient.invalidateQueries({
queryKey: [...pamKeys.discovery(), "stale", sourceId ?? ""]
});
queryClient.invalidateQueries({ queryKey: [...pamKeys.discovery(), "sources"] });
// A scan reconciles dependencies onto managed accounts, so refresh account views (their dependency
// lists are keyed under pamKeys.account()) which the discovery scan otherwise never invalidates.
queryClient.invalidateQueries({ queryKey: pamKeys.account() });
}
prevRunStatus.current = latestRunStatus;
}, [latestRunStatus, sourceId, queryClient]);
const handleScan = () => {
if (!source) return;
triggerScan.mutate(
{ discoveryType: source.discoveryType, sourceId: source.id },
{
onSuccess: () => {
createNotification({ type: "success", text: "Scan started" });
setTab(PamSheetTab.Runs);
}
}
);
};
const q = search.trim().toLowerCase();
const visibleStaged = q ? staged.filter((a) => a.name.toLowerCase().includes(q)) : staged;
const selectedAccounts = Object.values(selected);
const allPageSelected =
visibleStaged.length > 0 && visibleStaged.every((a) => Boolean(selected[a.id]));
const toggle = (account: TPamDiscoveredAccount) =>
setSelected((prev) => {
const next = { ...prev };
if (next[account.id]) {
delete next[account.id];
} else {
next[account.id] = account;
}
return next;
});
const toggleAll = () =>
setSelected((prev) => {
if (allPageSelected) {
const next = { ...prev };
visibleStaged.forEach((a) => delete next[a.id]);
return next;
}
const next = { ...prev };
visibleStaged.forEach((a) => {
next[a.id] = a;
});
return next;
});
const stagedTab: ReactNode = (
<div className="flex flex-1 flex-col gap-4 p-4">
<Card>
<CardHeader className="border-b">
<CardTitle className="text-base">Staged Accounts</CardTitle>
<CardDescription>
Accounts found by the last scan. Select accounts to import them into a folder.
</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-4">
<InputGroup>
<InputGroupAddon align="inline-start">
<Search />
</InputGroupAddon>
<InputGroupInput
placeholder="Search accounts..."
value={search}
onChange={(e) => setSearch(e.target.value)}
/>
</InputGroup>
{totalCount === 0 ? (
<Empty className="border">
<EmptyHeader>
<EmptyTitle>
{debouncedSearch
? "No accounts match your search."
: "No staged accounts. Run a scan to discover accounts."}
</EmptyTitle>
</EmptyHeader>
</Empty>
) : (
<>
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-8">
<Checkbox
id="select-all-discovered"
isChecked={allPageSelected}
onCheckedChange={toggleAll}
/>
</TableHead>
<TableHead>Name</TableHead>
<TableHead className="w-40">Type</TableHead>
{showDependencies && <TableHead className="w-40">Dependencies</TableHead>}
</TableRow>
</TableHeader>
<TableBody>
{visibleStaged.map((account) => {
const typeDetails = accountTypeMap[account.accountType as PamAccountType];
const hasDeps = account.dependencyCount > 0;
return (
<TableRow key={account.id}>
<TableCell>
<Checkbox
id={`discovered-${account.id}`}
isChecked={Boolean(selected[account.id])}
onCheckedChange={() => toggle(account)}
/>
</TableCell>
<TableCell className="font-medium text-foreground">
<HighlightText text={account.name} highlight={search} />
</TableCell>
<TableCell>
<div className="flex items-center gap-2">
{typeDetails && (
<ProviderIcon
icon={typeDetails.icon}
alt={typeDetails.name}
className="size-5 shrink-0 rounded-sm"
/>
)}
<span className="text-sm">
{typeDetails?.name ?? account.accountType}
</span>
</div>
</TableCell>
{showDependencies && (
<TableCell>
{hasDeps ? (
<Badge variant="neutral">{account.dependencyCount}</Badge>
) : (
<span className="text-sm text-muted">-</span>
)}
</TableCell>
)}
</TableRow>
);
})}
</TableBody>
</Table>
<Pagination
count={totalCount}
page={page}
perPage={perPage}
onChangePage={setPage}
onChangePerPage={(newPerPage) => {
setPerPage(newPerPage);
setPage(1);
setUserTablePreference(
"pamDiscoveredAccountsTable",
PreferenceKey.PerPage,
newPerPage
);
}}
/>
</>
)}
</CardContent>
</Card>
{selectedAccounts.length > 0 && (
<div className="sticky bottom-0 -mx-4 mt-auto -mb-4 flex items-center gap-2 border-t border-border bg-popover px-4 py-3">
<span className="mr-auto text-sm text-muted">{selectedAccounts.length} selected</span>
<Button type="button" variant="ghost" onClick={() => setSelected({})}>
Clear
</Button>
<Button type="button" variant="pam" onClick={() => setIsImportOpen(true)}>
Import Accounts
</Button>
</div>
)}
</div>
);
const sq = staleSearch.trim().toLowerCase();
const visibleStale = sq ? stale.filter((a) => a.name.toLowerCase().includes(sq)) : stale;
const staleTab: ReactNode = (
<div className="flex flex-1 flex-col gap-4 p-4">
<Card>
<CardHeader className="border-b">
<CardTitle className="text-base">Stale Accounts</CardTitle>
<CardDescription>
Imported accounts the latest scan no longer found in the environment. They keep working
as normal, including rotation and access, so review them and delete the ones that are
really gone.
</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-4">
<InputGroup>
<InputGroupAddon align="inline-start">
<Search />
</InputGroupAddon>
<InputGroupInput
placeholder="Search accounts..."
value={staleSearch}
onChange={(e) => setStaleSearch(e.target.value)}
/>
</InputGroup>
{staleTotal === 0 ? (
<Empty className="border">
<EmptyHeader>
<EmptyTitle>
{debouncedStaleSearch
? "No accounts match your search."
: "No stale accounts. The latest scan found everything imported from this source."}
</EmptyTitle>
</EmptyHeader>
</Empty>
) : (
<>
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead className="w-40">Folder</TableHead>
<TableHead className="w-40">Type</TableHead>
<TableHead className="w-48">Last seen</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{visibleStale.map((account) => {
const typeDetails = accountTypeMap[account.accountType as PamAccountType];
return (
<TableRow key={account.id}>
<TableCell className="font-medium text-foreground">
<Link
to="/organizations/$orgId/pam/accounts"
params={{ orgId: currentOrg.id }}
search={{ accountId: account.accountId }}
className="hover:underline"
>
<HighlightText text={account.name} highlight={staleSearch} />
</Link>
</TableCell>
<TableCell className="text-muted">{account.folderName ?? "-"}</TableCell>
<TableCell>
<div className="flex items-center gap-2">
{typeDetails && (
<ProviderIcon
icon={typeDetails.icon}
alt={typeDetails.name}
className="size-5 shrink-0 rounded-sm"
/>
)}
<span className="text-sm">
{typeDetails?.name ?? account.accountType}
</span>
</div>
</TableCell>
<TableCell className="text-muted">
{account.lastDiscoveredAt
? format(new Date(account.lastDiscoveredAt), "MMM d, yyyy h:mm a")
: "-"}
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
<Pagination
count={staleTotal}
page={stalePage}
perPage={stalePerPage}
onChangePage={setStalePage}
onChangePerPage={(newPerPage) => {
setStalePerPage(newPerPage);
setStalePage(1);
setUserTablePreference(
"pamStaleAccountsTable",
PreferenceKey.PerPage,
newPerPage
);
}}
/>
</>
)}
</CardContent>
</Card>
</div>
);
const runsTab: ReactNode = (
<div className="flex flex-1 flex-col gap-4 p-4">
<Card>
<CardHeader className="border-b">
<CardTitle className="text-base">Scan History</CardTitle>
<CardDescription>The result of each scan run for this source.</CardDescription>
</CardHeader>
<CardContent>
{runs.length === 0 ? (
<Empty className="border">
<EmptyHeader>
<EmptyTitle>This source has not been scanned yet.</EmptyTitle>
</EmptyHeader>
</Empty>
) : (
<Table className="w-full">
<TableHeader>
<TableRow>
<TableHead className="w-44">Started</TableHead>
<TableHead className="w-28">Status</TableHead>
<TableHead>Result</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{runs.map((run) => {
const machineErrors = run.machineErrors ?? [];
// A completed run can still have per-machine failures; surface them full-width below the row
const hasMachineErrors = run.status !== "failed" && machineErrors.length > 0;
return (
<Fragment key={run.id}>
<TableRow className={hasMachineErrors ? "[&>td]:border-b-0" : undefined}>
<TableCell className="text-muted">
{run.startedAt
? format(new Date(run.startedAt), "MMM d, yyyy h:mm a")
: "-"}
</TableCell>
<TableCell>
<RunStatusBadge status={run.status} />
</TableCell>
<TableCell className="whitespace-normal text-muted">
{run.status === "failed" ? (
<span className="break-words whitespace-pre-line text-danger">
{run.errorMessage}
</span>
) : (
<div className="grid w-fit grid-cols-[auto_auto] gap-x-6">
<span>
{run.discoveredCount}{" "}
{run.discoveredCount === 1 ? "account" : "accounts"}
</span>
<span className="text-muted/60">{run.newCount} new</span>
{typeof run.dependencyCount === "number" && (
<>
<span>
{run.dependencyCount}{" "}
{run.dependencyCount === 1 ? "dep" : "deps"}
</span>
<span className="text-muted/60">
{run.newDependencyCount ?? 0} new
</span>
</>
)}
</div>
)}
</TableCell>
</TableRow>
{hasMachineErrors && (
<TableRow className="bg-warning/[0.04] hover:bg-warning/[0.04]">
<TableCell colSpan={3} className="pt-3 pb-4 whitespace-normal">
<div className="flex items-center gap-2 text-sm font-medium text-warning">
<TriangleAlert className="size-4 shrink-0" />
The scan couldn't complete on some machines
</div>
<ul className="mt-2 flex flex-col gap-1.5">
{machineErrors.map((m) => (
<li key={m.machine} className="text-xs break-words">
<span className="font-medium text-foreground">{m.machine}</span>
<span className="text-muted">: {m.error}</span>
</li>
))}
</ul>
</TableCell>
</TableRow>
)}
</Fragment>
);
})}
</TableBody>
</Table>
)}
</CardContent>
</Card>
</div>
);
const tabContent: Partial<Record<PamSheetTab, ReactNode>> = {
[PamSheetTab.General]: stagedTab,
[PamSheetTab.Stale]: staleTab,
[PamSheetTab.Runs]: runsTab,
[PamSheetTab.Configuration]: source ? (
<ConfigurationTab source={source} onDirtyChange={setIsFormDirty} />
) : null
};
const tabs: PamDetailSheetTab[] = PAM_DISCOVERY_TABS.map((t) => ({
value: t.value,
label: t.label,
icon: <t.icon className="mr-1 size-4" />,
content: tabContent[t.value] ?? null
}));
return (
<>
<PamDetailSheet
isOpen={isOpen}
onOpenChange={(open) => {
if (!open) {
setSelected({});
setSearch("");
setPage(1);
setStaleSearch("");
setStalePage(1);
}
onOpenChange(open);
}}
isLoading={isOpen && !source}
icon={
<div className="mb-4 flex size-16 items-center justify-center rounded-lg border border-border bg-container">
{typeMeta?.icon ? (
<ProviderIcon
icon={typeMeta.icon}
alt={typeMeta.name}
className="size-10 rounded-sm"
/>
) : (
<Radar className="size-8 text-muted" />
)}
</div>
}
title={source?.name}
typeBadge={typeMeta?.name ?? "Active Directory"}
badges={<DiscoveryStatusBadge status={runs[0]?.status} error={runs[0]?.errorMessage} />}
metadata={[
{
label: "Credential Account",
value: source?.credentialAccountId ? (
<Link
to="/organizations/$orgId/pam/accounts"
params={{ orgId: currentOrg.id }}
search={{ accountId: source.credentialAccountId }}
className="font-medium text-foreground hover:underline"
>
{credentialAccountLabel}
</Link>
) : (
"None"
)
},
{ label: "Schedule", value: <span className="capitalize">{source?.schedule}</span> },
{
label: "Last Run",
value: source?.lastRunAt
? format(new Date(source.lastRunAt), "MMM d, yyyy h:mm a")
: "Never"
}
]}
sidebarFooter={
<Button
variant="pam"
size="xs"
className="w-full"
isPending={triggerScan.isPending}
isDisabled={!source}
onClick={handleScan}
>
<Play />
Scan Now
</Button>
}
tabs={tabs}
activeTab={tab ?? PamSheetTab.General}
onTabChange={setTab}
isDirty={isFormDirty}
/>
{sourceId && (
<ImportDiscoveredModal
isOpen={isImportOpen}
onOpenChange={setIsImportOpen}
sourceId={sourceId}
credentialAccountId={source?.credentialAccountId}
accounts={selectedAccounts}
onImported={(discoveredAccountIds) =>
setSelected((prev) =>
Object.fromEntries(
Object.entries(prev).filter(([id]) => !discoveredAccountIds.includes(id))
)
)
}
/>
)}
</>
);
};