1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/feature/project-select-component.jsx

44 lines
1.1 KiB
React
Raw Normal View History

2020-11-20 15:35:41 +01:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import MySelect from '../common/select';
2020-11-20 15:35:41 +01:00
class ProjectSelectComponent extends Component {
componentDidMount() {
const { fetchProjects, projects, enabled } = this.props;
if (projects[0].initial && enabled) {
fetchProjects();
2020-11-20 15:35:41 +01:00
}
}
render() {
const { value, projects, onChange, enabled } = this.props;
2020-11-20 15:35:41 +01:00
if (!enabled) {
2020-11-20 15:35:41 +01:00
return null;
}
const options = projects.map(t => ({
key: t.id,
label: t.name,
title: t.description,
}));
2020-11-20 15:35:41 +01:00
if (value && !options.find(o => o.key === value)) {
2020-11-20 15:35:41 +01:00
options.push({ key: value, label: value });
}
return <MySelect label="Project" options={options} value={value} onChange={onChange} />;
2020-11-20 15:35:41 +01:00
}
}
ProjectSelectComponent.propTypes = {
value: PropTypes.string,
filled: PropTypes.bool,
enabled: PropTypes.bool,
2020-11-20 15:35:41 +01:00
projects: PropTypes.array.isRequired,
fetchProjects: PropTypes.func,
onChange: PropTypes.func.isRequired,
};
export default ProjectSelectComponent;