Show input box when editing

pull/975/head
Jared Scheib 2017-03-06 12:17:07 -08:00
parent 630dec75d6
commit e7db0f474f
3 changed files with 72 additions and 43 deletions

View File

@ -8,6 +8,13 @@ export const loadUsers = ({users}) => ({
}, },
}) })
export const loadRoles = ({roles}) => ({
type: 'LOAD_ROLES',
payload: {
roles,
},
})
export const killQuery = (queryID) => ({ export const killQuery = (queryID) => ({
type: 'KILL_QUERY', type: 'KILL_QUERY',
payload: { payload: {
@ -34,12 +41,6 @@ export const loadUsersAsync = (url) => async (dispatch) => {
const {data} = await getUsers(url) const {data} = await getUsers(url)
dispatch(loadUsers(data)) dispatch(loadUsers(data))
} }
export const loadRoles = ({roles}) => ({
type: 'LOAD_ROLES',
payload: {
roles,
},
})
export const loadRolesAsync = (url) => async (dispatch) => { export const loadRolesAsync = (url) => async (dispatch) => {
const {data} = await getRoles(url) const {data} = await getRoles(url)

View File

@ -1,9 +1,9 @@
import React, {PropTypes} from 'react' import React, {PropTypes} from 'react'
import MultiSelectDropdown from 'shared/components/MultiSelectDropdown' import MultiSelectDropdown from 'shared/components/MultiSelectDropdown'
const UserRow = ({user: {name, roles, permissions}}) => ( const UserRow = ({user: {name, roles, permissions}, isEditing}) => (
<tr> <tr>
<td>{name}</td> {isEditing ? <input type="text"></input> : <td>{name}</td>}
<td> <td>
{ {
roles && roles.length ? roles && roles.length ?
@ -31,6 +31,7 @@ const UserRow = ({user: {name, roles, permissions}}) => (
const { const {
arrayOf, arrayOf,
bool,
shape, shape,
string, string,
} = PropTypes } = PropTypes
@ -45,6 +46,7 @@ UserRow.propTypes = {
name: string, name: string,
})), })),
}).isRequired, }).isRequired,
isEditing: bool,
} }
export default UserRow export default UserRow

View File

@ -1,43 +1,69 @@
import React, {PropTypes} from 'react' import React, {Component, PropTypes} from 'react'
import UserRow from 'src/admin/components/UserRow' import UserRow from 'src/admin/components/UserRow'
import EmptyRow from 'src/admin/components/EmptyRow' import EmptyRow from 'src/admin/components/EmptyRow'
const UsersTable = ({users}) => ( class UsersTable extends Component {
<div className="panel panel-info"> constructor(props) {
<div className="panel-heading u-flex u-ai-center u-jc-space-between"> super(props)
<div className="users__search-widget input-group admin__search-widget">
<input this.state = {users: this.props.users}
type="text"
className="form-control" this.addUser = ::this.addUser
placeholder="Filter Role..." }
/>
<div className="input-group-addon"> addUser() {
<span className="icon search" aria-hidden="true"></span> const newUser = {
name: '',
roles: [],
permissions: [],
isEditing: true,
}
const newUsers = [...this.state.users]
newUsers.unshift(newUser)
this.setState({users: newUsers})
}
render() {
return (
<div className="panel panel-info">
<div className="panel-heading u-flex u-ai-center u-jc-space-between">
<div className="users__search-widget input-group admin__search-widget">
<input
type="text"
className="form-control"
placeholder="Filter Role..."
/>
<div className="input-group-addon">
<span className="icon search" aria-hidden="true"></span>
</div>
</div>
<button className="btn btn-primary" onClick={this.addUser}>Create User</button>
</div>
<div className="panel-body">
<table className="table v-center">
<thead>
<tr>
<th>User</th>
<th>Roles</th>
<th>Permissions</th>
</tr>
</thead>
<tbody>
{
this.state.users.length ?
this.state.users.map((user) =>
<UserRow key={user.name} user={user} isEditing={user.isEditing} />
) : <EmptyRow tableName={'Users'} />
}
</tbody>
</table>
</div> </div>
</div> </div>
<a href="#" className="btn btn-primary">Create User</a> )
</div> }
<div className="panel-body"> }
<table className="table v-center">
<thead>
<tr>
<th>User</th>
<th>Roles</th>
<th>Permissions</th>
</tr>
</thead>
<tbody>
{
users.length ?
users.map((user) =>
<UserRow key={user.name} user={user} />
) : <EmptyRow tableName={'Users'} />
}
</tbody>
</table>
</div>
</div>
)
const { const {
arrayOf, arrayOf,