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
Fredrik Strand Oseberg dbed06f300 Feat/material UI (#250)
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
Co-authored-by: Christopher Kolstad <git@chriswk.no>
2021-03-30 15:14:02 +02:00

44 lines
1.1 KiB
JavaScript

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