@@ -199,17 +199,70 @@ export const QueryLibraryEditor = () => {
199199const newName = nameGenerator . genItemName ( trans ( "queryLibrary.unnamed" ) ) ;
200200
201201const handleAdd = ( type :BottomResTypeEnum , extraInfo ?:any ) => {
202+ // Build basic query DSL
203+ let queryDSL :any = {
204+ triggerType :"manual" ,
205+ datasourceId :extraInfo ?. dataSourceId ,
206+ compType :extraInfo ?. compType ,
207+ } ;
208+
209+ // If it is a REST API created from cURL, pre-populate the HTTP query fields
210+ if ( extraInfo ?. compType === "restApi" && extraInfo ?. curlData ) {
211+ const curlData = extraInfo . curlData ;
212+
213+ const rawHeaders :Record < string , any > | undefined =
214+ curlData . header || curlData . headers ;
215+ const rawParams :Record < string , any > | undefined =
216+ curlData . params || curlData . parameters || curlData . query ;
217+
218+ const headersArr = rawHeaders
219+ ?Object . entries ( rawHeaders ) . map ( ( [ key , value ] ) => ( { key, value} ) )
220+ :[ { key :"" , value :"" } ] ;
221+
222+ const paramsArr = rawParams
223+ ?Object . entries ( rawParams ) . map ( ( [ key , value ] ) => ( { key, value} ) )
224+ :[ { key :"" , value :"" } ] ;
225+
226+ const bodyContent :any =
227+ curlData . body ?? curlData . data ?? curlData . postData ?? undefined ;
228+
229+ let bodyType :string = "none" ;
230+ if ( bodyContent !== undefined && bodyContent !== "" ) {
231+ const contentTypeHeader =
232+ ( rawHeaders && ( rawHeaders [ "Content-Type" ] || rawHeaders [ "content-type" ] ) ) || "" ;
233+ if ( contentTypeHeader ) {
234+ bodyType = contentTypeHeader ;
235+ } else if ( typeof bodyContent === "object" ) {
236+ bodyType = "application/json" ;
237+ } else {
238+ bodyType = "text/plain" ;
239+ }
240+ }
241+
242+ queryDSL = {
243+ ...queryDSL ,
244+ comp :{
245+ httpMethod :curlData . method || "GET" ,
246+ path :curlData . url || curlData . path || "" ,
247+ headers :headersArr ,
248+ params :paramsArr ,
249+ bodyType :bodyType ,
250+ body :
251+ typeof bodyContent === "object"
252+ ?JSON . stringify ( bodyContent , null , 2 )
253+ :bodyContent || "" ,
254+ bodyFormData :[ { key :"" , value :"" , type :"text" } ] ,
255+ } ,
256+ } ;
257+ }
258+
202259dispatch (
203260createQueryLibrary (
204261{
205262name :newName ,
206263organizationId :orgId ,
207264libraryQueryDSL :{
208- query :{
209- triggerType :"manual" ,
210- datasourceId :extraInfo ?. dataSourceId ,
211- compType :extraInfo ?. compType ,
212- } ,
265+ query :queryDSL ,
213266} ,
214267} ,
215268( resp ) => {
@@ -218,7 +271,6 @@ export const QueryLibraryEditor = () => {
218271setModify ( ! modify ) ;
219272} , 200 ) ;
220273setCurrentPage ( Math . ceil ( elements . total / pageSize ) ) ;
221-
222274} ,
223275( ) => { }
224276)