From 869cb0777b3409c2e7fd695704caa870cb3abfd7 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 24 Jul 2023 12:02:24 +0100 Subject: [PATCH] Validate query names to avoid parentheses --- .../components/integration/QueryViewer.svelte | 27 ++++++++++++------- .../server/src/api/controllers/query/index.ts | 6 +++++ packages/shared-core/src/constants.ts | 1 + 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/components/integration/QueryViewer.svelte b/packages/builder/src/components/integration/QueryViewer.svelte index 3377ff3a88..4683bc6335 100644 --- a/packages/builder/src/components/integration/QueryViewer.svelte +++ b/packages/builder/src/components/integration/QueryViewer.svelte @@ -14,8 +14,9 @@ Tab, Modal, ModalContent, + notifications, + Divider, } from "@budibase/bbui" - import { notifications, Divider } from "@budibase/bbui" import ExtraQueryConfig from "./ExtraQueryConfig.svelte" import IntegrationQueryEditor from "components/integration/index.svelte" import ExternalDataSourceTable from "components/backend/DataTable/ExternalDataSourceTable.svelte" @@ -28,6 +29,7 @@ import KeyValueBuilder from "./KeyValueBuilder.svelte" import { fieldsToSchema, schemaToFields } from "helpers/data/utils" import AccessLevelSelect from "./AccessLevelSelect.svelte" + import { ValidQueryNameRegex } from "@budibase/shared-core" export let query @@ -47,6 +49,7 @@ let saveModal let override = false let navigateTo = null + let nameError = null // seed the transformer if (query && !query.transformer) { @@ -77,7 +80,7 @@ $: queryConfig = integrationInfo?.query $: shouldShowQueryConfig = queryConfig && query.queryVerb $: readQuery = query.queryVerb === "read" || query.readable - $: queryInvalid = !query.name || (readQuery && data.length === 0) + $: queryInvalid = !query.name || nameError || (readQuery && data.length === 0) //Cast field in query preview response to number if specified by schema $: { @@ -139,9 +142,10 @@ queryStr = JSON.stringify(query) } + notifications.success("Query saved successfully") return response } catch (error) { - notifications.error("Error saving query") + notifications.error(error.message || "Error saving query") } } @@ -183,8 +187,14 @@ value={query.name} on:input={e => { let newValue = e.target.value || "" - query.name = newValue.trim() + if (newValue.match(ValidQueryNameRegex)) { + query.name = newValue.trim() + nameError = null + } else { + nameError = "Invalid query name" + } }} + error={nameError} /> {#if queryConfig} @@ -250,9 +260,9 @@ size="L" /> - Add a JavaScript function to transform the query result. + + Add a JavaScript function to transform the query result. +
Results - +