Skip to content

Commit

Permalink
Merge pull request #12437 from influxdata/feat/remove-member-org
Browse files Browse the repository at this point in the history
Add the ability to remove a member from org
  • Loading branch information
Palakp41 authored Mar 8, 2019
2 parents a2b06c4 + 834f6d0 commit 0e022e3
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 130 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ On most `linux` systems:

```sh

# Replace <username> with your actual username.
# Replace <username> with your actual username.

$ rm -r /home/<username>/.influxdbv2/engine
```
Expand All @@ -32,6 +32,7 @@ Once completed, `v2.0.0-alpha.5` can be started.
1. [12111](https://github.com/influxdata/influxdb/pull/12111): Add ability to filter resources by clicking a label
1. [12401](https://github.com/influxdata/influxdb/pull/12401): Add ability to add a member to org
1. [12391](https://github.com/influxdata/influxdb/pull/12391): Improve representation of TSM tagsets on disk
1. [12437](https://github.com/influxdata/influxdb/pull/12437): Add ability to remove a member from org

### Bug Fixes

Expand Down
47 changes: 14 additions & 33 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
},
"dependencies": {
"@influxdata/clockface": "0.0.5",
"@influxdata/influx": "0.2.28",
"@influxdata/influx": "0.2.29",
"@influxdata/react-custom-scrollbars": "4.3.8",
"axios": "^0.18.0",
"babel-polyfill": "^6.26.0",
Expand Down
6 changes: 3 additions & 3 deletions ui/src/organizations/components/AddMembersOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {UsersMap} from 'src/organizations/components/Members'
interface Props {
onCloseModal: () => void
users: UsersMap
addUser: (user: AddResourceMemberRequestBody) => void
addMember: (user: AddResourceMemberRequestBody) => void
}

interface State {
Expand Down Expand Up @@ -53,12 +53,12 @@ export default class AddMembersOverlay extends PureComponent<Props, State> {
}

private handleSave = () => {
const {users, addUser} = this.props
const {users, addMember} = this.props
const {selectedUserIDs} = this.state

selectedUserIDs.forEach(id => {
if (users[id]) {
addUser({id: id, name: users[id].name})
addMember({id: id, name: users[id].name})
}
})
}
Expand Down
18 changes: 9 additions & 9 deletions ui/src/organizations/components/MemberList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ import React, {PureComponent} from 'react'

// Components
import {IndexList} from 'src/clockface'
import MemberRow from 'src/organizations/components/MemberRow'

// Types
import {ResourceOwner} from '@influxdata/influx'

interface Props {
members: ResourceOwner[]
emptyState: JSX.Element
onDelete: (member: ResourceOwner) => void
}

export default class MemberList extends PureComponent<Props> {
public render() {
return (
<IndexList>
<IndexList.Header>
<IndexList.HeaderCell columnName="Username" width="25%" />
<IndexList.HeaderCell columnName="Role" width="25%" />
<IndexList.HeaderCell width="50%" />
<IndexList.HeaderCell columnName="Username" width="20%" />
<IndexList.HeaderCell columnName="Role" width="20%" />
<IndexList.HeaderCell width="60%" />
</IndexList.Header>
<IndexList.Body columnCount={3} emptyState={this.props.emptyState}>
{this.rows}
Expand All @@ -29,12 +31,10 @@ export default class MemberList extends PureComponent<Props> {
}

private get rows(): JSX.Element[] {
return this.props.members.map(member => (
<IndexList.Row key={member.id}>
<IndexList.Cell>{member.name}</IndexList.Cell>
<IndexList.Cell>{member.role}</IndexList.Cell>
<IndexList.Cell />
</IndexList.Row>
const {members, onDelete} = this.props

return members.map(member => (
<MemberRow key={member.id} member={member} onDelete={onDelete} />
))
}
}
42 changes: 42 additions & 0 deletions ui/src/organizations/components/MemberRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Libraries
import React, {PureComponent} from 'react'

// Components
import {ResourceOwner} from '@influxdata/influx'
import {
IndexList,
ConfirmationButton,
ComponentSize,
Alignment,
} from 'src/clockface'

interface Props {
member: ResourceOwner
onDelete: (member: ResourceOwner) => void
}

export default class MemberRow extends PureComponent<Props> {
public render() {
const {member} = this.props

return (
<IndexList.Row key={member.id}>
<IndexList.Cell>{member.name}</IndexList.Cell>
<IndexList.Cell>{member.role}</IndexList.Cell>
<IndexList.Cell revealOnHover={true} alignment={Alignment.Right}>
<ConfirmationButton
size={ComponentSize.ExtraSmall}
text="Delete"
confirmText="Confirm"
onConfirm={this.handleDelete}
/>
</IndexList.Cell>
</IndexList.Row>
)
}

private handleDelete = () => {
const {member, onDelete} = this.props
onDelete(member)
}
}
34 changes: 28 additions & 6 deletions ui/src/organizations/components/Members.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {client} from 'src/utils/api'
import {
memberAddSuccess,
memberAddFailed,
memberRemoveSuccess,
memberRemoveFailed,
} from 'src/shared/copy/v2/notifications'

export interface UsersMap {
Expand Down Expand Up @@ -87,13 +89,19 @@ export default class Members extends PureComponent<Props, State> {
searchKeys={['name']}
searchTerm={searchTerm}
>
{ms => <MemberList members={ms} emptyState={this.emptyState} />}
{ms => (
<MemberList
members={ms}
emptyState={this.emptyState}
onDelete={this.removeMember}
/>
)}
</FilterList>
<OverlayTechnology visible={overlayState === OverlayState.Open}>
<AddMembersOverlay
onCloseModal={this.handleCloseModal}
users={this.state.users}
addUser={this.addUser}
addMember={this.addMember}
/>
</OverlayTechnology>
</>
Expand Down Expand Up @@ -133,14 +141,14 @@ export default class Members extends PureComponent<Props, State> {
this.setState({users: users})
}

private addUser = async (user: AddResourceMemberRequestBody) => {
const {notify} = this.props
private addMember = async (user: AddResourceMemberRequestBody) => {
const {notify, onChange} = this.props

try {
await client.organizations.addMember(this.props.orgID, user)
this.setState({overlayState: OverlayState.Closed})
notify(memberAddSuccess())
this.props.onChange()
onChange()
notify(memberAddSuccess(user.name))
} catch (e) {
console.error(e)
this.setState({overlayState: OverlayState.Closed})
Expand All @@ -149,6 +157,20 @@ export default class Members extends PureComponent<Props, State> {
}
}

private removeMember = async (member: ResourceOwner) => {
const {orgID, notify, onChange} = this.props

try {
await client.organizations.removeMember(orgID, member.id)
onChange()
notify(memberRemoveSuccess(member.name))
} catch (e) {
console.error(e)
const message = _.get(e, 'response.data.message', 'Unknown error')
notify(memberRemoveFailed(message))
}
}

private get emptyState(): JSX.Element {
const {orgName} = this.props
const {searchTerm} = this.state
Expand Down
Loading

0 comments on commit 0e022e3

Please sign in to comment.