@@ -71,10 +71,12 @@ import { parseCurl, type CurlRequest } from "./curl";
7171
7272export const parseResource = ( {
7373 id,
74+ control,
7475 name,
7576 formData,
7677} : {
7778 id : string ;
79+ control ?: string ;
7880 name ?: string ;
7981 formData : FormData ;
8082} ) => {
@@ -84,6 +86,7 @@ export const parseResource = ({
8486 const headerValues = formData . getAll ( "header-value" ) as string [ ] ;
8587 return Resource . parse ( {
8688 id,
89+ control,
8790 name : name ?? formData . get ( "name" ) ,
8891 url : formData . get ( "url" ) ,
8992 searchParams : searchParamNames
@@ -250,7 +253,7 @@ const SearchParamPair = ({
250253} ) => {
251254 const evaluatedValue = evaluateExpressionWithinScope ( value , scope ) ;
252255 // expressions with variables or objects cannot be edited from input
253- const isValueUnbound =
256+ const isValueUnboundString =
254257 isLiteralExpression ( value ) && typeof evaluatedValue === "string" ;
255258 return (
256259 < Grid
@@ -271,7 +274,7 @@ const SearchParamPair = ({
271274 < InputField
272275 placeholder = "Value"
273276 name = "search-param-value-literal"
274- disabled = { ! isValueUnbound }
277+ disabled = { ! isValueUnboundString }
275278 value = { serializeValue ( evaluatedValue ) }
276279 // update text value as string literal
277280 onChange = { ( event ) =>
@@ -281,7 +284,7 @@ const SearchParamPair = ({
281284 < BindingPopover
282285 scope = { scope }
283286 aliases = { aliases }
284- variant = { isValueUnbound ? "default" : "bound" }
287+ variant = { isLiteralExpression ( value ) ? "default" : "bound" }
285288 value = { value }
286289 onChange = { ( newValue ) => onChange ( name , newValue ) }
287290 onRemove = { ( evaluatedValue ) =>
@@ -374,7 +377,7 @@ const HeaderPair = ({
374377} ) => {
375378 const evaluatedValue = evaluateExpressionWithinScope ( value , scope ) ;
376379 // expressions with variables or objects cannot be edited from input
377- const isValueUnbound =
380+ const isValueUnboundString =
378381 isLiteralExpression ( value ) && typeof evaluatedValue === "string" ;
379382 return (
380383 < Grid
@@ -395,7 +398,7 @@ const HeaderPair = ({
395398 < InputField
396399 placeholder = "Value"
397400 name = "header-value-validator"
398- disabled = { ! isValueUnbound }
401+ disabled = { ! isValueUnboundString }
399402 value = { serializeValue ( evaluatedValue ) }
400403 // update text value as string literal
401404 onChange = { ( event ) =>
@@ -405,7 +408,7 @@ const HeaderPair = ({
405408 < BindingPopover
406409 scope = { scope }
407410 aliases = { aliases }
408- variant = { isValueUnbound ? "default" : "bound" }
411+ variant = { isLiteralExpression ( value ) ? "default" : "bound" }
409412 value = { value }
410413 onChange = { ( newValue ) => onChange ( name , newValue ) }
411414 onRemove = { ( evaluatedValue ) =>
@@ -980,8 +983,6 @@ export const SystemResourceForm = forwardRef<
980983 ? resources . get ( variable . resourceId )
981984 : undefined ;
982985
983- const method = "get" ;
984-
985986 const localResources = [
986987 {
987988 label : "Sitemap" ,
@@ -1006,19 +1007,15 @@ export const SystemResourceForm = forwardRef<
10061007 if ( scopeInstanceId === undefined ) {
10071008 return ;
10081009 }
1009- const name = z . string ( ) . parse ( formData . get ( "name" ) ) ;
1010- const newResource : Resource = {
1010+ const newResource : Resource = parseResource ( {
10111011 id : resource ?. id ?? nanoid ( ) ,
1012- name,
10131012 control : "system" ,
1014- url : localResource . value ,
1015- method,
1016- headers : [ ] ,
1017- } ;
1013+ formData,
1014+ } ) ;
10181015 const newVariable : DataSource = {
10191016 id : variable ?. id ?? nanoid ( ) ,
10201017 scopeInstanceId,
1021- name,
1018+ name : newResource . name ,
10221019 type : "resource" ,
10231020 resourceId : newResource . id ,
10241021 } ;
@@ -1037,6 +1034,8 @@ export const SystemResourceForm = forwardRef<
10371034
10381035 return (
10391036 < >
1037+ < input type = "hidden" name = "method" value = "get" />
1038+ < input type = "hidden" name = "url" value = { localResource . value } />
10401039 < Flex direction = "column" css = { { gap : theme . spacing [ 3 ] } } >
10411040 < Label htmlFor = { resourceId } > Resource</ Label >
10421041 < Select
@@ -1116,28 +1115,15 @@ export const GraphqlResourceForm = forwardRef<
11161115 if ( scopeInstanceId === undefined ) {
11171116 return ;
11181117 }
1119- const name = z . string ( ) . parse ( formData . get ( "name" ) ) ;
1120- const body = generateObjectExpression (
1121- new Map ( [
1122- [ "query" , JSON . stringify ( query ) ] ,
1123- [ "variables" , variables ] ,
1124- ] )
1125- ) ;
1126- const newResource : Resource = {
1118+ const newResource = parseResource ( {
11271119 id : resource ?. id ?? nanoid ( ) ,
1128- name,
11291120 control : "graphql" ,
1130- url,
1131- method : "post" ,
1132- headers : headers . some ( ( { name } ) => isContentType ( name ) )
1133- ? headers
1134- : [ ...headers , { name : "Content-Type" , value : `"application/json"` } ] ,
1135- body,
1136- } ;
1121+ formData,
1122+ } ) ;
11371123 const newVariable : DataSource = {
11381124 id : variable ?. id ?? nanoid ( ) ,
11391125 scopeInstanceId,
1140- name,
1126+ name : newResource . name ,
11411127 type : "resource" ,
11421128 resourceId : newResource . id ,
11431129 } ;
@@ -1154,6 +1140,28 @@ export const GraphqlResourceForm = forwardRef<
11541140
11551141 return (
11561142 < >
1143+ < input type = "hidden" name = "method" value = "post" />
1144+ { ! headers . some ( ( { name } ) => isContentType ( name ) ) && (
1145+ < >
1146+ < input type = "hidden" name = "header-name" value = "Content-Type" />
1147+ < input
1148+ type = "hidden"
1149+ name = "header-value"
1150+ value = { `"application/json"` }
1151+ />
1152+ </ >
1153+ ) }
1154+ < input
1155+ type = "hidden"
1156+ name = "body"
1157+ value = { generateObjectExpression (
1158+ new Map ( [
1159+ [ "query" , JSON . stringify ( query ) ] ,
1160+ [ "variables" , variables ] ,
1161+ ] )
1162+ ) }
1163+ />
1164+
11571165 < UrlField
11581166 scope = { scope }
11591167 aliases = { aliases }
@@ -1177,7 +1185,6 @@ export const GraphqlResourceForm = forwardRef<
11771185 }
11781186 } }
11791187 />
1180- < input type = "hidden" name = "method" value = "post" />
11811188
11821189 < Grid gap = { 1 } >
11831190 < Label htmlFor = { queryId } > Query</ Label >
0 commit comments