(props: { open: boolean; onOpenChange: (open: boolean) => void })
| 164 | }; |
| 165 | |
| 166 | export function ConnectDialog(props: { open: boolean; onOpenChange: (open: boolean) => void }) { |
| 167 | const integrationPlugins = useIntegrationPlugins(); |
| 168 | const doDetect = useAtomSet(detectIntegration, { mode: "promiseExit" }); |
| 169 | const navigate = useNavigate(); |
| 170 | |
| 171 | const [query, setQuery] = useState(""); |
| 172 | const [detecting, setDetecting] = useState(false); |
| 173 | const [error, setError] = useState<string | null>(null); |
| 174 | |
| 175 | const isUrl = looksLikeUrl(query); |
| 176 | const presetSearch = isUrl ? "" : query; |
| 177 | |
| 178 | const closeAndReset = useCallback(() => { |
| 179 | setQuery(""); |
| 180 | setError(null); |
| 181 | setDetecting(false); |
| 182 | props.onOpenChange(false); |
| 183 | }, [props]); |
| 184 | |
| 185 | const handleDetect = useCallback(async () => { |
| 186 | const trimmed = query.trim(); |
| 187 | if (!trimmed) return; |
| 188 | setDetecting(true); |
| 189 | setError(null); |
| 190 | // Detection is read-only — it inspects a URL and returns candidates without |
| 191 | // mutating the catalog, so it invalidates nothing. |
| 192 | const exit = await doDetect({ |
| 193 | payload: { url: trimmed }, |
| 194 | reactivityKeys: [], |
| 195 | }); |
| 196 | if (Exit.isFailure(exit)) { |
| 197 | trackEvent("integration_detect_submitted", { success: false }); |
| 198 | setError("Detection failed. Try adding an integration manually."); |
| 199 | setDetecting(false); |
| 200 | return; |
| 201 | } |
| 202 | const results = exit.value; |
| 203 | if (results.length === 0) { |
| 204 | trackEvent("integration_detect_submitted", { success: false }); |
| 205 | setError("Could not detect an integration type from this URL. Try adding manually."); |
| 206 | setDetecting(false); |
| 207 | return; |
| 208 | } |
| 209 | const detected = bestDetection(results); |
| 210 | if (!detected) { |
| 211 | trackEvent("integration_detect_submitted", { success: false }); |
| 212 | setError("Could not detect an integration type from this URL. Try adding manually."); |
| 213 | setDetecting(false); |
| 214 | return; |
| 215 | } |
| 216 | trackEvent("integration_detect_submitted", { |
| 217 | success: true, |
| 218 | detected_kind: detected.kind, |
| 219 | confidence: detected.confidence, |
| 220 | }); |
| 221 | const pluginKey = KIND_TO_PLUGIN_KEY[detected.kind] ?? detected.kind; |
| 222 | if (integrationPlugins.some((p) => p.key === pluginKey)) { |
| 223 | trackEvent("integration_add_started", { plugin_key: pluginKey, via: "detect" }); |
nothing calls this directly
no test coverage detected