History

Merge remote-tracking branch 'origin/codex/effect-lint-graphql-react-ui' into codex/effect-lint-integration

Rhys Sullivan committed 6 months ago

Commit ab4880f2 parents 75ec915 cf3f9372 files · +60 −55Browse files

Unified · Split

2 files
  1. packages/plugins/graphql/src/react/AddGraphqlSource.tsx +30 −28
  2. packages/plugins/graphql/src/react/EditGraphqlSource.tsx +30 −27
packages/plugins/graphql/src/react/AddGraphqlSource.tsx+30−28
@@ -1,5 +1,6 @@
11 import { useCallback, useState } from "react";
22 import { useAtomSet } from "@effect/atom-react";
3+import * as Exit from "effect/Exit";
34
45 import { useScope } from "@executor-js/react/api/scope-context";
56 import { sourceWriteKeys } from "@executor-js/react/api/reactivity-keys";
@@ -55,7 +56,7 @@ export default function AddGraphqlSource(props: { · 49 unmodified lines
5556 const [tokens, setTokens] = useState<OAuthCompletionPayload | null>(null);
5657
5758 const scopeId = useScope();
58− const doAdd = useAtomSet(addGraphqlSource, { mode: "promise" });
59+ const doAdd = useAtomSet(addGraphqlSource, { mode: "promiseExit" });
5960 const { beginAdd } = usePendingSources();
6061 const secretList = useSecretPickerSecrets();
6162 const oauth = useOAuthPopupFlow({
@@ -118,35 +119,36 @@ export default function AddGraphqlSource(props: { · 56 unmodified lines
118119 kind: "graphql",
119120 url: trimmedEndpoint || undefined,
120121 });
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");
146147 setAdding(false);
147− } finally {
148− placeholder.done();
148+ return;
149149 }
150+
151+ props.onComplete();
150152 };
151153
152154 return (
packages/plugins/graphql/src/react/EditGraphqlSource.tsx+30−27
@@ -1,5 +1,6 @@
11 import { useState } from "react";
22 import { useAtomValue, useAtomSet } from "@effect/atom-react";
3+import * as Exit from "effect/Exit";
34 import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
45 import { graphqlSourceAtom, updateGraphqlSource } from "./atoms";
56 import { useScope } from "@executor-js/react/api/scope-context";
@@ -41,7 +42,7 @@ const graphqlOAuthConnectionId = (namespaceSlug: string): string => · 35 unmodified lines
4142
4243 function EditForm(props: { sourceId: string; initial: EditableSource; onSave: () => void }) {
4344 const scopeId = useScope();
44− const doUpdate = useAtomSet(updateGraphqlSource, { mode: "promise" });
45+ const doUpdate = useAtomSet(updateGraphqlSource, { mode: "promiseExit" });
4546 const secretList = useSecretPickerSecrets();
4647
4748 const identity = useSourceIdentity({
@@ -71,34 +72,36 @@ function EditForm(props: { sourceId: string; initial: EditableSource; onSave: () · 23 unmodified lines
7172 setSaving(true);
7273 setError(null);
7374 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");
10098 setSaving(false);
99+ return;
101100 }
101+
102+ setDirty(false);
103+ props.onSave();
104+ setSaving(false);
102105 };
103106
104107 return (