remove builderstore/datasource
This commit is contained in:
parent
3771ab2ffc
commit
f3d5e2b4a0
|
@ -1,54 +0,0 @@
|
|||
import { datasources, tables } from "../stores/backend"
|
||||
import { IntegrationNames } from "../constants/backend"
|
||||
import { get } from "svelte/store"
|
||||
import cloneDeep from "lodash/cloneDeepWith"
|
||||
import { API } from "api"
|
||||
|
||||
function prepareData(config) {
|
||||
let datasource = {}
|
||||
let existingTypeCount = get(datasources).list.filter(
|
||||
ds => ds.source === config.type
|
||||
).length
|
||||
|
||||
let baseName = IntegrationNames[config.type] || config.name
|
||||
let name =
|
||||
existingTypeCount === 0 ? baseName : `${baseName}-${existingTypeCount + 1}`
|
||||
|
||||
datasource.type = "datasource"
|
||||
datasource.source = config.type
|
||||
datasource.config = config.config
|
||||
datasource.name = name
|
||||
datasource.plus = config.plus
|
||||
|
||||
return datasource
|
||||
}
|
||||
|
||||
export async function saveDatasource(config, { skipFetch, tablesFilter } = {}) {
|
||||
const datasource = prepareData(config)
|
||||
// Create datasource
|
||||
const fetchSchema = !skipFetch && datasource.plus
|
||||
const resp = await datasources.save(datasource, { fetchSchema, tablesFilter })
|
||||
|
||||
// update the tables incase datasource plus
|
||||
await tables.fetch()
|
||||
await datasources.select(resp._id)
|
||||
return resp
|
||||
}
|
||||
|
||||
export async function createRestDatasource(integration) {
|
||||
const config = cloneDeep(integration)
|
||||
return saveDatasource(config)
|
||||
}
|
||||
|
||||
export async function validateDatasourceConfig(config) {
|
||||
const datasource = prepareData(config)
|
||||
return await API.validateDatasource(datasource)
|
||||
}
|
||||
|
||||
export async function getDatasourceInfo(config) {
|
||||
let datasource = config
|
||||
if (!config._id) {
|
||||
datasource = prepareData(config)
|
||||
}
|
||||
return await API.fetchInfoForDatasource(datasource)
|
||||
}
|
|
@ -16,7 +16,6 @@
|
|||
import ArrayRenderer from "components/common/renderers/ArrayRenderer.svelte"
|
||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||
import { goto } from "@roxi/routify"
|
||||
import { getDatasourceInfo } from "builderStore/datasource"
|
||||
|
||||
export let datasource
|
||||
export let save
|
||||
|
@ -170,8 +169,7 @@
|
|||
<Button
|
||||
secondary
|
||||
on:click={async () => {
|
||||
const info = await getDatasourceInfo(datasource)
|
||||
tableList = info.tableNames
|
||||
tableList = await datasources.getTableNames(datasource)
|
||||
confirmDialog.show()
|
||||
}}
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue