Add ability to filter orgs index
parent
f4e7cc4233
commit
6d0654d0f8
|
@ -1,5 +1,5 @@
|
||||||
// Libraries
|
// Libraries
|
||||||
import React, {PureComponent} from 'react'
|
import React, {PureComponent, ChangeEvent} from 'react'
|
||||||
import {WithRouterProps} from 'react-router'
|
import {WithRouterProps} from 'react-router'
|
||||||
import {connect} from 'react-redux'
|
import {connect} from 'react-redux'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
@ -13,6 +13,7 @@ import {
|
||||||
IconFont,
|
IconFont,
|
||||||
ComponentColor,
|
ComponentColor,
|
||||||
OverlayTechnology,
|
OverlayTechnology,
|
||||||
|
Input,
|
||||||
} from 'src/clockface'
|
} from 'src/clockface'
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
@ -36,6 +37,7 @@ interface DispatchProps {
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
modalState: ModalState
|
modalState: ModalState
|
||||||
|
searchTerm: string
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ModalState {
|
enum ModalState {
|
||||||
|
@ -47,15 +49,14 @@ type Props = StateProps & DispatchProps & WithRouterProps
|
||||||
|
|
||||||
@ErrorHandling
|
@ErrorHandling
|
||||||
class OrganizationsIndex extends PureComponent<Props, State> {
|
class OrganizationsIndex extends PureComponent<Props, State> {
|
||||||
constructor(props) {
|
public state: State = {
|
||||||
super(props)
|
modalState: ModalState.Closed,
|
||||||
this.state = {
|
searchTerm: '',
|
||||||
modalState: ModalState.Closed,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const {orgs, links, onCreateOrg, onDeleteOrg} = this.props
|
const {links, onCreateOrg, onDeleteOrg} = this.props
|
||||||
const {modalState} = this.state
|
const {modalState, searchTerm} = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -65,6 +66,12 @@ class OrganizationsIndex extends PureComponent<Props, State> {
|
||||||
<Page.Title title="Organizations" />
|
<Page.Title title="Organizations" />
|
||||||
</Page.Header.Left>
|
</Page.Header.Left>
|
||||||
<Page.Header.Right>
|
<Page.Header.Right>
|
||||||
|
<Input
|
||||||
|
value={searchTerm}
|
||||||
|
placeholder="Filter organizations by name..."
|
||||||
|
onChange={this.handleChangeSearchTerm}
|
||||||
|
/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
color={ComponentColor.Primary}
|
color={ComponentColor.Primary}
|
||||||
onClick={this.handleOpenModal}
|
onClick={this.handleOpenModal}
|
||||||
|
@ -75,7 +82,10 @@ class OrganizationsIndex extends PureComponent<Props, State> {
|
||||||
</Page.Header.Right>
|
</Page.Header.Right>
|
||||||
</Page.Header>
|
</Page.Header>
|
||||||
<Page.Contents fullWidth={false} scrollable={true}>
|
<Page.Contents fullWidth={false} scrollable={true}>
|
||||||
<OrganizationsIndexContents orgs={orgs} onDeleteOrg={onDeleteOrg} />
|
<OrganizationsIndexContents
|
||||||
|
orgs={this.filteredOrgs}
|
||||||
|
onDeleteOrg={onDeleteOrg}
|
||||||
|
/>
|
||||||
</Page.Contents>
|
</Page.Contents>
|
||||||
</Page>
|
</Page>
|
||||||
<OverlayTechnology visible={modalState === ModalState.Open}>
|
<OverlayTechnology visible={modalState === ModalState.Open}>
|
||||||
|
@ -89,6 +99,17 @@ class OrganizationsIndex extends PureComponent<Props, State> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get filteredOrgs(): Organization[] {
|
||||||
|
const {orgs} = this.props
|
||||||
|
const {searchTerm} = this.state
|
||||||
|
|
||||||
|
const filteredOrgs = orgs.filter(org =>
|
||||||
|
org.name.toLowerCase().includes(searchTerm.toLowerCase())
|
||||||
|
)
|
||||||
|
|
||||||
|
return filteredOrgs
|
||||||
|
}
|
||||||
|
|
||||||
private handleOpenModal = (): void => {
|
private handleOpenModal = (): void => {
|
||||||
this.setState({modalState: ModalState.Open})
|
this.setState({modalState: ModalState.Open})
|
||||||
}
|
}
|
||||||
|
@ -96,6 +117,10 @@ class OrganizationsIndex extends PureComponent<Props, State> {
|
||||||
private handleCloseModal = (): void => {
|
private handleCloseModal = (): void => {
|
||||||
this.setState({modalState: ModalState.Closed})
|
this.setState({modalState: ModalState.Closed})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleChangeSearchTerm = (e: ChangeEvent<HTMLInputElement>): void => {
|
||||||
|
this.setState({searchTerm: e.target.value})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mstp = (state): StateProps => {
|
const mstp = (state): StateProps => {
|
||||||
|
|
Loading…
Reference in New Issue