(test = false)
| 125 | }; |
| 126 | |
| 127 | const _onCreateConnection = (test = false) => { |
| 128 | setErrors({}); |
| 129 | |
| 130 | if (!connection.name || connection.name.length > 24) { |
| 131 | setTimeout(() => { |
| 132 | setErrors({ ...errors, name: "Please enter a name which is less than 24 characters" }); |
| 133 | }, 100); |
| 134 | return; |
| 135 | } |
| 136 | if (!connection.host) { |
| 137 | setTimeout(() => { |
| 138 | setErrors({ ...errors, host: "Please enter a host name or IP address for your database" }); |
| 139 | }, 100); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | // prepare the options |
| 144 | const tempOptions = connection.optionsArray; |
| 145 | const newOptions = []; |
| 146 | if (tempOptions && tempOptions.length > 0) { |
| 147 | for (let i = 0; i < tempOptions.length; i++) { |
| 148 | if (tempOptions[i].key && tempOptions[i].value) { |
| 149 | newOptions.push({ [tempOptions[i].key]: tempOptions[i].value }); |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | // add the project ID |
| 155 | const newConnection = { ...connection, options: newOptions }; |
| 156 | setConnection(newConnection); |
| 157 | |
| 158 | if (test === true) { |
| 159 | setTestLoading(true); |
| 160 | _onTestRequest(newConnection) |
| 161 | .then(() => setTestLoading(false)) |
| 162 | .catch(() => setTestLoading(false)); |
| 163 | } else { |
| 164 | setLoading(true); |
| 165 | onComplete(newConnection) |
| 166 | .then(() => setLoading(false)) |
| 167 | .catch(() => setLoading(false)); |
| 168 | } |
| 169 | }; |
| 170 | |
| 171 | const _addOption = () => { |
| 172 | const option = { |
no test coverage detected