MCPcopy Index your code
hub / github.com/sqlchat/sqlchat / CreateConnectionModal

Function CreateConnectionModal

src/components/CreateConnectionModal.tsx:89–443  ·  view source on GitHub ↗
(props: Props)

Source from the content-addressed store, hash-verified

87};
88
89const CreateConnectionModal = (props: Props) => {
90 const { connection: editConnection, close } = props;
91 const { t } = useTranslation();
92 const connectionStore = useConnectionStore();
93 const [connection, setConnection] = useState<Connection>(defaultConnection);
94 const [showDeleteConnectionModal, setShowDeleteConnectionModal] = useState(false);
95 const [sslType, setSSLType] = useState<SSLType>("preferred");
96 const [selectedSSLField, setSelectedSSLField] = useState<SSLFieldType>("ca");
97 const [isRequesting, setIsRequesting] = useState(false);
98 const showDatabaseField = connection.engineType === Engine.PostgreSQL || connection.engineType === Engine.MSSQL;
99 const isEditing = editConnection !== undefined;
100 const allowSave = connection.title !== "" && connection.host !== "" && connection.username !== "";
101
102 useEffect(() => {
103 const connection = isEditing ? editConnection : defaultConnection;
104 setConnection(connection);
105 if (connection.ssl) {
106 if (connection.ssl.ca && connection.ssl.cert && connection.ssl.key) {
107 setSSLType("full");
108 } else {
109 setSSLType("ca-only");
110 }
111 }
112 }, []);
113
114 useEffect(() => {
115 let ssl: SSLOptions | undefined = undefined;
116 if (sslType === "ca-only") {
117 ssl = {
118 ca: "",
119 };
120 } else if (sslType === "full") {
121 ssl = {
122 ca: "",
123 cert: "",
124 key: "",
125 };
126 }
127 setConnection((connection) => ({
128 ...connection,
129 ssl: ssl,
130 }));
131 setSelectedSSLField("ca");
132 }, [sslType]);
133
134 const setPartialConnection = (state: Partial<Connection>) => {
135 setConnection({
136 ...connection,
137 ...state,
138 });
139 };
140
141 const handleSSLFileInputChange = (event: ChangeEvent<HTMLInputElement>) => {
142 const files = event.currentTarget.files;
143 if (!files || files.length === 0) {
144 return;
145 }
146

Callers

nothing calls this directly

Calls 2

setPartialConnectionFunction · 0.85
handleDeleteConnectionFunction · 0.85

Tested by

no test coverage detected