mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-05 11:11:13 +00:00
Extracted table headers common code on the frontend Fixed the search matching and extracted further common code in the UI
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
import React from 'react';
|
|
import { Map as makeMap } from 'immutable';
|
|
|
|
import { NODE_DETAILS_DATA_ROWS_DEFAULT_LIMIT } from '../../constants/limits';
|
|
import NodeDetailsRelativesLink from './node-details-relatives-link';
|
|
|
|
export default class NodeDetailsRelatives extends React.Component {
|
|
|
|
constructor(props, context) {
|
|
super(props, context);
|
|
this.state = {
|
|
limit: NODE_DETAILS_DATA_ROWS_DEFAULT_LIMIT
|
|
};
|
|
this.handleLimitClick = this.handleLimitClick.bind(this);
|
|
}
|
|
|
|
handleLimitClick(ev) {
|
|
ev.preventDefault();
|
|
const limit = this.state.limit ? 0 : NODE_DETAILS_DATA_ROWS_DEFAULT_LIMIT;
|
|
this.setState({limit});
|
|
}
|
|
|
|
render() {
|
|
let { relatives } = this.props;
|
|
const { matches = makeMap() } = this.props;
|
|
|
|
const limited = this.state.limit > 0 && relatives.length > this.state.limit;
|
|
const showLimitAction = limited || (this.state.limit === 0
|
|
&& relatives.length > NODE_DETAILS_DATA_ROWS_DEFAULT_LIMIT);
|
|
const limitActionText = limited ? 'Show more' : 'Show less';
|
|
if (limited) {
|
|
relatives = relatives.slice(0, this.state.limit);
|
|
}
|
|
|
|
return (
|
|
<div className="node-details-relatives">
|
|
{relatives.map(relative => (
|
|
<NodeDetailsRelativesLink
|
|
key={relative.id}
|
|
match={matches.get(relative.id)}
|
|
{...relative} />))}
|
|
{showLimitAction && <span
|
|
className="node-details-relatives-more"
|
|
onClick={this.handleLimitClick}>
|
|
{limitActionText}
|
|
</span>}
|
|
</div>
|
|
);
|
|
}
|
|
}
|