diff options
Diffstat (limited to 'opendc-web/opendc-web-ui/src/store/hooks/project.js')
| -rw-r--r-- | opendc-web/opendc-web-ui/src/store/hooks/project.js | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/opendc-web/opendc-web-ui/src/store/hooks/project.js b/opendc-web/opendc-web-ui/src/store/hooks/project.js index 0f2f1b66..0db49fdd 100644 --- a/opendc-web/opendc-web-ui/src/store/hooks/project.js +++ b/opendc-web/opendc-web-ui/src/store/hooks/project.js @@ -25,8 +25,54 @@ import { useSelector } from 'react-redux' /** * Return the current active project. */ -export function useProject() { +export function useActiveProject() { return useSelector((state) => state.currentProjectId !== '-1' ? state.objects.project[state.currentProjectId] : undefined ) } + +/** + * Return the active portfolio. + */ +export function useActivePortfolio() { + return useSelector((state) => state.objects.portfolio[state.currentPortfolioId]) +} + +/** + * Return the active scenario. + */ +export function useActiveScenario() { + return useSelector((state) => state.objects.scenario[state.currentScenarioId]) +} + +/** + * Return the portfolios for the specified project id. + */ +export function usePortfolios(projectId) { + return useSelector((state) => { + let portfolios = state.objects.project[projectId] + ? state.objects.project[projectId].portfolioIds.map((t) => state.objects.portfolio[t]) + : [] + if (portfolios.filter((t) => !t).length > 0) { + portfolios = [] + } + + return portfolios + }) +} + +/** + * Return the scenarios for the specified portfolio id. + */ +export function useScenarios(portfolioId) { + return useSelector((state) => { + let scenarios = state.objects.portfolio[portfolioId] + ? state.objects.portfolio[portfolioId].scenarioIds.map((t) => state.objects.scenario[t]) + : [] + if (scenarios.filter((t) => !t).length > 0) { + scenarios = [] + } + + return scenarios + }) +} |
