import React from "react"; import { Form, Input, Select } from "antd"; import { ClusterOutlined, DatabaseOutlined, SafetyCertificateOutlined, } from "@ant-design/icons"; import type { SavedConnection } from "../types"; import { getStoredSecretPlaceholder, type ConnectionConfigSectionKey, } from "../utils/connectionModalPresentation"; import { useI18n } from "../i18n/provider"; import { noAutoCapInputProps } from "../utils/inputAutoCap"; type ChoiceCardOption = { value: string; label: string; description?: string; }; type RenderChoiceCards = (params: { fieldName: string; value: string; options: ChoiceCardOption[]; minWidth?: number; onSelect?: (value: string) => void; }) => React.ReactNode; type RenderConfigSectionCard = (params: { sectionKey: ConnectionConfigSectionKey; icon: React.ReactNode; children: React.ReactNode; badge?: React.ReactNode; }) => React.ReactNode; type RenderStoredSecretControls = (params: { fieldName: string; clearKey: "redisSentinelPassword"; hasStoredSecret?: boolean; clearLabel: string; description: string; }) => React.ReactNode; interface ConnectionModalRedisSectionsProps { redisTopology: string; redisDbList: number[]; initialValues?: SavedConnection | null; primaryPasswordVisible: boolean; setPrimaryPasswordVisible: (visible: boolean) => void; renderChoiceCards: RenderChoiceCards; renderConfigSectionCard: RenderConfigSectionCard; renderStoredSecretControls: RenderStoredSecretControls; createUriAwareRequiredRule: ( messageText: string, validateValue?: (value: unknown) => boolean, ) => any; } const ConnectionModalRedisSections: React.FC = ({ redisTopology, redisDbList, initialValues, primaryPasswordVisible, setPrimaryPasswordVisible, renderChoiceCards, renderConfigSectionCard, renderStoredSecretControls, createUriAwareRequiredRule, }) => { const { t } = useI18n(); return ( <> {renderConfigSectionCard({ sectionKey: "connectionMode", icon: , children: ( <> {renderChoiceCards({ fieldName: "redisTopology", value: String(redisTopology), options: [ { value: "single", label: t("connection.modal.redis.topology.single.label"), description: t("connection.modal.redis.topology.single.description"), }, { value: "cluster", label: t("connection.modal.redis.topology.cluster.label"), description: t("connection.modal.redis.topology.cluster.description"), }, { value: "sentinel", label: t("connection.modal.redis.topology.sentinel.label"), description: t("connection.modal.redis.topology.sentinel.description"), }, ], })} {(redisTopology === "cluster" || redisTopology === "sentinel") && ( <> )} )} ), })} {renderConfigSectionCard({ sectionKey: "credentials", icon: , children: ( <> {redisTopology === "sentinel" && ( <>
{renderStoredSecretControls({ fieldName: "redisSentinelPassword", clearKey: "redisSentinelPassword", hasStoredSecret: initialValues?.hasRedisSentinelPassword, clearLabel: t("connection.modal.redis.credentials.sentinelPassword.clear"), description: t( "connection.modal.redis.credentials.sentinelPassword.description", ), })} )} ), })} {renderConfigSectionCard({ sectionKey: "databaseScope", icon: , children: ( ), })} ); }; export default ConnectionModalRedisSections;