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 return json
}, },
select: queryId => select: query =>
store.update(state => { store.update(state => {
state.selectedDatasourceId = null state.selectedDatasourceId = query.datasourceId
state.selectedQueryId = queryId state.selectedQueryId = query._id
return state return state
}), }),
delete: async query => { delete: async query => {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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