2020-11-20 15:35:41 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-11-27 22:23:44 +01:00
|
|
|
import MySelect from '../common/select';
|
2020-11-20 15:35:41 +01:00
|
|
|
|
|
|
|
class ProjectSelectComponent extends Component {
|
|
|
|
componentDidMount() {
|
2021-02-24 11:03:18 +01:00
|
|
|
const { fetchProjects, projects, enabled } = this.props;
|
|
|
|
if (projects[0].initial && enabled) {
|
|
|
|
fetchProjects();
|
2020-11-20 15:35:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-02-24 11:03:18 +01:00
|
|
|
const { value, projects, onChange, filled, enabled } = this.props;
|
2020-11-20 15:35:41 +01:00
|
|
|
|
2021-02-24 11:03:18 +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 }));
|
|
|
|
|
|
|
|
if (!options.find(o => o.key === value)) {
|
|
|
|
options.push({ key: value, label: value });
|
|
|
|
}
|
|
|
|
|
|
|
|
return <MySelect label="Project" options={options} value={value} onChange={onChange} filled={filled} />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectSelectComponent.propTypes = {
|
|
|
|
value: PropTypes.string,
|
|
|
|
filled: PropTypes.bool,
|
2021-02-24 11:03:18 +01:00
|
|
|
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;
|