@@ -71,10 +71,12 @@ import { parseCurl, type CurlRequest } from "./curl";
71
71
72
72
export const parseResource = ( {
73
73
id,
74
+ control,
74
75
name,
75
76
formData,
76
77
} : {
77
78
id : string ;
79
+ control ?: string ;
78
80
name ?: string ;
79
81
formData : FormData ;
80
82
} ) => {
@@ -84,6 +86,7 @@ export const parseResource = ({
84
86
const headerValues = formData . getAll ( "header-value" ) as string [ ] ;
85
87
return Resource . parse ( {
86
88
id,
89
+ control,
87
90
name : name ?? formData . get ( "name" ) ,
88
91
url : formData . get ( "url" ) ,
89
92
searchParams : searchParamNames
@@ -250,7 +253,7 @@ const SearchParamPair = ({
250
253
} ) => {
251
254
const evaluatedValue = evaluateExpressionWithinScope ( value , scope ) ;
252
255
// expressions with variables or objects cannot be edited from input
253
- const isValueUnbound =
256
+ const isValueUnboundString =
254
257
isLiteralExpression ( value ) && typeof evaluatedValue === "string" ;
255
258
return (
256
259
< Grid
@@ -271,7 +274,7 @@ const SearchParamPair = ({
271
274
< InputField
272
275
placeholder = "Value"
273
276
name = "search-param-value-literal"
274
- disabled = { ! isValueUnbound }
277
+ disabled = { ! isValueUnboundString }
275
278
value = { serializeValue ( evaluatedValue ) }
276
279
// update text value as string literal
277
280
onChange = { ( event ) =>
@@ -281,7 +284,7 @@ const SearchParamPair = ({
281
284
< BindingPopover
282
285
scope = { scope }
283
286
aliases = { aliases }
284
- variant = { isValueUnbound ? "default" : "bound" }
287
+ variant = { isLiteralExpression ( value ) ? "default" : "bound" }
285
288
value = { value }
286
289
onChange = { ( newValue ) => onChange ( name , newValue ) }
287
290
onRemove = { ( evaluatedValue ) =>
@@ -374,7 +377,7 @@ const HeaderPair = ({
374
377
} ) => {
375
378
const evaluatedValue = evaluateExpressionWithinScope ( value , scope ) ;
376
379
// expressions with variables or objects cannot be edited from input
377
- const isValueUnbound =
380
+ const isValueUnboundString =
378
381
isLiteralExpression ( value ) && typeof evaluatedValue === "string" ;
379
382
return (
380
383
< Grid
@@ -395,7 +398,7 @@ const HeaderPair = ({
395
398
< InputField
396
399
placeholder = "Value"
397
400
name = "header-value-validator"
398
- disabled = { ! isValueUnbound }
401
+ disabled = { ! isValueUnboundString }
399
402
value = { serializeValue ( evaluatedValue ) }
400
403
// update text value as string literal
401
404
onChange = { ( event ) =>
@@ -405,7 +408,7 @@ const HeaderPair = ({
405
408
< BindingPopover
406
409
scope = { scope }
407
410
aliases = { aliases }
408
- variant = { isValueUnbound ? "default" : "bound" }
411
+ variant = { isLiteralExpression ( value ) ? "default" : "bound" }
409
412
value = { value }
410
413
onChange = { ( newValue ) => onChange ( name , newValue ) }
411
414
onRemove = { ( evaluatedValue ) =>
@@ -980,8 +983,6 @@ export const SystemResourceForm = forwardRef<
980
983
? resources . get ( variable . resourceId )
981
984
: undefined ;
982
985
983
- const method = "get" ;
984
-
985
986
const localResources = [
986
987
{
987
988
label : "Sitemap" ,
@@ -1006,19 +1007,15 @@ export const SystemResourceForm = forwardRef<
1006
1007
if ( scopeInstanceId === undefined ) {
1007
1008
return ;
1008
1009
}
1009
- const name = z . string ( ) . parse ( formData . get ( "name" ) ) ;
1010
- const newResource : Resource = {
1010
+ const newResource : Resource = parseResource ( {
1011
1011
id : resource ?. id ?? nanoid ( ) ,
1012
- name,
1013
1012
control : "system" ,
1014
- url : localResource . value ,
1015
- method,
1016
- headers : [ ] ,
1017
- } ;
1013
+ formData,
1014
+ } ) ;
1018
1015
const newVariable : DataSource = {
1019
1016
id : variable ?. id ?? nanoid ( ) ,
1020
1017
scopeInstanceId,
1021
- name,
1018
+ name : newResource . name ,
1022
1019
type : "resource" ,
1023
1020
resourceId : newResource . id ,
1024
1021
} ;
@@ -1037,6 +1034,8 @@ export const SystemResourceForm = forwardRef<
1037
1034
1038
1035
return (
1039
1036
< >
1037
+ < input type = "hidden" name = "method" value = "get" />
1038
+ < input type = "hidden" name = "url" value = { localResource . value } />
1040
1039
< Flex direction = "column" css = { { gap : theme . spacing [ 3 ] } } >
1041
1040
< Label htmlFor = { resourceId } > Resource</ Label >
1042
1041
< Select
@@ -1116,28 +1115,15 @@ export const GraphqlResourceForm = forwardRef<
1116
1115
if ( scopeInstanceId === undefined ) {
1117
1116
return ;
1118
1117
}
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 ( {
1127
1119
id : resource ?. id ?? nanoid ( ) ,
1128
- name,
1129
1120
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
+ } ) ;
1137
1123
const newVariable : DataSource = {
1138
1124
id : variable ?. id ?? nanoid ( ) ,
1139
1125
scopeInstanceId,
1140
- name,
1126
+ name : newResource . name ,
1141
1127
type : "resource" ,
1142
1128
resourceId : newResource . id ,
1143
1129
} ;
@@ -1154,6 +1140,28 @@ export const GraphqlResourceForm = forwardRef<
1154
1140
1155
1141
return (
1156
1142
< >
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
+
1157
1165
< UrlField
1158
1166
scope = { scope }
1159
1167
aliases = { aliases }
@@ -1177,7 +1185,6 @@ export const GraphqlResourceForm = forwardRef<
1177
1185
}
1178
1186
} }
1179
1187
/>
1180
- < input type = "hidden" name = "method" value = "post" />
1181
1188
1182
1189
< Grid gap = { 1 } >
1183
1190
< Label htmlFor = { queryId } > Query</ Label >
0 commit comments