-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1613 from topcoder-platform/PM-875_project-filters
PM-875 - move projects to new container, add filters
- Loading branch information
Showing
12 changed files
with
383 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React, { useEffect, useMemo, useState } from 'react' | ||
import cn from 'classnames' | ||
import { DebounceInput } from 'react-debounce-input' | ||
import { withRouter, Link } from 'react-router-dom' | ||
import { connect } from 'react-redux' | ||
import PropTypes from 'prop-types' | ||
import Loader from '../../components/Loader' | ||
import { checkAdminOrCopilot } from '../../util/tc' | ||
import { PrimaryButton } from '../../components/Buttons' | ||
import Select from '../../components/Select' | ||
import ProjectCard from '../../components/ProjectCard' | ||
import InfiniteLoadTrigger from '../../components/InfiniteLoadTrigger' | ||
import { loadProjects, loadMoreProjects, unloadProjects } from '../../actions/projects' | ||
import { PROJECT_STATUSES } from '../../config/constants' | ||
|
||
import styles from './styles.module.scss' | ||
|
||
const Projects = ({ projects, auth, isLoading, projectsCount, loadProjects, loadMoreProjects, unloadProjects }) => { | ||
const [search, setSearch] = useState() | ||
const [projectStatus, setProjectStatus] = useState('') | ||
const selectedStatus = useMemo(() => PROJECT_STATUSES.find(s => s.value === projectStatus)) | ||
|
||
useEffect(() => { | ||
loadProjects(search, projectStatus ? { status: projectStatus } : {}) | ||
}, [search, projectStatus]) | ||
|
||
// unload projects on dismount | ||
useEffect(() => () => unloadProjects, []) | ||
|
||
if (isLoading && projects.length === 0) { | ||
return ( | ||
<div className={styles.container}> | ||
<Loader /> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<div className={styles.headerLine}> | ||
<h2>Projects</h2> | ||
{checkAdminOrCopilot(auth.token) && ( | ||
<Link className={styles.buttonNewProject} to={`/projects/new`}> | ||
<PrimaryButton text={'New Project'} type={'info'} /> | ||
</Link> | ||
)} | ||
</div> | ||
<div className={styles.searchWrapper}> | ||
<div className={styles['col-6']}> | ||
<div className={cn(styles.field, styles.input1)}> | ||
<label>Search :</label> | ||
</div> | ||
<div className={styles.searchInputWrapper}> | ||
<DebounceInput | ||
className={styles.searchInput} | ||
minLength={2} | ||
debounceTimeout={300} | ||
placeholder='Keyword' | ||
onChange={e => setSearch(e.target.value)} | ||
value={search} | ||
/> | ||
</div> | ||
</div> | ||
<div className={styles['col-6']}> | ||
<div className={cn(styles.field, styles.input1)}> | ||
<label>Project Status:</label> | ||
</div> | ||
<div className={styles.searchInputWrapper}> | ||
<Select | ||
name='projectStatus' | ||
options={PROJECT_STATUSES} | ||
placeholder='All' | ||
value={selectedStatus} | ||
onChange={e => setProjectStatus(e ? e.value : '')} | ||
isClearable | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
{projects.length > 0 ? ( | ||
<> | ||
<ul> | ||
{projects.map(p => ( | ||
<li key={p.id}> | ||
<ProjectCard | ||
projectStatus={p.status} | ||
projectName={p.name} | ||
projectId={p.id} | ||
/> | ||
</li> | ||
))} | ||
</ul> | ||
{projects && projects.length < projectsCount - 1 && ( | ||
// fix | ||
<InfiniteLoadTrigger onLoadMore={loadMoreProjects} /> | ||
)} | ||
</> | ||
) : ( | ||
<span>No projects available yet</span> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
Projects.propTypes = { | ||
projectsCount: PropTypes.number.isRequired, | ||
projects: PropTypes.array, | ||
auth: PropTypes.object.isRequired, | ||
isLoading: PropTypes.bool.isRequired, | ||
unloadProjects: PropTypes.func.isRequired, | ||
loadProjects: PropTypes.func.isRequired, | ||
loadMoreProjects: PropTypes.func.isRequired | ||
} | ||
|
||
const mapStateToProps = ({ projects, auth }) => { | ||
return { | ||
projectsCount: projects.projectsCount, | ||
projects: projects.projects, | ||
isLoading: projects.isLoading, | ||
auth | ||
} | ||
} | ||
|
||
const mapDispatchToProps = { | ||
unloadProjects: unloadProjects, | ||
loadProjects: loadProjects, | ||
loadMoreProjects: loadMoreProjects | ||
} | ||
|
||
export default withRouter( | ||
connect(mapStateToProps, mapDispatchToProps)(Projects) | ||
) |
Oops, something went wrong.