Add column name input validation.

This commit is contained in:
Sam Rose 2023-10-25 15:29:56 +01:00
parent fbf60ece4f
commit 5779e97e6e
No known key found for this signature in database
2 changed files with 14 additions and 11 deletions

View File

@ -47,7 +47,6 @@ export const createBuilderWebsocket = appId => {
// Data section events // Data section events
socket.onOther(BuilderSocketEvent.TableChange, ({ id, table }) => { socket.onOther(BuilderSocketEvent.TableChange, ({ id, table }) => {
console.log("Table change", id, table)
tables.replaceTable(id, table) tables.replaceTable(id, table)
}) })
socket.onOther(BuilderSocketEvent.DatasourceChange, ({ id, datasource }) => { socket.onOther(BuilderSocketEvent.DatasourceChange, ({ id, datasource }) => {

View File

@ -6,13 +6,23 @@
InlineAlert, InlineAlert,
} from "@budibase/bbui" } from "@budibase/bbui"
import { getContext } from "svelte" import { getContext } from "svelte"
import { ValidColumnNameRegex } from "@budibase/shared-core"
const { API, dispatch, definition, rows } = getContext("grid") const { API, dispatch, definition, rows } = getContext("grid")
export let column export let column
let newColumnName = `${column.schema.name} (migrated)` let newColumnName = `${column.schema.name} migrated`
$: newAndOldNameMatch = column.schema.name === newColumnName $: error = checkNewColumnName(newColumnName)
const checkNewColumnName = newColumnName => {
if (column.schema.name === newColumnName) {
return "New column name can't be the same as the existing column name."
}
if (newColumnName.match(ValidColumnNameRegex) === null) {
return "Illegal character; must be alpha-numeric."
}
}
const migrateUserColumn = async () => { const migrateUserColumn = async () => {
let subtype = "users" let subtype = "users"
@ -44,7 +54,7 @@
confirmText="Continue" confirmText="Continue"
cancelText="Cancel" cancelText="Cancel"
onConfirm={migrateUserColumn} onConfirm={migrateUserColumn}
disabled={newAndOldNameMatch} disabled={error !== undefined}
size="M" size="M"
> >
This operation will kick off a migration of the column "{column.schema.name}" This operation will kick off a migration of the column "{column.schema.name}"
@ -56,11 +66,5 @@
header="Are you sure?" header="Are you sure?"
message="This will leave bindings which utilised the user relationship column in a state where they will need to be updated to use the new column instead." message="This will leave bindings which utilised the user relationship column in a state where they will need to be updated to use the new column instead."
/> />
<Input <Input bind:value={newColumnName} label="New column name" {error} />
bind:value={newColumnName}
label="New column name"
error={newAndOldNameMatch
? "New column name can't be the same as the existing column name"
: undefined}
/>
</ModalContent> </ModalContent>