@@ -3,7 +3,7 @@ import React, { Component } from 'react'
33import PropTypes from 'prop-types'
44import { connect } from 'react-redux'
55import Sidebar from '../../components/Sidebar'
6- import { loadProjects , setActiveProject , resetSidebarActiveParams } from '../../actions/sidebar'
6+ import { loadProjects , setActiveProject , resetSidebarActiveParams , unloadProjects } from '../../actions/sidebar'
77
88class SidebarContainer extends Component {
99 constructor ( props ) {
@@ -26,10 +26,32 @@ class SidebarContainer extends Component {
2626 }
2727
2828 componentWillReceiveProps ( nextProps ) {
29- const { projectId, isLoading } = nextProps
30- if ( this . props . projectId !== projectId && ! projectId && ! isLoading ) {
31- this . props . loadProjects ( )
29+ const { projectId, isLoading, selfServe, projects } = nextProps
30+
31+ // if we're viewing a specific project,
32+ // or we're viewing the self serve page,
33+ // or if the project is already loading,
34+ // don't load the projects
35+ if ( ! ! projectId || selfServe || isLoading ) {
36+ // if we're not in the middle of loading,
37+ // and we have projects to unload,
38+ // unload them
39+ if ( ! isLoading && ! ! projects && ! ! projects . length ) {
40+ this . props . unloadProjects ( )
41+ }
42+
43+ return
3244 }
45+
46+ // if we don't have a project id
47+ // and we already have projects in the list,
48+ // don't load the projects again
49+ if ( ! projectId && ! ! projects && ! ! projects . length ) {
50+ return
51+ }
52+
53+ // now it's okay to load the projects
54+ this . props . loadProjects ( )
3355 }
3456
3557 updateProjectName ( val ) {
@@ -38,7 +60,7 @@ class SidebarContainer extends Component {
3860 }
3961
4062 render ( ) {
41- const { isLoading, setActiveProject, projectId, resetSidebarActiveParams, projects } = this . props
63+ const { isLoading, setActiveProject, projectId, resetSidebarActiveParams, projects, selfServe , unloadProjects } = this . props
4264 const { searchProjectName } = this . state
4365
4466 return (
@@ -50,6 +72,8 @@ class SidebarContainer extends Component {
5072 resetSidebarActiveParams = { resetSidebarActiveParams }
5173 updateProjectsList = { this . updateProjectName }
5274 searchProjectName = { searchProjectName }
75+ selfServe = { selfServe }
76+ unloadProjects = { unloadProjects }
5377 />
5478 )
5579 }
@@ -59,6 +83,7 @@ SidebarContainer.propTypes = {
5983 projects : PropTypes . arrayOf ( PropTypes . shape ( ) ) ,
6084 isLoading : PropTypes . bool ,
6185 loadProjects : PropTypes . func ,
86+ unloadProjects : PropTypes . func ,
6287 activeProjectId : PropTypes . number ,
6388 setActiveProject : PropTypes . func ,
6489 projectId : PropTypes . string ,
@@ -72,6 +97,7 @@ const mapStateToProps = ({ sidebar }) => ({
7297
7398const mapDispatchToProps = {
7499 loadProjects,
100+ unloadProjects,
75101 setActiveProject,
76102 resetSidebarActiveParams
77103}
0 commit comments