Validate feature toggle

This commit is contained in:
Adria Navarro 2023-05-23 18:23:37 +02:00
parent 7be824b2e6
commit 0c97f61cc8
2 changed files with 14 additions and 6 deletions

View File

@ -53,6 +53,7 @@
config, config,
schema: selected.datasource, schema: selected.datasource,
auth: selected.auth, auth: selected.auth,
features: selected.features || [],
} }
if (selected.friendlyName) { if (selected.friendlyName) {
integration.name = selected.friendlyName integration.name = selected.friendlyName

View File

@ -8,7 +8,6 @@
saveDatasource as save, saveDatasource as save,
validateDatasourceConfig, validateDatasourceConfig,
} from "builderStore/datasource" } from "builderStore/datasource"
import { onMount } from "svelte"
export let integration export let integration
export let modal export let modal
@ -37,18 +36,22 @@
return connected return connected
} }
$: shouldValidate = integration.features?.find(f => f === "connection")
async function saveDatasource() { async function saveDatasource() {
if (shouldValidate) {
const valid = await validateConfig() const valid = await validateConfig()
if (!valid) { if (!valid) {
return false return false
} }
}
try { try {
if (!datasource.name) { if (!datasource.name) {
datasource.name = name datasource.name = name
} }
const resp = await save(datasource) const resp = await save(datasource)
$goto(`./datasource/${resp._id}`) $goto(`./datasource/${resp._id}`)
notifications.success(`Datasource updated successfully.`) notifications.success(`Datasource created successfully.`)
} catch (err) { } catch (err) {
notifications.error(err?.message ?? "Error saving datasource") notifications.error(err?.message ?? "Error saving datasource")
// prevent the modal from closing // prevent the modal from closing
@ -61,7 +64,11 @@
title={`Connect to ${name}`} title={`Connect to ${name}`}
onConfirm={() => saveDatasource()} onConfirm={() => saveDatasource()}
onCancel={() => modal.show()} onCancel={() => modal.show()}
confirmText={datasource.plus ? "Connect" : "Save and continue to query"} confirmText={datasource.plus
? shouldValidate
? "Connect"
: "Save and continue"
: "Save and continue to query"}
cancelText="Back" cancelText="Back"
showSecondaryButton={datasource.plus} showSecondaryButton={datasource.plus}
size="L" size="L"