fix dynamic params

This commit is contained in:
Martin McKeaveney 2021-01-18 15:37:32 +00:00
parent 53db6e05f9
commit 133d93fbee
7 changed files with 36 additions and 33 deletions

View File

@ -139,10 +139,10 @@ export const getBackendUiStore = () => {
})
return json
},
select: queryId =>
select: query =>
store.update(state => {
state.selectedDatasourceId = null
state.selectedQueryId = queryId
state.selectedDatasourceId = query.datasourceId
state.selectedQueryId = query._id
return state
}),
delete: async query => {

View File

@ -18,13 +18,12 @@
$goto(`./datasource/${datasource._id}`)
}
function onClickQuery(datasourceId, queryId) {
if ($backendUiStore.selectedQueryId === queryId) {
function onClickQuery(query) {
if ($backendUiStore.selectedQueryId === query._id) {
return
}
backendUiStore.actions.datasources.select(datasourceId)
backendUiStore.actions.queries.select(queryId)
$goto(`./datasource/${datasourceId}/${queryId}`)
backendUiStore.actions.queries.select(query)
$goto(`./datasource/${query.datasourceId}/${query._id}`)
}
onMount(() => {
@ -55,7 +54,7 @@
icon="ri-eye-line"
text={query.name}
selected={$backendUiStore.selectedQueryId === query._id}
on:click={() => onClickQuery(datasource._id, query._id)}>
on:click={() => onClickQuery(query)}>
<EditQueryPopover {query} />
</NavItem>
{/each}

View File

@ -29,22 +29,24 @@
<Spacer medium />
{#if schema}
{#if schema.type === QueryTypes.SQL}
<Editor
label="Query"
mode="sql"
on:change={updateQuery}
readOnly={!editable}
value={query.fields.sql} />
{:else if schema.type === QueryTypes.JSON}
<Spacer large />
<Editor
label="Query"
mode="json"
on:change={updateQuery}
readOnly={!editable}
value={query.fields.json} />
{:else if schema.type === QueryTypes.FIELDS}
<FieldsBuilder bind:fields={query.fields} {schema} {editable} />
{/if}
{#key query._id}
{#if schema.type === QueryTypes.SQL}
<Editor
label="Query"
mode="sql"
on:change={updateQuery}
readOnly={!editable}
value={query.fields.sql} />
{:else if schema.type === QueryTypes.JSON}
<Spacer large />
<Editor
label="Query"
mode="json"
on:change={updateQuery}
readOnly={!editable}
value={query.fields.json} />
{:else if schema.type === QueryTypes.FIELDS}
<FieldsBuilder bind:fields={query.fields} {schema} {editable} />
{/if}
{/key}
{/if}

View File

@ -51,7 +51,7 @@
<Spacer medium />
{#if query?.parameters.length > 0}
{#if query?.parameters?.length > 0}
<ParameterBuilder
bind:customParams={parameters.queryParams}
parameters={query.parameters}

View File

@ -9,17 +9,19 @@
export let multiselect = false
const tables = $backendUiStore.tables
const queries = $backendUiStore.queries
let options = []
$: table = componentInstance.datasource
$: table = componentInstance.datasource?.type === "table"
? tables.find(m => m._id === componentInstance.datasource.tableId)
: null
: queries.find(query => query._id === componentInstance.datasource._id)
$: type = componentInstance.datasource.type
$: if (table) {
options =
type === "table" || type === "link"
type === "table" || type === "link" || type === "query"
? Object.keys(table.schema)
: Object.keys(table.views[componentInstance.datasource.name].schema)
}

View File

@ -122,7 +122,7 @@
{#if value.parameters.length > 0}
<ParameterBuilder
bind:customParams={value.queryParams}
parameters={value.parameters}
parameters={queries.find(query => query._id === value._id).parameters}
bindings={queryBindableProperties} />
{/if}
</div>

View File

@ -25,7 +25,7 @@ export const fetchDatasource = async (datasource, dataContext) => {
} else if (type === "query") {
const bindings = get(bindingStore)
// TODO: refactor. Set these defaults up somewhere else
// Set the default query params
let queryParams = datasource.queryParams || {}
for (let param of datasource.parameters) {
if (!queryParams[param.name]) {