import React from "react"; import { Alert, Button, Checkbox, Form, Input, Select, Space, Table, Tag, Typography, } from "antd"; import { ApiOutlined, ClusterOutlined, ThunderboltOutlined, } from "@ant-design/icons"; import type { MongoMemberInfo, SavedConnection } from "../types"; import { getStoredSecretPlaceholder, type ConnectionConfigSectionKey, } from "../utils/connectionModalPresentation"; import { useI18n } from "../i18n/provider"; import { noAutoCapInputProps } from "../utils/inputAutoCap"; const { Text } = Typography; 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: "mongoReplicaPassword"; hasStoredSecret?: boolean; clearLabel: string; description: string; }) => React.ReactNode; interface ConnectionModalMongoSectionsProps { mongoTopology: string; mongoSrv: boolean; useSSH: boolean; darkMode: boolean; modalMutedTextStyle: React.CSSProperties; mongoReadPreference: string; mongoMembers: MongoMemberInfo[]; discoveringMembers: boolean; initialValues?: SavedConnection | null; renderChoiceCards: RenderChoiceCards; renderConfigSectionCard: RenderConfigSectionCard; renderStoredSecretControls: RenderStoredSecretControls; setChoiceFieldValue: (fieldName: string, value: string | boolean) => void; handleDiscoverMongoMembers: () => void; } const ConnectionModalMongoSections: React.FC = ({ mongoTopology, mongoSrv, useSSH, darkMode, modalMutedTextStyle, mongoReadPreference, mongoMembers, discoveringMembers, initialValues, renderChoiceCards, renderConfigSectionCard, renderStoredSecretControls, setChoiceFieldValue, handleDiscoverMongoMembers, }) => { const { t } = useI18n(); return ( <> {renderConfigSectionCard({ sectionKey: "connectionMode", icon: , children: renderChoiceCards({ fieldName: "mongoTopology", value: String(mongoTopology), options: [ { value: "single", label: t("connection.modal.mongodb.topology.single.label"), description: t("connection.modal.topology.mongodb_single_description"), }, { value: "replica", label: t("connection.modal.mongodb.topology.replica.label"), description: t("connection.modal.topology.mongodb_replica_description"), }, ], }), })} {renderConfigSectionCard({ sectionKey: "mongoDiscovery", icon: , children: ( <>
{[ { value: false, label: t("connection.modal.mongodb.discovery.standard.label"), description: t("connection.modal.mongodb.discovery.standard.description"), }, { value: true, label: t("connection.modal.mongodb.discovery.srv.label"), description: t("connection.modal.mongodb.discovery.srv.description"), }, ].map((option) => { const active = mongoSrv === option.value; return ( ); })}
{mongoSrv && useSSH && ( )} ), })} {mongoTopology === "replica" && renderConfigSectionCard({ sectionKey: "replica", icon: , children: ( <> {renderStoredSecretControls({ fieldName: "mongoReplicaPassword", clearKey: "mongoReplicaPassword", hasStoredSecret: initialValues?.hasMongoReplicaPassword, clearLabel: t("connection.modal.mongodb.replica.password.clear"), description: t("connection.modal.mongodb.replica.password.description"), })} {mongoMembers.length > 0 && ( record.host} pagination={false} dataSource={mongoMembers} style={{ marginBottom: 12 }} columns={[ { title: "Host", dataIndex: "host", width: "48%" }, { title: t("connection.modal.mongodb.members.role"), dataIndex: "role", width: "32%", render: (value: string, record: MongoMemberInfo) => ( {value || "UNKNOWN"} ), }, { title: t("connection.modal.mongodb.members.health"), dataIndex: "healthy", width: "20%", render: (value: boolean) => ( {t( value ? "connection.modal.mongodb.members.health.ok" : "connection.modal.mongodb.members.health.error", )} ), }, ]} /> )} ), })} {renderConfigSectionCard({ sectionKey: "mongoPolicy", icon: , children: (
{t("connection.modal.mongodb.read_preference")} {renderChoiceCards({ fieldName: "mongoReadPreference", value: String(mongoReadPreference), minWidth: 130, options: [ { value: "primary", label: "primary", description: t("connection.modal.mongodb.read_preference.primary"), }, { value: "primaryPreferred", label: "primaryPreferred", description: t( "connection.modal.mongodb.read_preference.primary_preferred", ), }, { value: "secondary", label: "secondary", description: t("connection.modal.mongodb.read_preference.secondary"), }, { value: "secondaryPreferred", label: "secondaryPreferred", description: t( "connection.modal.mongodb.read_preference.secondary_preferred", ), }, { value: "nearest", label: "nearest", description: t("connection.modal.mongodb.read_preference.nearest"), }, ], })}
), })} ); }; export default ConnectionModalMongoSections;