Adding query string output to the URL.

This commit is contained in:
mike12345567 2021-12-02 11:32:21 +00:00
parent a85213f280
commit 0c2e1e9301
2 changed files with 39 additions and 19 deletions

View File

@ -19,8 +19,7 @@
) )
export function addEntry() { export function addEntry() {
console.log(fields) fields = [...fields, { name: "", value: "" }]
fields = [...fields, {}]
changed() changed()
} }

View File

@ -20,11 +20,13 @@
let query let query
let breakQs = {} let breakQs = {}
let url = ""
$: datasource = $datasources.list.find(ds => ds._id === query?.datasourceId) $: datasource = $datasources.list.find(ds => ds._id === query?.datasourceId)
$: datasourceType = datasource?.source $: datasourceType = datasource?.source
$: integrationInfo = $integrations[datasourceType] $: integrationInfo = $integrations[datasourceType]
$: queryConfig = integrationInfo?.query $: queryConfig = integrationInfo?.query
$: url = buildUrl(url, breakQs)
function getSelectedQuery() { function getSelectedQuery() {
return ( return (
@ -41,6 +43,9 @@
if (!qs) { if (!qs) {
return {} return {}
} }
if (qs.includes("?")) {
qs = qs.split("?")[1]
}
const params = qs.split("&") const params = qs.split("&")
let paramObj = {} let paramObj = {}
for (let param of params) { for (let param of params) {
@ -49,31 +54,49 @@
} }
} }
// function buildQueryString(obj) { function buildQueryString(obj) {
// let str = "" let str = ""
// for (let [key, value] of Object.entries(obj)) { for (let [key, value] of Object.entries(obj)) {
// if (str !== "") { if (!key || key === "") {
// str += "&" continue
// } }
// str += `${key}=${value}` if (str !== "") {
// } str += "&"
// return str }
// } str += `${key}=${value || ""}`
}
return str
}
function checkQueryName(queryToCheck, url = null) { function checkQueryName(queryToCheck, inputUrl = null) {
if (queryToCheck && (!queryToCheck.name || queryToCheck.flags.urlName)) { if (queryToCheck && (!queryToCheck.name || queryToCheck.flags.urlName)) {
queryToCheck.flags.urlName = true queryToCheck.flags.urlName = true
queryToCheck.name = url || queryToCheck.fields.path queryToCheck.name = url || inputUrl
} }
} }
function buildUrl(base, qsObj) {
console.log(base)
if (!base) {
return base
}
const qs = buildQueryString(qsObj)
let newUrl = base
if (base.includes("?")) {
newUrl = base.split("?")[0]
}
return qs.length > 0 ? `${newUrl}?${qs}` : newUrl
}
function learnMoreBanner() {} function learnMoreBanner() {}
function saveQuery() {} function saveQuery() {}
onMount(() => { onMount(() => {
query = getSelectedQuery() query = getSelectedQuery()
breakQs = breakQueryString(query?.fields.queryString) const qs = query?.fields.queryString
breakQs = breakQueryString(qs)
url = buildUrl(query.fields.path, qs)
if (query && !query.transformer) { if (query && !query.transformer) {
query.transformer = "return data" query.transformer = "return data"
} }
@ -108,13 +131,11 @@
</div> </div>
<div class="url"> <div class="url">
<Input <Input
bind:value={query.fields.path} bind:value={url}
on:change={({ detail }) => checkQueryName(query, detail)} on:change={({ detail }) => checkQueryName(query, detail)}
/> />
</div> </div>
<Button cta disabled={!query.fields.path} on:click={saveQuery} <Button cta disabled={!url} on:click={saveQuery}>Send</Button>
>Send</Button
>
</div> </div>
<Tabs selected="Params"> <Tabs selected="Params">
<Tab title="Params"> <Tab title="Params">