Content-Length: 404671 | pFad | http://github.com/lowcoder-org/lowcoder/commit/d8560aadde128f0d2c5b1693bf302efaa2603f43

1D add global query library curl · lowcoder-org/lowcoder@d8560aa · GitHub
Skip to content

Commit d8560aa

Browse files
committed
add global query library curl
1 parent 1e0295f commit d8560aa

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

client/packages/lowcoder/src/pages/queryLibrary/QueryLibraryEditor.tsx

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,70 @@ export const QueryLibraryEditor = () => {
199199
const newName = nameGenerator.genItemName(trans("queryLibrary.unnamed"));
200200

201201
const 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+
202259
dispatch(
203260
createQueryLibrary(
204261
{
205262
name: newName,
206263
organizationId: orgId,
207264
libraryQueryDSL: {
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 = () => {
218271
setModify(!modify);
219272
}, 200);
220273
setCurrentPage(Math.ceil(elements.total / pageSize));
221-
222274
},
223275
() => {}
224276
)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/lowcoder-org/lowcoder/commit/d8560aadde128f0d2c5b1693bf302efaa2603f43

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy