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-03-30 15:14:02 +02:00
|
|
|
const { value, projects, onChange, 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;
|
|
|
|
}
|
|
|
|
|
2021-03-30 15:14:02 +02:00
|
|
|
const options = projects.map(t => ({
|
|
|
|
key: t.id,
|
|
|
|
label: t.name,
|
|
|
|
title: t.description,
|
|
|
|
}));
|
2020-11-20 15:35:41 +01:00
|
|
|
|
2021-03-30 15:14:02 +02:00
|
|
|
if (value && !options.find(o => o.key === value)) {
|
2020-11-20 15:35:41 +01:00
|
|
|
options.push({ key: value, label: value });
|
|
|
|
}
|
|
|
|
|
2021-03-30 15:14:02 +02:00
|
|
|
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,
|
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;
|