1
0
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:
Ivar Conradi Østhus 2021-03-11 16:07:06 +01:00
parent b9e6586c30
commit 24d9bb03b1
3 changed files with 19 additions and 9 deletions

View File

@ -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 (
<React.Fragment>
@ -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"
/>
<Menu
@ -42,7 +49,7 @@ function ProjectComponent({ projects, currentProjectId, updateCurrentProject })
onClick={e => setProject(e.target.getAttribute('data-target'))}
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}
</MenuItem>
{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;

View File

@ -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),

View File

@ -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" },