Verify datasouce before updating
This commit is contained in:
parent
886b726627
commit
d6b00efa90
|
@ -22,16 +22,11 @@
|
||||||
IntegrationNames[datasource.type] || datasource.name || datasource.type
|
IntegrationNames[datasource.type] || datasource.name || datasource.type
|
||||||
|
|
||||||
async function validateConfig() {
|
async function validateConfig() {
|
||||||
function displayError(message) {
|
const displayError = message =>
|
||||||
notifications.error(message ?? "Error validating datasource")
|
notifications.error(message ?? "Error validating datasource")
|
||||||
}
|
|
||||||
|
|
||||||
let connected = false
|
let connected = false
|
||||||
try {
|
try {
|
||||||
if (!datasource.name) {
|
|
||||||
datasource.name = name
|
|
||||||
}
|
|
||||||
|
|
||||||
const resp = await validateDatasourceConfig(datasource)
|
const resp = await validateDatasourceConfig(datasource)
|
||||||
if (!resp.connected) {
|
if (!resp.connected) {
|
||||||
displayError(resp.error)
|
displayError(resp.error)
|
||||||
|
@ -42,7 +37,12 @@
|
||||||
}
|
}
|
||||||
return connected
|
return connected
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveDatasource() {
|
async function saveDatasource() {
|
||||||
|
const valid = await validateConfig()
|
||||||
|
if (!valid) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (!datasource.name) {
|
if (!datasource.name) {
|
||||||
datasource.name = name
|
datasource.name = name
|
||||||
|
@ -64,8 +64,7 @@
|
||||||
|
|
||||||
<ModalContent
|
<ModalContent
|
||||||
title={`Connect to ${name}`}
|
title={`Connect to ${name}`}
|
||||||
onConfirm={() =>
|
onConfirm={() => saveDatasource()}
|
||||||
validateConfig().then(connected => connected && saveDatasource())}
|
|
||||||
onCancel={() => modal.show()}
|
onCancel={() => modal.show()}
|
||||||
confirmText={datasource.plus
|
confirmText={datasource.plus
|
||||||
? "Save and fetch tables"
|
? "Save and fetch tables"
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
import { isEqual } from "lodash"
|
import { isEqual } from "lodash"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import ImportRestQueriesModal from "components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte"
|
import ImportRestQueriesModal from "components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte"
|
||||||
|
import { API } from "api"
|
||||||
|
|
||||||
const querySchema = {
|
const querySchema = {
|
||||||
name: {},
|
name: {},
|
||||||
|
@ -45,7 +46,28 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function validateConfig() {
|
||||||
|
const displayError = message =>
|
||||||
|
notifications.error(message ?? "Error validating datasource")
|
||||||
|
|
||||||
|
let connected = false
|
||||||
|
try {
|
||||||
|
const resp = await API.validateDatasource(datasource)
|
||||||
|
if (!resp.connected) {
|
||||||
|
displayError(resp.error)
|
||||||
|
}
|
||||||
|
connected = resp.connected
|
||||||
|
} catch (err) {
|
||||||
|
displayError(err?.message)
|
||||||
|
}
|
||||||
|
return connected
|
||||||
|
}
|
||||||
|
|
||||||
const saveDatasource = async () => {
|
const saveDatasource = async () => {
|
||||||
|
const valid = await validateConfig()
|
||||||
|
if (!valid) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Create datasource
|
// Create datasource
|
||||||
await datasources.save(datasource)
|
await datasources.save(datasource)
|
||||||
|
|
Loading…
Reference in New Issue