Updating params in the REST interface so that they can be used in and out of the URL - meaning that updating in one place affects the other. Reduces a bit of the confusing UX around this - discussed in #7683.
This commit is contained in:
parent
c8468c39ea
commit
c61a4df998
|
@ -23,6 +23,7 @@
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
let bindingDrawer
|
let bindingDrawer
|
||||||
let valid = true
|
let valid = true
|
||||||
|
let currentVal = value
|
||||||
|
|
||||||
$: readableValue = runtimeToReadableBinding(bindings, value)
|
$: readableValue = runtimeToReadableBinding(bindings, value)
|
||||||
$: tempValue = readableValue
|
$: tempValue = readableValue
|
||||||
|
@ -30,11 +31,17 @@
|
||||||
|
|
||||||
const saveBinding = () => {
|
const saveBinding = () => {
|
||||||
onChange(tempValue)
|
onChange(tempValue)
|
||||||
|
onBlur()
|
||||||
bindingDrawer.hide()
|
bindingDrawer.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
const onChange = value => {
|
const onChange = value => {
|
||||||
dispatch("change", readableToRuntimeBinding(bindings, value))
|
currentVal = readableToRuntimeBinding(bindings, value)
|
||||||
|
dispatch("change", currentVal)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onBlur = () => {
|
||||||
|
dispatch("blur", currentVal)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -45,6 +52,7 @@
|
||||||
readonly={isJS}
|
readonly={isJS}
|
||||||
value={isJS ? "(JavaScript function)" : readableValue}
|
value={isJS ? "(JavaScript function)" : readableValue}
|
||||||
on:change={event => onChange(event.detail)}
|
on:change={event => onChange(event.detail)}
|
||||||
|
on:blur={onBlur}
|
||||||
{placeholder}
|
{placeholder}
|
||||||
{updateOnChange}
|
{updateOnChange}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -107,7 +107,7 @@
|
||||||
placeholder={keyPlaceholder}
|
placeholder={keyPlaceholder}
|
||||||
readonly={readOnly}
|
readonly={readOnly}
|
||||||
bind:value={field.name}
|
bind:value={field.name}
|
||||||
on:change={changed}
|
on:blur={changed}
|
||||||
/>
|
/>
|
||||||
{#if options}
|
{#if options}
|
||||||
<Select bind:value={field.value} on:change={changed} {options} />
|
<Select bind:value={field.value} on:change={changed} {options} />
|
||||||
|
@ -115,7 +115,10 @@
|
||||||
<DrawerBindableInput
|
<DrawerBindableInput
|
||||||
{bindings}
|
{bindings}
|
||||||
placeholder="Value"
|
placeholder="Value"
|
||||||
on:change={e => (field.value = e.detail)}
|
on:blur={e => {
|
||||||
|
field.value = e.detail
|
||||||
|
changed()
|
||||||
|
}}
|
||||||
disabled={readOnly}
|
disabled={readOnly}
|
||||||
value={field.value}
|
value={field.value}
|
||||||
allowJS={false}
|
allowJS={false}
|
||||||
|
@ -127,7 +130,7 @@
|
||||||
placeholder={valuePlaceholder}
|
placeholder={valuePlaceholder}
|
||||||
readonly={readOnly}
|
readonly={readOnly}
|
||||||
bind:value={field.value}
|
bind:value={field.value}
|
||||||
on:change={changed}
|
on:blur={changed}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{#if toggle}
|
{#if toggle}
|
||||||
|
|
|
@ -28,25 +28,25 @@
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import restUtils from "helpers/data/utils"
|
import restUtils from "helpers/data/utils"
|
||||||
import {
|
import {
|
||||||
RestBodyTypes as bodyTypes,
|
|
||||||
SchemaTypeOptions,
|
|
||||||
PaginationLocations,
|
PaginationLocations,
|
||||||
PaginationTypes,
|
PaginationTypes,
|
||||||
|
RawRestBodyTypes,
|
||||||
|
RestBodyTypes as bodyTypes,
|
||||||
|
SchemaTypeOptions,
|
||||||
} from "constants/backend"
|
} from "constants/backend"
|
||||||
import JSONPreview from "components/integration/JSONPreview.svelte"
|
import JSONPreview from "components/integration/JSONPreview.svelte"
|
||||||
import AccessLevelSelect from "components/integration/AccessLevelSelect.svelte"
|
import AccessLevelSelect from "components/integration/AccessLevelSelect.svelte"
|
||||||
import DynamicVariableModal from "../../_components/DynamicVariableModal.svelte"
|
import DynamicVariableModal from "../../_components/DynamicVariableModal.svelte"
|
||||||
import Placeholder from "assets/bb-spaceship.svg"
|
import Placeholder from "assets/bb-spaceship.svg"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { RawRestBodyTypes } from "constants/backend"
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getRestBindings,
|
getRestBindings,
|
||||||
toBindingsArray,
|
|
||||||
runtimeToReadableBinding,
|
|
||||||
readableToRuntimeBinding,
|
readableToRuntimeBinding,
|
||||||
runtimeToReadableMap,
|
|
||||||
readableToRuntimeMap,
|
readableToRuntimeMap,
|
||||||
|
runtimeToReadableBinding,
|
||||||
|
runtimeToReadableMap,
|
||||||
|
toBindingsArray,
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
|
|
||||||
let query, datasource
|
let query, datasource
|
||||||
|
@ -95,7 +95,7 @@
|
||||||
$: runtimeUrlQueries = readableToRuntimeMap(mergedBindings, breakQs)
|
$: runtimeUrlQueries = readableToRuntimeMap(mergedBindings, breakQs)
|
||||||
|
|
||||||
function getSelectedQuery() {
|
function getSelectedQuery() {
|
||||||
const cloneQuery = cloneDeep(
|
return cloneDeep(
|
||||||
$queries.list.find(q => q._id === $queries.selected) || {
|
$queries.list.find(q => q._id === $queries.selected) || {
|
||||||
datasourceId: $params.selectedDatasource,
|
datasourceId: $params.selectedDatasource,
|
||||||
parameters: [],
|
parameters: [],
|
||||||
|
@ -107,7 +107,6 @@
|
||||||
queryVerb: "read",
|
queryVerb: "read",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return cloneQuery
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkQueryName(inputUrl = null) {
|
function checkQueryName(inputUrl = null) {
|
||||||
|
@ -121,14 +120,15 @@
|
||||||
if (!base) {
|
if (!base) {
|
||||||
return base
|
return base
|
||||||
}
|
}
|
||||||
const qs = restUtils.buildQueryString(
|
let qs = restUtils.buildQueryString(
|
||||||
runtimeToReadableMap(mergedBindings, qsObj)
|
runtimeToReadableMap(mergedBindings, qsObj)
|
||||||
)
|
)
|
||||||
let newUrl = base
|
let newUrl = base
|
||||||
if (base.includes("?")) {
|
if (base.includes("?")) {
|
||||||
newUrl = base.split("?")[0]
|
const split = base.split("?")
|
||||||
|
newUrl = split[0]
|
||||||
}
|
}
|
||||||
return qs.length > 0 ? `${newUrl}?${qs}` : newUrl
|
return qs.length === 0 ? newUrl : `${newUrl}?${qs}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildQuery() {
|
function buildQuery() {
|
||||||
|
@ -314,6 +314,27 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: console.log(breakQs)
|
||||||
|
|
||||||
|
const paramsChanged = evt => {
|
||||||
|
breakQs = {}
|
||||||
|
for (let param of evt.detail) {
|
||||||
|
breakQs[param.name] = param.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlChanged = evt => {
|
||||||
|
breakQs = {}
|
||||||
|
const qs = evt.target.value.split("?")[1]
|
||||||
|
if (qs && qs.length > 0) {
|
||||||
|
const parts = qs.split("&")
|
||||||
|
for (let part of parts) {
|
||||||
|
const [key, value] = part.split("=")
|
||||||
|
breakQs[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
query = getSelectedQuery()
|
query = getSelectedQuery()
|
||||||
|
|
||||||
|
@ -426,7 +447,11 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="url">
|
<div class="url">
|
||||||
<Input bind:value={url} placeholder="http://www.api.com/endpoint" />
|
<Input
|
||||||
|
on:blur={urlChanged}
|
||||||
|
bind:value={url}
|
||||||
|
placeholder="http://www.api.com/endpoint"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Button primary disabled={!url} on:click={runQuery}>Send</Button>
|
<Button primary disabled={!url} on:click={runQuery}>Send</Button>
|
||||||
<Button
|
<Button
|
||||||
|
@ -456,13 +481,16 @@
|
||||||
/>
|
/>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab title="Params">
|
<Tab title="Params">
|
||||||
|
{#key breakQs}
|
||||||
<KeyValueBuilder
|
<KeyValueBuilder
|
||||||
bind:object={breakQs}
|
on:change={paramsChanged}
|
||||||
|
object={breakQs}
|
||||||
name="param"
|
name="param"
|
||||||
headings
|
headings
|
||||||
bindings={mergedBindings}
|
bindings={mergedBindings}
|
||||||
bindingDrawerLeft="260px"
|
bindingDrawerLeft="260px"
|
||||||
/>
|
/>
|
||||||
|
{/key}
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab title="Headers">
|
<Tab title="Headers">
|
||||||
<KeyValueBuilder
|
<KeyValueBuilder
|
||||||
|
|
Loading…
Reference in New Issue