From 24d9bb03b1fbf9fef3eb85a8b617ad9a2f830aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Thu, 11 Mar 2021 16:07:06 +0100 Subject: [PATCH] fix: should fetch projects once to make sure we know about projects --- .../feature/list/project-component.jsx | 24 ++++++++++++------- .../feature/list/project-container.jsx | 2 ++ frontend/vercel.json | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/frontend/src/component/feature/list/project-component.jsx b/frontend/src/component/feature/list/project-component.jsx index ddc313e74c..bcd4690c6c 100644 --- a/frontend/src/component/feature/list/project-component.jsx +++ b/frontend/src/component/feature/list/project-component.jsx @@ -1,7 +1,8 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { Menu, MenuItem } from 'react-mdl'; import { DropdownButton } from '../../common'; import PropTypes from 'prop-types'; +import { enable } from 'debug'; const ALL_PROJECTS = { id: '*', name: '> All projects' }; @@ -13,20 +14,26 @@ function projectItem(selectedId, item) { ); } -function ProjectComponent({ projects, currentProjectId, updateCurrentProject }) { +function ProjectComponent({ projects, currentProjectId, updateCurrentProject, enabled, fetchProjects }) { function setProject(v) { const id = typeof v === 'string' ? v.trim() : ''; updateCurrentProject(id); } - if (!projects || projects.length === 1) { + useEffect(() => { + if (enabled) { + fetchProjects(); + } + }, [enabled]); + + if (!enabled) { return null; } // TODO fixme - let curentProject = projects.find(i => i.id === currentProjectId); - if (!curentProject) { - curentProject = ALL_PROJECTS; + let currentProject = projects.find(i => i.id === currentProjectId); + if (!currentProject) { + currentProject = ALL_PROJECTS; } return ( @@ -34,7 +41,7 @@ function ProjectComponent({ projects, currentProjectId, updateCurrentProject }) className="mdl-color--amber-50" style={{ textTransform: 'none', fontWeight: 'normal' }} id="project" - label={`${curentProject.name}`} + label={`${currentProject.name}`} title="Select project" /> setProject(e.target.getAttribute('data-target'))} style={{ width: '168px' }} > - + {ALL_PROJECTS.name} {projects.map(p => projectItem(currentProjectId, p))} @@ -56,6 +63,7 @@ ProjectComponent.propTypes = { fetchProjects: PropTypes.func.isRequired, currentProjectId: PropTypes.string.isRequired, updateCurrentProject: PropTypes.func.isRequired, + enabled: PropTypes.bool, }; export default ProjectComponent; diff --git a/frontend/src/component/feature/list/project-container.jsx b/frontend/src/component/feature/list/project-container.jsx index ea40511c94..80eca17d19 100644 --- a/frontend/src/component/feature/list/project-container.jsx +++ b/frontend/src/component/feature/list/project-container.jsx @@ -1,8 +1,10 @@ import { connect } from 'react-redux'; import Component from './project-component'; import { fetchProjects } from './../../../store/project/actions'; +import { P } from '../../common/flags'; const mapStateToProps = (state, ownProps) => ({ + enabled: !!state.uiConfig.toJS().flags[P], projects: state.projects.toJS(), currentProjectId: ownProps.settings.currentProjectId || '*', updateCurrentProject: id => ownProps.updateSetting('currentProjectId', id), diff --git a/frontend/vercel.json b/frontend/vercel.json index 78592d1d5c..4e6c15552e 100644 --- a/frontend/vercel.json +++ b/frontend/vercel.json @@ -1,7 +1,7 @@ { "rewrites": [ { "source": "/api/admin/user", "destination": "https://unleash.herokuapp.com/api/admin/user" }, - { "source": "/api/admin/uiconfig", "destination": "https://unleash.herokuapp.com/api/admin/uiconfig" }, + { "source": "/api/admin/ui-config", "destination": "https://unleash.herokuapp.com/api/admin/ui-config" }, { "source": "/api/admin/context", "destination": "https://unleash.herokuapp.com/api/admin/context" }, { "source": "/api/admin/feature-types", "destination": "https://unleash.herokuapp.com/api/admin/feature-types" }, { "source": "/api/admin/strategies", "destination": "https://unleash.herokuapp.com/api/admin/strategies" },