Merge pull request #2807 from beekeeper-studio/fix/index-form-validation

add validation to index form
This commit is contained in:
Day Matchullis
2025-03-18 13:01:21 -06:00
committed by GitHub

View File

@@ -294,7 +294,19 @@ export default Vue.extend({
this.newRows.forEach((r) => r.delete())
this.clearChanges()
},
validateNewRows() {
this.newRows.forEach((row: RowComponent) => {
const data = row.getData()
if (_.isEmpty(data.name)) {
throw new Error('Name cannot be empty')
}
if (_.isEmpty(data.columns)) {
throw new Error('Columns cannot be empty')
}
})
},
getPayload(): IndexAlterations {
this.validateNewRows()
const additions = this.newRows.map((row: RowComponent) => {
const data = row.getData()
let dataColumns: string[]
@@ -335,6 +347,7 @@ export default Vue.extend({
this.$noty.success("Indexes Updated")
this.$emit('actionCompleted')
this.clearChanges()
this.error = null
// this.$nextTick(() => this.initializeTabulator())
} catch (ex) {
log.error('submitting index error', ex)
@@ -345,10 +358,15 @@ export default Vue.extend({
},
async submitSql() {
const payload = this.getPayload()
const sql = await this.connection.alterIndexSql(payload)
const formatted = format(sql, { language: FormatterDialect(this.dialect)})
this.$root.$emit(AppEvent.newTab, formatted)
try {
const payload = this.getPayload()
const sql = await this.connection.alterIndexSql(payload)
const formatted = format(sql, { language: FormatterDialect(this.dialect)})
this.error = null
this.$root.$emit(AppEvent.newTab, formatted)
} catch (e) {
this.error = e
}
},
initializeTabulator() {