Fix org link & filtering by passing whole org object around
Does not fix the double-click bug introduced in c8f1cf1, which is probably due to an unloaded curry on first click.pull/10616/head
parent
02337eb259
commit
ae997e94bc
|
@ -15,8 +15,8 @@ class ChronografUsersTable extends Component {
|
||||||
super(props)
|
super(props)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChooseFilter = filterString => () => {
|
handleChooseFilter = organization => () => {
|
||||||
this.props.onFilterUsers({name: filterString})
|
this.props.onFilterUsers({organization})
|
||||||
}
|
}
|
||||||
|
|
||||||
// currentOrg is a role object that contains the organization id being updated
|
// currentOrg is a role object that contains the organization id being updated
|
||||||
|
|
|
@ -9,8 +9,12 @@ class UsersTableHeader extends Component {
|
||||||
super(props)
|
super(props)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleChooseFilter = () => organization => {
|
||||||
|
this.props.onFilterUsers({organization})
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {onFilterUsers, organizations, organizationName} = this.props
|
const {organizations, organizationName} = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="panel-heading u-flex u-ai-center u-jc-space-between">
|
<div className="panel-heading u-flex u-ai-center u-jc-space-between">
|
||||||
|
@ -30,7 +34,7 @@ class UsersTableHeader extends Component {
|
||||||
text: org.name,
|
text: org.name,
|
||||||
}))}
|
}))}
|
||||||
selected={organizationName}
|
selected={organizationName}
|
||||||
onChoose={onFilterUsers}
|
onChoose={this.handleChooseFilter()}
|
||||||
buttonSize="btn-md"
|
buttonSize="btn-md"
|
||||||
className="dropdown-220"
|
className="dropdown-220"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Dropdown from 'shared/components/Dropdown'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DEFAULT_ORG_NAME,
|
DEFAULT_ORG_NAME,
|
||||||
|
DEFAULT_ORG_ID,
|
||||||
NO_ORG,
|
NO_ORG,
|
||||||
MEMBER_ROLE,
|
MEMBER_ROLE,
|
||||||
} from 'src/admin/constants/dummyUsers'
|
} from 'src/admin/constants/dummyUsers'
|
||||||
|
@ -42,27 +43,37 @@ const UsersTableOrgCell = ({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return organizations.length
|
||||||
<td style={{width: colOrg}}>
|
? <td style={{width: colOrg}}>
|
||||||
{user.roles
|
{user.roles
|
||||||
.filter(role => {
|
.filter(role => {
|
||||||
return !(role.organizationName === DEFAULT_ORG_NAME)
|
return !(role.organization === DEFAULT_ORG_ID)
|
||||||
})
|
})
|
||||||
.map((role, i) =>
|
.map((role, i) => {
|
||||||
<span key={i} className="chronograf-user--org">
|
const org = organizations.find(o => o.id === role.organization)
|
||||||
<a href="#" onClick={onChooseFilter(role.organizationName)}>
|
return (
|
||||||
{role.organizationName}
|
<span key={i} className="chronograf-user--org">
|
||||||
</a>
|
<a href="#" onClick={onChooseFilter(org)}>
|
||||||
</span>
|
{org.name}
|
||||||
)}
|
</a>
|
||||||
</td>
|
</span>
|
||||||
)
|
)
|
||||||
|
})}
|
||||||
|
</td>
|
||||||
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const {arrayOf, func, shape} = PropTypes
|
const {arrayOf, func, shape, string} = PropTypes
|
||||||
|
|
||||||
UsersTableOrgCell.propTypes = {
|
UsersTableOrgCell.propTypes = {
|
||||||
user: shape(),
|
user: shape({
|
||||||
|
roles: arrayOf(
|
||||||
|
shape({
|
||||||
|
name: string.isRequired,
|
||||||
|
organization: string.isRequired,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
organizations: arrayOf(shape()),
|
organizations: arrayOf(shape()),
|
||||||
onChangeUserOrg: func.isRequired,
|
onChangeUserOrg: func.isRequired,
|
||||||
onChooseFilter: func.isRequired,
|
onChooseFilter: func.isRequired,
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React, {PropTypes} from 'react'
|
||||||
|
|
||||||
import Dropdown from 'shared/components/Dropdown'
|
import Dropdown from 'shared/components/Dropdown'
|
||||||
|
|
||||||
import {DEFAULT_ORG_NAME, USER_ROLES} from 'src/admin/constants/dummyUsers'
|
import {DEFAULT_ORG_ID, USER_ROLES} from 'src/admin/constants/dummyUsers'
|
||||||
import {USERS_TABLE} from 'src/admin/constants/chronografTableSizing'
|
import {USERS_TABLE} from 'src/admin/constants/chronografTableSizing'
|
||||||
|
|
||||||
const UsersTableRoleCell = ({user, onChangeUserRole}) => {
|
const UsersTableRoleCell = ({user, onChangeUserRole}) => {
|
||||||
|
@ -21,7 +21,7 @@ const UsersTableRoleCell = ({user, onChangeUserRole}) => {
|
||||||
<td style={{width: colRole}}>
|
<td style={{width: colRole}}>
|
||||||
{user.roles
|
{user.roles
|
||||||
.filter(role => {
|
.filter(role => {
|
||||||
return !(role.organizationName === DEFAULT_ORG_NAME)
|
return !(role.organization === DEFAULT_ORG_ID)
|
||||||
})
|
})
|
||||||
.map((role, i) =>
|
.map((role, i) =>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
|
@ -41,10 +41,17 @@ const UsersTableRoleCell = ({user, onChangeUserRole}) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const {func, shape} = PropTypes
|
const {arrayOf, func, shape, string} = PropTypes
|
||||||
|
|
||||||
UsersTableRoleCell.propTypes = {
|
UsersTableRoleCell.propTypes = {
|
||||||
user: shape(),
|
user: shape({
|
||||||
|
roles: arrayOf(
|
||||||
|
shape({
|
||||||
|
name: string.isRequired,
|
||||||
|
organization: string.isRequired,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
onChangeUserRole: func.isRequired,
|
onChangeUserRole: func.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ class AdminChronografPage extends Component {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
// TODO: pass around organization object instead of just name
|
// TODO: pass around organization object instead of just name
|
||||||
organizationName: this.props.currentOrganization.name,
|
organization: this.props.currentOrganization,
|
||||||
selectedUsers: [],
|
selectedUsers: [],
|
||||||
filteredUsers: this.props.users,
|
filteredUsers: this.props.users,
|
||||||
showManageOverlay: false,
|
showManageOverlay: false,
|
||||||
|
@ -43,7 +43,7 @@ class AdminChronografPage extends Component {
|
||||||
const {users, currentOrganization} = nextProps
|
const {users, currentOrganization} = nextProps
|
||||||
|
|
||||||
this.handleFilterUsers({
|
this.handleFilterUsers({
|
||||||
name: currentOrganization.name,
|
organization: currentOrganization,
|
||||||
users,
|
users,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -68,26 +68,26 @@ class AdminChronografPage extends Component {
|
||||||
this.setState({showManageOverlay: false, showCreateUserOverlay: false})
|
this.setState({showManageOverlay: false, showCreateUserOverlay: false})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFilterUsers = ({users, name}) => {
|
handleFilterUsers = ({users, organization}) => {
|
||||||
const nextUsers = users || this.props.users
|
const nextUsers = users || this.props.users
|
||||||
const nextOrganizationName = name || this.props.currentOrganization.name
|
const nextOrganization = organization || this.props.currentOrganization
|
||||||
|
|
||||||
const filteredUsers =
|
const filteredUsers =
|
||||||
nextOrganizationName === DEFAULT_ORG_NAME
|
nextOrganization.name === DEFAULT_ORG_NAME
|
||||||
? nextUsers
|
? nextUsers
|
||||||
: nextUsers.filter(
|
: nextUsers.filter(
|
||||||
user =>
|
user =>
|
||||||
nextOrganizationName === NO_ORG
|
nextOrganization.name === NO_ORG
|
||||||
? user.roles.length === 1 // Filter out if user is only part of Default Org
|
? user.roles.length === 1 // Filter out if user is only part of Default Org
|
||||||
: user.roles.find(
|
: user.roles.find(
|
||||||
role => role.organizationName === nextOrganizationName
|
role => role.organization === nextOrganization.id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
this.setState({
|
this.setState({
|
||||||
filteredUsers,
|
filteredUsers,
|
||||||
organizationName: nextOrganizationName,
|
organization: nextOrganization,
|
||||||
selectedUsers:
|
selectedUsers:
|
||||||
nextOrganizationName === DEFAULT_ORG_NAME
|
nextOrganization.name === DEFAULT_ORG_NAME
|
||||||
? this.state.selectedUsers
|
? this.state.selectedUsers
|
||||||
: [],
|
: [],
|
||||||
})
|
})
|
||||||
|
@ -205,7 +205,7 @@ class AdminChronografPage extends Component {
|
||||||
render() {
|
render() {
|
||||||
const {users, organizations} = this.props
|
const {users, organizations} = this.props
|
||||||
const {
|
const {
|
||||||
organizationName,
|
organization,
|
||||||
selectedUsers,
|
selectedUsers,
|
||||||
filteredUsers,
|
filteredUsers,
|
||||||
showManageOverlay,
|
showManageOverlay,
|
||||||
|
@ -228,13 +228,13 @@ class AdminChronografPage extends Component {
|
||||||
<div className="col-xs-12">
|
<div className="col-xs-12">
|
||||||
<div className="panel panel-minimal">
|
<div className="panel panel-minimal">
|
||||||
<UsersTableHeader
|
<UsersTableHeader
|
||||||
organizationName={organizationName}
|
organizationName={organization.name}
|
||||||
organizations={organizations}
|
organizations={organizations}
|
||||||
onFilterUsers={this.handleFilterUsers}
|
onFilterUsers={this.handleFilterUsers}
|
||||||
/>
|
/>
|
||||||
<BatchActionsBar
|
<BatchActionsBar
|
||||||
numUsersSelected={numUsersSelected}
|
numUsersSelected={numUsersSelected}
|
||||||
organizationName={organizationName}
|
organizationName={organization.name}
|
||||||
organizations={organizations}
|
organizations={organizations}
|
||||||
onDeleteUsers={this.handleBatchDeleteUsers}
|
onDeleteUsers={this.handleBatchDeleteUsers}
|
||||||
onAddUsersToOrg={this.handleBatchAddUsersToOrg}
|
onAddUsersToOrg={this.handleBatchAddUsersToOrg}
|
||||||
|
@ -246,11 +246,11 @@ class AdminChronografPage extends Component {
|
||||||
<div className="panel-body chronograf-admin-table--panel">
|
<div className="panel-body chronograf-admin-table--panel">
|
||||||
<Authorized
|
<Authorized
|
||||||
requiredRole={SUPERADMIN_ROLE}
|
requiredRole={SUPERADMIN_ROLE}
|
||||||
propsOverride={{organizationName}}
|
propsOverride={{organizationName: organization.name}}
|
||||||
>
|
>
|
||||||
<UsersTable
|
<UsersTable
|
||||||
filteredUsers={filteredUsers} // TODO: change to users upon separating Orgs & Users views
|
filteredUsers={filteredUsers} // TODO: change to users upon separating Orgs & Users views
|
||||||
organizationName={organizationName}
|
organizationName={organization.name}
|
||||||
organizations={organizations}
|
organizations={organizations}
|
||||||
onFilterUsers={this.handleFilterUsers}
|
onFilterUsers={this.handleFilterUsers}
|
||||||
onToggleUserSelected={this.handleToggleUserSelected}
|
onToggleUserSelected={this.handleToggleUserSelected}
|
||||||
|
|
Loading…
Reference in New Issue