mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
fix: should fetch projects once to make sure we know about projects
This commit is contained in:
parent
b9e6586c30
commit
24d9bb03b1
@ -1,7 +1,8 @@
|
|||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { Menu, MenuItem } from 'react-mdl';
|
import { Menu, MenuItem } from 'react-mdl';
|
||||||
import { DropdownButton } from '../../common';
|
import { DropdownButton } from '../../common';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { enable } from 'debug';
|
||||||
|
|
||||||
const ALL_PROJECTS = { id: '*', name: '> All projects' };
|
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) {
|
function setProject(v) {
|
||||||
const id = typeof v === 'string' ? v.trim() : '';
|
const id = typeof v === 'string' ? v.trim() : '';
|
||||||
updateCurrentProject(id);
|
updateCurrentProject(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!projects || projects.length === 1) {
|
useEffect(() => {
|
||||||
|
if (enabled) {
|
||||||
|
fetchProjects();
|
||||||
|
}
|
||||||
|
}, [enabled]);
|
||||||
|
|
||||||
|
if (!enabled) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO fixme
|
// TODO fixme
|
||||||
let curentProject = projects.find(i => i.id === currentProjectId);
|
let currentProject = projects.find(i => i.id === currentProjectId);
|
||||||
if (!curentProject) {
|
if (!currentProject) {
|
||||||
curentProject = ALL_PROJECTS;
|
currentProject = ALL_PROJECTS;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
@ -34,7 +41,7 @@ function ProjectComponent({ projects, currentProjectId, updateCurrentProject })
|
|||||||
className="mdl-color--amber-50"
|
className="mdl-color--amber-50"
|
||||||
style={{ textTransform: 'none', fontWeight: 'normal' }}
|
style={{ textTransform: 'none', fontWeight: 'normal' }}
|
||||||
id="project"
|
id="project"
|
||||||
label={`${curentProject.name}`}
|
label={`${currentProject.name}`}
|
||||||
title="Select project"
|
title="Select project"
|
||||||
/>
|
/>
|
||||||
<Menu
|
<Menu
|
||||||
@ -42,7 +49,7 @@ function ProjectComponent({ projects, currentProjectId, updateCurrentProject })
|
|||||||
onClick={e => setProject(e.target.getAttribute('data-target'))}
|
onClick={e => setProject(e.target.getAttribute('data-target'))}
|
||||||
style={{ width: '168px' }}
|
style={{ width: '168px' }}
|
||||||
>
|
>
|
||||||
<MenuItem disabled={curentProject === ALL_PROJECTS} data-target={ALL_PROJECTS.id}>
|
<MenuItem disabled={currentProject === ALL_PROJECTS} data-target={ALL_PROJECTS.id}>
|
||||||
{ALL_PROJECTS.name}
|
{ALL_PROJECTS.name}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{projects.map(p => projectItem(currentProjectId, p))}
|
{projects.map(p => projectItem(currentProjectId, p))}
|
||||||
@ -56,6 +63,7 @@ ProjectComponent.propTypes = {
|
|||||||
fetchProjects: PropTypes.func.isRequired,
|
fetchProjects: PropTypes.func.isRequired,
|
||||||
currentProjectId: PropTypes.string.isRequired,
|
currentProjectId: PropTypes.string.isRequired,
|
||||||
updateCurrentProject: PropTypes.func.isRequired,
|
updateCurrentProject: PropTypes.func.isRequired,
|
||||||
|
enabled: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ProjectComponent;
|
export default ProjectComponent;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import Component from './project-component';
|
import Component from './project-component';
|
||||||
import { fetchProjects } from './../../../store/project/actions';
|
import { fetchProjects } from './../../../store/project/actions';
|
||||||
|
import { P } from '../../common/flags';
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => ({
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
|
enabled: !!state.uiConfig.toJS().flags[P],
|
||||||
projects: state.projects.toJS(),
|
projects: state.projects.toJS(),
|
||||||
currentProjectId: ownProps.settings.currentProjectId || '*',
|
currentProjectId: ownProps.settings.currentProjectId || '*',
|
||||||
updateCurrentProject: id => ownProps.updateSetting('currentProjectId', id),
|
updateCurrentProject: id => ownProps.updateSetting('currentProjectId', id),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"rewrites": [
|
"rewrites": [
|
||||||
{ "source": "/api/admin/user", "destination": "https://unleash.herokuapp.com/api/admin/user" },
|
{ "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/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/feature-types", "destination": "https://unleash.herokuapp.com/api/admin/feature-types" },
|
||||||
{ "source": "/api/admin/strategies", "destination": "https://unleash.herokuapp.com/api/admin/strategies" },
|
{ "source": "/api/admin/strategies", "destination": "https://unleash.herokuapp.com/api/admin/strategies" },
|
||||||
|
Loading…
Reference in New Issue
Block a user