Skip to content

Commit 1bfae89

Browse files
committed
Add search to Explore Teams page
1 parent 88475fc commit 1bfae89

File tree

4 files changed

+65
-33
lines changed

4 files changed

+65
-33
lines changed

cypress/e2e/teams/index.cy.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,21 @@ describe('Teams page', () => {
3131
cy.get("[data-cy='teams-table-pagination']").should('exist')
3232
cy.get('[data-cy=teams-table-pagination]').contains('Showing 1-10 of 35')
3333

34-
// Perform sort by team name
34+
// Sort by team name
3535
cy.get('[data-cy=table-head-column-name]').click()
36-
cy.get('[data-cy=teams-table]').contains('Team 035')
37-
cy.get('[data-cy=teams-table]').contains('Team 026')
36+
cy.get('[data-cy=teams-table]')
37+
.find('tbody tr:nth-child(1) td:nth-child(2)')
38+
.contains('Team 035')
39+
cy.get('[data-cy=teams-table]')
40+
.find('tbody tr:nth-child(10) td:nth-child(2)')
41+
.contains('Team 026')
42+
43+
// Search by team name
44+
cy.get('[data-cy=teams-table-search-input]').type('02')
45+
cy.get('[data-cy=teams-table-search-submit]').click()
46+
cy.get('[data-cy=teams-table]')
47+
.find('tbody tr:nth-child(5) td:nth-child(2)')
48+
.contains('Team 025')
49+
cy.get('[data-cy=teams-table-pagination]').contains('Showing 1-10 of 11')
3850
})
3951
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Field, Form, Formik } from 'formik'
2+
import Button from '../button'
3+
4+
const SearchInput = ({ onSearch, placeholder, 'data-cy': dataCy }) => (
5+
<Formik
6+
initialValues={{ search: '' }}
7+
onSubmit={({ search }) => onSearch(search)}
8+
>
9+
<Form className='form-control'>
10+
<Field
11+
data-cy={`${dataCy}-search-input`}
12+
type='text'
13+
name='search'
14+
id='search'
15+
placeholder={placeholder}
16+
/>
17+
<Button
18+
data-cy={`${dataCy}-search-submit`}
19+
type='submit'
20+
variant='submit'
21+
>
22+
Search
23+
</Button>
24+
</Form>
25+
</Formik>
26+
)
27+
28+
export default SearchInput

src/pages/teams/[id]/members-table.js

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,10 @@ import Table from '../../../components/tables/table'
33
import { useState } from 'react'
44
import Pagination from '../../../components/pagination'
55
import { serverRuntimeConfig } from '../../../../next.config.js'
6-
import { Field, Form, Formik } from 'formik'
7-
import Button from '../../../components/button'
86
import * as R from 'ramda'
7+
import SearchInput from '../../../components/tables/search-input'
98
const { DEFAULT_PAGE_SIZE } = serverRuntimeConfig
109

11-
const SearchInput = ({ onSearch, 'data-cy': dataCy }) => (
12-
<Formik
13-
initialValues={{ search: '' }}
14-
onSubmit={({ search }) => onSearch(search)}
15-
>
16-
<Form className='form-control'>
17-
<Field
18-
data-cy={`${dataCy}-search-input`}
19-
type='text'
20-
name='search'
21-
id='search'
22-
placeholder='Type an username...'
23-
/>
24-
<Button
25-
data-cy={`${dataCy}-search-submit`}
26-
type='submit'
27-
variant='submit'
28-
>
29-
Search
30-
</Button>
31-
</Form>
32-
</Formik>
33-
)
34-
3510
function MembersTable({ rows: allRows, onRowClick }) {
3611
const [page, setPage] = useState(1)
3712
const [search, setSearch] = useState(null)
@@ -66,18 +41,19 @@ function MembersTable({ rows: allRows, onRowClick }) {
6641
return (
6742
<>
6843
<SearchInput
69-
data-cy={`team-members-table`}
44+
data-cy='team-members-table'
45+
placeholder='Type an username...'
7046
onSearch={(search) => {
7147
// Reset to page 1 and search
7248
setPage(1)
7349
setSearch(search)
7450
}}
7551
/>
7652
<Table
77-
data-cy={`team-members-table`}
53+
data-cy='team-members-table'
7854
rows={rows.slice(pageStartIndex, pageEndIndex)}
7955
columns={columns}
80-
emptyPlaceHolder={'This team has no members.'}
56+
emptyPlaceHolder='This team has no members.'
8157
onRowClick={onRowClick}
8258
showRowNumbers
8359
sort={sort}

src/pages/teams/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getTeams } from '../../lib/teams-api'
1010
import logger from '../../lib/logger'
1111
import { serverRuntimeConfig } from '../../../next.config.js'
1212
import Pagination from '../../components/pagination'
13+
import SearchInput from '../../components/tables/search-input'
1314
const { DEFAULT_PAGE_SIZE } = serverRuntimeConfig
1415

1516
const Map = dynamic(import('../../components/list-map'), {
@@ -32,6 +33,7 @@ export default class TeamList extends Component {
3233
key: 'name',
3334
direction: 'asc',
3435
},
36+
search: '',
3537
}
3638
}
3739

@@ -59,7 +61,7 @@ export default class TeamList extends Component {
5961
}
6062

6163
renderTeams() {
62-
const { teams, sortOptions, page } = this.state
64+
const { teams, sortOptions, page, search } = this.state
6365
if (!teams) return null
6466

6567
const columns = [
@@ -75,12 +77,26 @@ export default class TeamList extends Component {
7577
teams
7678
)
7779

80+
if (search?.length > 0) {
81+
rows = rows.filter((r) =>
82+
r.name.toUpperCase().includes(search.toUpperCase())
83+
)
84+
}
85+
7886
// Calculate start and end index
7987
const pageStartIndex = (page - 1) * DEFAULT_PAGE_SIZE
8088
const pageEndIndex = pageStartIndex + DEFAULT_PAGE_SIZE
8189

8290
return (
8391
<>
92+
<SearchInput
93+
data-cy='teams-table'
94+
placeholder='Search by team name...'
95+
onSearch={(search) => {
96+
// Reset to page 1 and search
97+
this.setState({ page: 1, search })
98+
}}
99+
/>
84100
<Table
85101
data-cy={`teams-table`}
86102
columns={columns}

0 commit comments

Comments
 (0)