Fixing some issues around deleting datasources/queries and managing the full URL for migrating queries.

This commit is contained in:
mike12345567 2021-12-13 12:41:47 +00:00
parent a7743c8481
commit 1948c867cc
4 changed files with 25 additions and 5 deletions

View File

@ -1,6 +1,6 @@
<script> <script>
import { goto } from "@roxi/routify" import { goto } from "@roxi/routify"
import { datasources, tables } from "stores/backend" import { datasources, queries, tables } from "stores/backend"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
import { ActionMenu, MenuItem, Icon } from "@budibase/bbui" import { ActionMenu, MenuItem, Icon } from "@budibase/bbui"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
@ -12,7 +12,13 @@
let updateDatasourceDialog let updateDatasourceDialog
async function deleteDatasource() { async function deleteDatasource() {
const wasSelectedSource = $datasources.selected let wasSelectedSource = $datasources.selected
if (!wasSelectedSource && $queries.selected) {
const queryId = $queries.selected
wasSelectedSource = $datasources.list.find(ds =>
queryId.includes(ds._id)
)?._id
}
const wasSelectedTable = $tables.selected const wasSelectedTable = $tables.selected
await datasources.delete(datasource) await datasources.delete(datasource)
notifications.success("Datasource deleted") notifications.success("Datasource deleted")

View File

@ -1,14 +1,20 @@
<script> <script>
import { goto } from "@roxi/routify"
import { ActionMenu, MenuItem, Icon, notifications } from "@budibase/bbui" import { ActionMenu, MenuItem, Icon, notifications } from "@budibase/bbui"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { queries } from "stores/backend" import { datasources, queries } from "stores/backend"
export let query export let query
let confirmDeleteDialog let confirmDeleteDialog
async function deleteQuery() { async function deleteQuery() {
const wasSelectedQuery = $queries.selected
const selectedDatasource = $datasources.selected
await queries.delete(query) await queries.delete(query)
if (wasSelectedQuery === query._id) {
$goto(`./datasource/${selectedDatasource}`)
}
notifications.success("Query deleted") notifications.success("Query deleted")
} }

View File

@ -52,7 +52,6 @@
let response, schema, enabledHeaders let response, schema, enabledHeaders
let datasourceType, integrationInfo, queryConfig, responseSuccess let datasourceType, integrationInfo, queryConfig, responseSuccess
$: 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
@ -135,8 +134,14 @@
onMount(() => { onMount(() => {
query = getSelectedQuery() query = getSelectedQuery()
datasource = $datasources.list.find(ds => ds._id === query?.datasourceId)
const datasourceUrl = datasource?.config.url
const qs = query?.fields.queryString const qs = query?.fields.queryString
breakQs = breakQueryString(qs) breakQs = breakQueryString(qs)
if (datasourceUrl && !query.fields.path?.startsWith(datasourceUrl)) {
const path = query.fields.path
query.fields.path = `${datasource.config.url}/${path ? path : ""}`
}
url = buildUrl(query.fields.path, breakQs) url = buildUrl(query.fields.path, breakQs)
schema = schemaToFields(query.schema) schema = schemaToFields(query.schema)
bindings = queryParametersToKeyValue(query.parameters) bindings = queryParametersToKeyValue(query.parameters)

View File

@ -153,7 +153,10 @@ module RestModule {
getUrl(path: string, queryString: string): string { getUrl(path: string, queryString: string): string {
const main = `${path}?${queryString}` const main = `${path}?${queryString}`
let complete = !this.config.url ? main : `${this.config.url}/${main}` let complete = main
if (this.config.url && !main.startsWith(this.config.url)) {
complete = !this.config.url ? main : `${this.config.url}/${main}`
}
if (!complete.startsWith("http")) { if (!complete.startsWith("http")) {
complete = `http://${complete}` complete = `http://${complete}`
} }