Remove system databases from "Write Data" dropdown

Users should not write to _internal, or generally any other database
preceeded with an '_', as we take that to mean a system-internal
database of some kind. This filters the list of databases to remove
those with names preceeded by a '_' character.

Also 'SHOW DATABASES' can return an error if users are not authorized to
do that, so it's important to throw that so it can be properly handled /
displayed to the user.
pull/1612/head
Tim Raymond 2017-06-14 16:30:47 -04:00
parent baa43f738a
commit b0ef948585
1 changed files with 10 additions and 4 deletions

View File

@ -43,12 +43,18 @@ class DatabaseDropdown extends Component {
const proxy = source.links.proxy
try {
const {data} = await showDatabases(proxy)
const {databases} = showDatabasesParser(data)
const {databases, errors} = showDatabasesParser(data)
if (errors.length > 0) {
throw errors[0] // only one error can come back from this, but it's returned as an array
}
this.setState({databases})
const selectedDatabaseText = databases.includes(database)
// system databases are those preceded with an '_'
const nonSystemDatabases = databases.filter((name) => name[0] !== '_')
this.setState({databases: nonSystemDatabases})
const selectedDatabaseText = nonSystemDatabases.includes(database)
? database
: databases[0] || 'No databases'
: nonSystemDatabases[0] || 'No databases'
onSelectDatabase({text: selectedDatabaseText})
} catch (error) {
console.error(error)