Unified · Split
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import { useCallback, useState } from "react"; |
| 2 | 2 | import { useAtomSet } from "@effect/atom-react"; |
| 3 | +import * as Exit from "effect/Exit"; | |
| 3 | 4 | |
| 4 | 5 | import { useScope } from "@executor-js/react/api/scope-context"; |
| 5 | 6 | import { sourceWriteKeys } from "@executor-js/react/api/reactivity-keys"; |
| @@ -55,7 +56,7 @@ export default function AddGraphqlSource(props: { · 49 unmodified lines | ||
| 55 | 56 | const [tokens, setTokens] = useState<OAuthCompletionPayload | null>(null); |
| 56 | 57 | |
| 57 | 58 | const scopeId = useScope(); |
| 58 | − const doAdd = useAtomSet(addGraphqlSource, { mode: "promise" }); | |
| 59 | + const doAdd = useAtomSet(addGraphqlSource, { mode: "promiseExit" }); | |
| 59 | 60 | const { beginAdd } = usePendingSources(); |
| 60 | 61 | const secretList = useSecretPickerSecrets(); |
| 61 | 62 | const oauth = useOAuthPopupFlow({ |
| @@ -118,35 +119,36 @@ export default function AddGraphqlSource(props: { · 56 unmodified lines | ||
| 118 | 119 | kind: "graphql", |
| 119 | 120 | url: trimmedEndpoint || undefined, |
| 120 | 121 | }); |
| 121 | − try { | |
| 122 | − await doAdd({ | |
| 123 | − params: { scopeId }, | |
| 124 | − payload: { | |
| 125 | − endpoint: trimmedEndpoint, | |
| 126 | − name: identity.name.trim() || undefined, | |
| 127 | − namespace: slugifyNamespace(identity.namespace) || undefined, | |
| 128 | − ...(Object.keys(headerMap).length > 0 ? { headers: headerMap } : {}), | |
| 129 | − ...(Object.keys(queryParams).length > 0 | |
| 130 | − ? { queryParams: queryParams as Record<string, HeaderValue> } | |
| 131 | − : {}), | |
| 132 | − ...(authMode === "oauth2" && tokens | |
| 133 | − ? { | |
| 134 | − auth: { | |
| 135 | − kind: "oauth2" as const, | |
| 136 | − connectionId: tokens.connectionId, | |
| 137 | − }, | |
| 138 | − } | |
| 139 | − : {}), | |
| 140 | − }, | |
| 141 | − reactivityKeys: sourceWriteKeys, | |
| 142 | − }); | |
| 143 | − props.onComplete(); | |
| 144 | − } catch (e) { | |
| 145 | − setAddError(e instanceof Error ? e.message : "Failed to add source"); | |
| 122 | + const exit = await doAdd({ | |
| 123 | + params: { scopeId }, | |
| 124 | + payload: { | |
| 125 | + endpoint: trimmedEndpoint, | |
| 126 | + name: identity.name.trim() || undefined, | |
| 127 | + namespace: slugifyNamespace(identity.namespace) || undefined, | |
| 128 | + ...(Object.keys(headerMap).length > 0 ? { headers: headerMap } : {}), | |
| 129 | + ...(Object.keys(queryParams).length > 0 | |
| 130 | + ? { queryParams: queryParams as Record<string, HeaderValue> } | |
| 131 | + : {}), | |
| 132 | + ...(authMode === "oauth2" && tokens | |
| 133 | + ? { | |
| 134 | + auth: { | |
| 135 | + kind: "oauth2" as const, | |
| 136 | + connectionId: tokens.connectionId, | |
| 137 | + }, | |
| 138 | + } | |
| 139 | + : {}), | |
| 140 | + }, | |
| 141 | + reactivityKeys: sourceWriteKeys, | |
| 142 | + }); | |
| 143 | + placeholder.done(); | |
| 144 | + | |
| 145 | + if (Exit.isFailure(exit)) { | |
| 146 | + setAddError("Failed to add source"); | |
| 146 | 147 | setAdding(false); |
| 147 | − } finally { | |
| 148 | − placeholder.done(); | |
| 148 | + return; | |
| 149 | 149 | } |
| 150 | + | |
| 151 | + props.onComplete(); | |
| 150 | 152 | }; |
| 151 | 153 | |
| 152 | 154 | return ( |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import { useState } from "react"; |
| 2 | 2 | import { useAtomValue, useAtomSet } from "@effect/atom-react"; |
| 3 | +import * as Exit from "effect/Exit"; | |
| 3 | 4 | import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"; |
| 4 | 5 | import { graphqlSourceAtom, updateGraphqlSource } from "./atoms"; |
| 5 | 6 | import { useScope } from "@executor-js/react/api/scope-context"; |
| @@ -41,7 +42,7 @@ const graphqlOAuthConnectionId = (namespaceSlug: string): string => · 35 unmodified lines | ||
| 41 | 42 | |
| 42 | 43 | function EditForm(props: { sourceId: string; initial: EditableSource; onSave: () => void }) { |
| 43 | 44 | const scopeId = useScope(); |
| 44 | − const doUpdate = useAtomSet(updateGraphqlSource, { mode: "promise" }); | |
| 45 | + const doUpdate = useAtomSet(updateGraphqlSource, { mode: "promiseExit" }); | |
| 45 | 46 | const secretList = useSecretPickerSecrets(); |
| 46 | 47 | |
| 47 | 48 | const identity = useSourceIdentity({ |
| @@ -71,34 +72,36 @@ function EditForm(props: { sourceId: string; initial: EditableSource; onSave: () · 23 unmodified lines | ||
| 71 | 72 | setSaving(true); |
| 72 | 73 | setError(null); |
| 73 | 74 | const { headers, queryParams } = serializeHttpCredentials(credentials); |
| 74 | − try { | |
| 75 | − await doUpdate({ | |
| 76 | − params: { scopeId, namespace: props.sourceId }, | |
| 77 | − payload: { | |
| 78 | − name: identity.name.trim() || undefined, | |
| 79 | − endpoint: endpoint.trim() || undefined, | |
| 80 | − headers, | |
| 81 | − queryParams: queryParams as Record<string, HeaderValue>, | |
| 82 | − auth: | |
| 83 | − authMode === "oauth2" | |
| 84 | − ? { | |
| 85 | − kind: "oauth2", | |
| 86 | − connectionId: | |
| 87 | − props.initial.auth.kind === "oauth2" | |
| 88 | − ? props.initial.auth.connectionId | |
| 89 | − : graphqlOAuthConnectionId(props.initial.namespace), | |
| 90 | − } | |
| 91 | − : { kind: "none" }, | |
| 92 | − }, | |
| 93 | − reactivityKeys: sourceWriteKeys, | |
| 94 | − }); | |
| 95 | − setDirty(false); | |
| 96 | − props.onSave(); | |
| 97 | − } catch (e) { | |
| 98 | − setError(e instanceof Error ? e.message : "Failed to update source"); | |
| 99 | − } finally { | |
| 75 | + const exit = await doUpdate({ | |
| 76 | + params: { scopeId, namespace: props.sourceId }, | |
| 77 | + payload: { | |
| 78 | + name: identity.name.trim() || undefined, | |
| 79 | + endpoint: endpoint.trim() || undefined, | |
| 80 | + headers, | |
| 81 | + queryParams: queryParams as Record<string, HeaderValue>, | |
| 82 | + auth: | |
| 83 | + authMode === "oauth2" | |
| 84 | + ? { | |
| 85 | + kind: "oauth2", | |
| 86 | + connectionId: | |
| 87 | + props.initial.auth.kind === "oauth2" | |
| 88 | + ? props.initial.auth.connectionId | |
| 89 | + : graphqlOAuthConnectionId(props.initial.namespace), | |
| 90 | + } | |
| 91 | + : { kind: "none" }, | |
| 92 | + }, | |
| 93 | + reactivityKeys: sourceWriteKeys, | |
| 94 | + }); | |
| 95 | + | |
| 96 | + if (Exit.isFailure(exit)) { | |
| 97 | + setError("Failed to update source"); | |
| 100 | 98 | setSaving(false); |
| 99 | + return; | |
| 101 | 100 | } |
| 101 | + | |
| 102 | + setDirty(false); | |
| 103 | + props.onSave(); | |
| 104 | + setSaving(false); | |
| 102 | 105 | }; |
| 103 | 106 | |
| 104 | 107 | return ( |