mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-21 01:16:49 +00:00
190 lines
7.3 KiB
TypeScript
190 lines
7.3 KiB
TypeScript
import {
|
|
faBan,
|
|
faCertificate,
|
|
faEllipsis,
|
|
faPencil,
|
|
faTrash
|
|
} from "@fortawesome/free-solid-svg-icons";
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
import { ProjectPermissionCan } from "@app/components/permissions";
|
|
import {
|
|
Badge,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
EmptyState,
|
|
Table,
|
|
TableContainer,
|
|
TableSkeleton,
|
|
TBody,
|
|
Td,
|
|
Th,
|
|
THead,
|
|
Tooltip,
|
|
Tr
|
|
} from "@app/components/v2";
|
|
import { ProjectPermissionActions, ProjectPermissionSub, useProject } from "@app/context";
|
|
import { CaStatus, CaType, useListExternalCasByProjectId } from "@app/hooks/api";
|
|
import { caStatusToNameMap, getCaStatusBadgeVariant } from "@app/hooks/api/ca/constants";
|
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
|
|
|
type Props = {
|
|
handlePopUpOpen: (
|
|
popUpName: keyof UsePopUpState<["ca", "deleteCa", "caStatus", "upgradePlan"]>,
|
|
data?: {
|
|
name?: string;
|
|
type?: CaType;
|
|
status?: CaStatus;
|
|
description?: string;
|
|
}
|
|
) => void;
|
|
};
|
|
|
|
export const ExternalCaTable = ({ handlePopUpOpen }: Props) => {
|
|
const { currentProject } = useProject();
|
|
const { data, isPending } = useListExternalCasByProjectId(currentProject.id);
|
|
|
|
return (
|
|
<div>
|
|
<TableContainer>
|
|
<Table>
|
|
<THead>
|
|
<Tr>
|
|
<Th>Name</Th>
|
|
<Th>Type</Th>
|
|
<Th>Status</Th>
|
|
<Th />
|
|
</Tr>
|
|
</THead>
|
|
<TBody>
|
|
{isPending && <TableSkeleton columns={3} innerKey="project-cas" />}
|
|
{!isPending &&
|
|
data &&
|
|
data.length > 0 &&
|
|
data.map((ca) => {
|
|
return (
|
|
<Tr
|
|
className="h-10 cursor-pointer transition-colors duration-100 hover:bg-mineshaft-700"
|
|
key={`ca-${ca.id}`}
|
|
onClick={() => {
|
|
handlePopUpOpen("ca", {
|
|
name: ca.name,
|
|
type: ca.type
|
|
});
|
|
}}
|
|
>
|
|
<Td>{ca.name}</Td>
|
|
<Td>{ca.type}</Td>
|
|
<Td>
|
|
<Badge variant={getCaStatusBadgeVariant(ca.status)}>
|
|
{caStatusToNameMap[ca.status]}
|
|
</Badge>
|
|
</Td>
|
|
<Td className="flex justify-end">
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild className="rounded-lg">
|
|
<div className="hover:text-primary-400 data-[state=open]:text-primary-400">
|
|
<Tooltip content="More options">
|
|
<FontAwesomeIcon size="lg" icon={faEllipsis} />
|
|
</Tooltip>
|
|
</div>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="start" className="p-1">
|
|
<ProjectPermissionCan
|
|
I={ProjectPermissionActions.Edit}
|
|
a={ProjectPermissionSub.CertificateAuthorities}
|
|
>
|
|
{(isAllowed) => (
|
|
<DropdownMenuItem
|
|
className={twMerge(
|
|
!isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
|
|
)}
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
handlePopUpOpen("ca", {
|
|
name: ca.name,
|
|
type: ca.type
|
|
});
|
|
}}
|
|
disabled={!isAllowed}
|
|
icon={<FontAwesomeIcon icon={faPencil} />}
|
|
>
|
|
Edit CA
|
|
</DropdownMenuItem>
|
|
)}
|
|
</ProjectPermissionCan>
|
|
{(ca.status === CaStatus.ACTIVE || ca.status === CaStatus.DISABLED) && (
|
|
<ProjectPermissionCan
|
|
I={ProjectPermissionActions.Edit}
|
|
a={ProjectPermissionSub.CertificateAuthorities}
|
|
>
|
|
{(isAllowed) => (
|
|
<DropdownMenuItem
|
|
className={twMerge(
|
|
!isAllowed &&
|
|
"pointer-events-none cursor-not-allowed opacity-50"
|
|
)}
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
handlePopUpOpen("caStatus", {
|
|
name: ca.name,
|
|
type: ca.type,
|
|
status:
|
|
ca.status === CaStatus.ACTIVE
|
|
? CaStatus.DISABLED
|
|
: CaStatus.ACTIVE
|
|
});
|
|
}}
|
|
disabled={!isAllowed}
|
|
icon={<FontAwesomeIcon icon={faBan} />}
|
|
>
|
|
{`${ca.status === CaStatus.ACTIVE ? "Disable" : "Enable"} CA`}
|
|
</DropdownMenuItem>
|
|
)}
|
|
</ProjectPermissionCan>
|
|
)}
|
|
<ProjectPermissionCan
|
|
I={ProjectPermissionActions.Delete}
|
|
a={ProjectPermissionSub.CertificateAuthorities}
|
|
>
|
|
{(isAllowed) => (
|
|
<DropdownMenuItem
|
|
className={twMerge(
|
|
!isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
|
|
)}
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
handlePopUpOpen("deleteCa", {
|
|
name: ca.name,
|
|
type: ca.type
|
|
});
|
|
}}
|
|
disabled={!isAllowed}
|
|
icon={<FontAwesomeIcon icon={faTrash} />}
|
|
>
|
|
Delete CA
|
|
</DropdownMenuItem>
|
|
)}
|
|
</ProjectPermissionCan>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</Td>
|
|
</Tr>
|
|
);
|
|
})}
|
|
</TBody>
|
|
</Table>
|
|
{!isPending && data?.length === 0 && (
|
|
<EmptyState
|
|
title="No external certificate authorities have been created"
|
|
icon={faCertificate}
|
|
/>
|
|
)}
|
|
</TableContainer>
|
|
</div>
|
|
);
|
|
};
|