Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions src/projects/actions/loadProjects.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import _ from 'lodash'
import {
PROJECT_SEARCH, GET_PROJECTS, PROJECT_STATUS, PROJECT_STATUS_CANCELLED,
PROJECT_SEARCH, GET_PROJECTS,
SET_SEARCH_TERM, SET_PROJECTS_SEARCH_CRITERIA,
CLEAR_PROJECT_SUGGESTIONS_SEARCH, PROJECT_SUGGESTIONS_SEARCH_SUCCESS,
ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN,
SET_PROJECTS_INFINITE_AUTOLOAD,
SET_PROJECTS_LIST_VIEW
} from '../../config/constants'
Expand All @@ -20,30 +19,9 @@ const getProjectsWithMembers = (dispatch, getState, criteria, pageNum) => {
pageNum
})

// for non power users, we hard coding the project status to not show Cancelled projects
// we don't want the URL to clutter with this, hence criteria has to modified just before passing to the API
// NOTE: we need to remove this if we provide status filter for such users
const requestCriteria = {...criteria} // make a copy of criteria to NOT to change it in the redux store
let isPowerUser = false
const loadUser = getState().loadUser
// power user roles
const roles = [ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN]
if (loadUser.user) {
// determine if user is a power user
isPowerUser = loadUser.user.roles.some((role) => roles.indexOf(role) !== -1)
if (!isPowerUser) {
// list of all project statuses
const statuses = PROJECT_STATUS.map((item) => item.value)
// statuses to be excluded for non power users
const excluded = [PROJECT_STATUS_CANCELLED]
// updates the criteria with status filter
_.set(requestCriteria, 'status', `in(${_.difference(statuses, excluded)})`)
}
}

return dispatch({
type: GET_PROJECTS,
payload: getProjects(requestCriteria, pageNum),
payload: getProjects(criteria, pageNum),
meta: {
// keep previous to enable the loading without paginator (infinite scroll)
keepPrevious : pageNum !== 1
Expand Down
65 changes: 35 additions & 30 deletions src/projects/list/components/Projects/ProjectListNavHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,44 @@ export default class ProjectListNavHeader extends Component {
)
)}
</MediaQuery>
<div className="primary-filter">
<div className="tc-switch clearfix">
<SwitchButton
onChange={ this.handleMyProjectsFilter }
label="My projects"
name="my-projects-only"
checked={this.props.criteria.memberOnly}
/>
{(!this.props.isCustomer) &&
<div className="primary-filter">
<div className="tc-switch clearfix">
<SwitchButton
onChange={ this.handleMyProjectsFilter }
label="My projects"
name="my-projects-only"
checked={this.props.criteria.memberOnly}
/>
</div>
</div>
</div>
}
</div>
<div className="right-wrapper">
{(!this.props.isCustomer) &&
<div className="right-wrapper">

<div className="primary-filter">
<div className="tc-switch clearfix">
<SwitchButton
onChange={ this.handleMyProjectsFilter }
label="My projects"
name="my-projects-only"
checked={this.props.criteria.memberOnly}
/>
<div className="primary-filter">
<div className="tc-switch clearfix">
<SwitchButton
onChange={ this.handleMyProjectsFilter }
label="My projects"
name="my-projects-only"
checked={this.props.criteria.memberOnly}
/>
</div>
</div>
<div className="list-nav-item nav-icon">
<a href="javascript;" data-view="grid" onClick={this.switchViews} className={`list-nav-btn sm right ${(this.state.selectedView === 'grid') ? 'active' : ''}`}>
<GridView className="grid-view-ico" />
</a>
</div>
<div className="list-nav-item nav-icon">
<a href="javascript;" data-view="card" onClick={this.switchViews} className={`list-nav-btn sm right ${(this.state.selectedView === 'card') ? 'active' : ''}`}>
<CardView className="card-view-ico" />
</a>
</div>
</div>
<div className="list-nav-item nav-icon">
<a href="javascript;" data-view="grid" onClick={this.switchViews} className={`list-nav-btn sm right ${(this.state.selectedView === 'grid') ? 'active' : ''}`}>
<GridView className="grid-view-ico" />
</a>
</div>
<div className="list-nav-item nav-icon">
<a href="javascript;" data-view="card" onClick={this.switchViews} className={`list-nav-btn sm right ${(this.state.selectedView === 'card') ? 'active' : ''}`}>
<CardView className="card-view-ico" />
</a>
</div>
</div>
}
</nav>
)
}
Expand All @@ -131,5 +135,6 @@ ProjectListNavHeader.propTypes = {
criteria: PT.object.isRequired,
history: PT.object.isRequired,
setInfiniteAutoload: PT.func.isRequired,
loadProjects: PT.func.isRequired
loadProjects: PT.func.isRequired,
isCustomer: PT.bool.isRequired
}
7 changes: 4 additions & 3 deletions src/projects/list/components/Projects/Projects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class Projects extends Component {
}

render() {
const { isPowerUser, isLoading, totalCount, criteria, projectsListView, setProjectsListView, setInfiniteAutoload, loadProjects, history, orgConfig } = this.props
const { isPowerUser, isCustomer, isLoading, totalCount, criteria, projectsListView, setProjectsListView, setInfiniteAutoload, loadProjects, history, orgConfig } = this.props
// show walk through if user is customer and no projects were returned
// for default filters
const showWalkThrough = !isLoading && totalCount === 0 &&
Expand Down Expand Up @@ -244,8 +244,8 @@ class Projects extends Component {
<div>
<section className="">
<div className="container">
{(isPowerUser && !showWalkThrough) &&
<ProjectListNavHeader applyFilters={this.applyFilters} selectedView={chosenView} changeView={setProjectsListView} currentStatus={currentStatus} criteria={criteria} setInfiniteAutoload={setInfiniteAutoload} loadProjects={loadProjects} history={history}/>}
{(!showWalkThrough) &&
<ProjectListNavHeader applyFilters={this.applyFilters} selectedView={chosenView} changeView={setProjectsListView} currentStatus={currentStatus} criteria={criteria} setInfiniteAutoload={setInfiniteAutoload} loadProjects={loadProjects} history={history} isCustomer={isCustomer}/>}
{ showWalkThrough ?
(
<Walkthrough newProjectLink={getNewProjectLink(orgConfig)} />
Expand Down Expand Up @@ -289,6 +289,7 @@ const mapStateToProps = ({ projectSearch, members, loadUser, projectState, templ
infiniteAutoload: projectSearch.infiniteAutoload,
projectsListView: projectSearch.projectsListView,
isPowerUser,
isCustomer : !isPowerUser,
gridView : isPowerUser,
refresh : projectSearch.refresh,
projectTemplates: templates.projectTemplates,
Expand Down