Skip to content

Commit

Permalink
Bug 1441950 add ability to filter through the list of roles (taskclus…
Browse files Browse the repository at this point in the history
…ter#481)

* added search panel

* code refactoring

* use SearchForm component
  • Loading branch information
hashi93 authored and eliperelman committed Mar 14, 2018
1 parent d0a61de commit 3d1e718
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/views/RoleManager/RoleManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import equal from 'deep-equal';
import Spinner from '../../components/Spinner';
import RoleEditor from '../../components/RoleEditor';
import HelmetTitle from '../../components/HelmetTitle';
import SearchForm from './SearchForm';

export default class RoleManager extends PureComponent {
constructor(props) {
super(props);

this.state = {
roles: null,
error: null
error: null,
roleIdContains: ''
};
}

Expand Down Expand Up @@ -73,6 +75,8 @@ export default class RoleManager extends PureComponent {
);
};

handleSetRoleId = value => this.setState({ roleIdContains: value });

renderRolesTable() {
const { roles } = this.state;

Expand All @@ -89,18 +93,29 @@ export default class RoleManager extends PureComponent {
</thead>
<tbody>
{this.state.roles
.filter(role => role.roleId.includes(this.state.roleIdContains))
.sort((a, b) => a.roleId.localeCompare(b.roleId))
.map(this.renderRoleRow)}
</tbody>
</Table>
);
}

renderTypeInput() {
return (
<SearchForm
default={this.state.roleIdContains}
onSearch={this.handleSetRoleId}
/>
);
}

render() {
return (
<Row style={{ marginTop: 10 }}>
<HelmetTitle title="Role Manager" />
<Col md={5}>
{this.renderTypeInput()}
{this.renderRolesTable()}
<ButtonToolbar>
<Button
Expand Down
60 changes: 60 additions & 0 deletions src/views/RoleManager/SearchForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { PureComponent } from 'react';
import { func } from 'prop-types';
import {
Glyphicon,
FormGroup,
InputGroup,
FormControl,
Form
} from 'react-bootstrap';
import styles from './styles.module.css';

export default class SearchForm extends PureComponent {
static propTypes = {
onSearch: func.isRequired
};

constructor(props) {
super(props);

this.state = { value: '' };
}

componentWillMount() {
if (this.props.default) {
this.setState({ value: this.props.default });
}
}

handleChange = e => this.setState({ value: e.target.value });

handleSearch = () => this.props.onSearch(this.state.value);

handleSubmit = e => {
e.preventDefault();

this.handleSearch();
};

render() {
return (
<div>
<Form onSubmit={this.handleSubmit} className={styles.typeInput}>
<FormGroup>
<InputGroup bsSize="sm">
<InputGroup.Addon>Role Id Containing</InputGroup.Addon>
<FormControl
onChange={this.handleChange}
value={this.state.value}
type="text"
/>
<InputGroup.Addon onClick={this.handleSearch} role="button">
<Glyphicon glyph="search" />
</InputGroup.Addon>
</InputGroup>
</FormGroup>
</Form>
</div>
);
}
}
5 changes: 5 additions & 0 deletions src/views/RoleManager/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.typeInput {
min-width: 300px;
max-width: 600px;
margin-top: 10px;
}

0 comments on commit 3d1e718

Please sign in to comment.