2021-04-12 13:32:25 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
|
import { noop } from "lodash";
|
2016-11-17 17:12:41 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
import labelInterface from "interfaces/label";
|
|
|
|
|
import PanelGroupItem from "components/side_panels/HostSidePanel/PanelGroupItem";
|
|
|
|
|
import statusLabelsInterface from "interfaces/status_labels";
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
|
class PanelGroup extends Component {
|
|
|
|
|
static propTypes = {
|
|
|
|
|
groupItems: PropTypes.arrayOf(labelInterface),
|
|
|
|
|
onLabelClick: PropTypes.func,
|
2020-03-30 02:19:54 +00:00
|
|
|
selectedFilter: PropTypes.string,
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels: statusLabelsInterface,
|
2016-12-22 19:26:18 +00:00
|
|
|
type: PropTypes.string,
|
2016-11-17 17:12:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
|
onLabelClick: noop,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderGroupItem = (item) => {
|
2021-04-12 13:32:25 +00:00
|
|
|
const { onLabelClick, selectedFilter, statusLabels, type } = this.props;
|
2021-09-01 01:02:23 +00:00
|
|
|
const selected =
|
|
|
|
|
(item && item.slug === selectedFilter) || type === selectedFilter;
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<PanelGroupItem
|
|
|
|
|
isSelected={selected}
|
|
|
|
|
item={item}
|
|
|
|
|
key={item.display_text}
|
|
|
|
|
onLabelClick={onLabelClick(item)}
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels={statusLabels}
|
2016-12-22 19:26:18 +00:00
|
|
|
type={type}
|
2016-11-17 17:12:41 +00:00
|
|
|
/>
|
|
|
|
|
);
|
2021-04-12 13:32:25 +00:00
|
|
|
};
|
2016-11-17 17:12:41 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
render() {
|
2020-11-30 17:17:55 +00:00
|
|
|
const { groupItems, type } = this.props;
|
2016-11-17 17:12:41 +00:00
|
|
|
const { renderGroupItem } = this;
|
2021-04-12 13:32:25 +00:00
|
|
|
const baseClass = "panel-group";
|
2016-11-17 17:12:41 +00:00
|
|
|
|
2020-12-04 20:19:08 +00:00
|
|
|
let multipleLabelsClass = baseClass;
|
2021-04-12 13:32:25 +00:00
|
|
|
if (type === "label" && groupItems.length > 6) {
|
2020-12-04 20:19:08 +00:00
|
|
|
multipleLabelsClass = `${baseClass}__${type}--scroll-labels`;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
return (
|
2021-04-12 13:32:25 +00:00
|
|
|
<div
|
|
|
|
|
className={`${baseClass} ${baseClass}__${type} ${multipleLabelsClass}`}
|
|
|
|
|
>
|
2016-11-17 17:12:41 +00:00
|
|
|
{groupItems.map((item) => {
|
|
|
|
|
return renderGroupItem(item);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default PanelGroup;
|