Fix behavior on db creation with enter and make db keys unique

pull/10616/head
deniz kusefoglu 2017-09-18 20:07:21 -07:00
parent 3b1482261f
commit e032e26993
2 changed files with 8 additions and 6 deletions

View File

@ -41,9 +41,9 @@ const DatabaseManager = ({
</button>
</div>
<div className="panel-body">
{databases.map(db =>
{databases.map((db, db_ind) =>
<DatabaseTable
key={db.links.self}
key={db_ind}
database={db}
notify={notify}
isRFDisplayed={isRFDisplayed}

View File

@ -59,12 +59,10 @@ class DatabaseManagerPage extends Component {
handleCreateDatabase = database => {
const {actions, notify, source, databases} = this.props
if (!database.name) {
return notify('error', 'Database name cannot be blank')
}
if (_.findIndex(databases, {name: database.name}, 1)) {
if (_.findIndex(databases, {name: database.name}, 1) !== -1) {
return notify('error', 'A database by this name already exists')
}
@ -78,7 +76,7 @@ class DatabaseManagerPage extends Component {
handleKeyDownDatabase = database => e => {
const {key} = e
const {actions, notify, source} = this.props
const {actions, notify, source, databases} = this.props
if (key === 'Escape') {
actions.removeDatabase(database)
@ -89,6 +87,10 @@ class DatabaseManagerPage extends Component {
return notify('error', 'Database name cannot be blank')
}
if (_.findIndex(databases, {name: database.name}, 1) !== -1) {
return notify('error', 'A database by this name already exists')
}
actions.createDatabaseAsync(source.links.databases, database)
}
}