blob: b32c8b1df51da6c9460c8f0adf8da88275abcf58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import PortfolioListComponent from '../../../../components/app/sidebars/project/PortfolioListComponent'
import { deletePortfolio, setCurrentPortfolio } from '../../../../actions/portfolios'
import { openNewPortfolioModal } from '../../../../actions/modals/portfolios'
import { getState } from '../../../../util/state-utils'
import { setCurrentTopology } from '../../../../actions/topology/building'
const mapStateToProps = (state) => {
let portfolios = state.objects.project[state.currentProjectId]
? state.objects.project[state.currentProjectId].portfolioIds.map((t) => state.objects.portfolio[t])
: []
if (portfolios.filter((t) => !t).length > 0) {
portfolios = []
}
return {
currentProjectId: state.currentProjectId,
currentPortfolioId: state.currentPortfolioId,
portfolios,
}
}
const mapDispatchToProps = (dispatch, ownProps) => {
return {
onNewPortfolio: () => {
dispatch(openNewPortfolioModal())
},
onChoosePortfolio: (portfolioId) => {
dispatch(setCurrentPortfolio(portfolioId))
},
onDeletePortfolio: async (id) => {
if (id) {
const state = await getState(dispatch)
dispatch(deletePortfolio(id))
dispatch(setCurrentTopology(state.objects.project[state.currentProjectId].topologyIds[0]))
ownProps.history.push(`/projects/${state.currentProjectId}`)
}
},
}
}
const PortfolioListContainer = withRouter(connect(mapStateToProps, mapDispatchToProps)(PortfolioListComponent))
export default PortfolioListContainer
|