Files
nginx-proxy-manager/frontend/src/components/Table/Formatter/CertificateInUseFormatter.tsx
T

83 lines
1.9 KiB
TypeScript
Raw Normal View History

2025-10-27 18:08:37 +10:00
import OverlayTrigger from "react-bootstrap/OverlayTrigger";
import Popover from "react-bootstrap/Popover";
2025-10-28 23:10:00 +10:00
import type { DeadHost, ProxyHost, RedirectionHost, Stream } from "src/api/backend";
2025-10-27 23:25:00 +10:00
import { TrueFalseFormatter } from "src/components";
2025-10-27 18:08:37 +10:00
import { T } from "src/locale";
const getSection = (title: string, items: ProxyHost[] | RedirectionHost[] | DeadHost[]) => {
if (items.length === 0) {
return null;
}
return (
<>
<div>
<strong>
<T id={title} />
</strong>
</div>
{items.map((host) => (
<div key={host.id} className="ms-1">
{host.domainNames.join(", ")}
</div>
))}
</>
);
};
2025-10-28 23:10:00 +10:00
const getSectionStream = (items: Stream[]) => {
if (items.length === 0) {
return null;
}
return (
<>
<div>
<strong>
<T id="streams" />
</strong>
</div>
{items.map((stream) => (
<div key={stream.id} className="ms-1">
{stream.forwardingHost}:{stream.forwardingPort}
</div>
))}
</>
);
};
2025-10-27 18:08:37 +10:00
interface Props {
proxyHosts: ProxyHost[];
redirectionHosts: RedirectionHost[];
deadHosts: DeadHost[];
2025-10-28 23:10:00 +10:00
streams: Stream[];
2025-10-27 18:08:37 +10:00
}
2025-10-28 23:10:00 +10:00
export function CertificateInUseFormatter({ proxyHosts, redirectionHosts, deadHosts, streams }: Props) {
const totalCount = proxyHosts?.length + redirectionHosts?.length + deadHosts?.length + streams?.length;
2025-10-27 18:08:37 +10:00
if (totalCount === 0) {
2025-10-27 23:25:00 +10:00
return <TrueFalseFormatter value={false} falseLabel="certificate.not-in-use" />;
2025-10-27 18:08:37 +10:00
}
proxyHosts.sort();
redirectionHosts.sort();
deadHosts.sort();
2025-10-28 23:10:00 +10:00
streams.sort();
2025-10-27 18:08:37 +10:00
const popover = (
<Popover id="popover-basic">
<Popover.Body>
{getSection("proxy-hosts", proxyHosts)}
{getSection("redirection-hosts", redirectionHosts)}
{getSection("dead-hosts", deadHosts)}
2025-10-28 23:10:00 +10:00
{getSectionStream(streams)}
2025-10-27 18:08:37 +10:00
</Popover.Body>
</Popover>
);
return (
2025-10-27 23:25:00 +10:00
<OverlayTrigger trigger={["hover", "click", "focus"]} placement="bottom" overlay={popover}>
<div>
<TrueFalseFormatter value trueLabel="certificate.in-use" />
</div>
2025-10-27 18:08:37 +10:00
</OverlayTrigger>
);
}