node-details-info.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { Map as makeMap } from 'immutable';
  4. import MatchedText from '../matched-text';
  5. import ShowMore from '../show-more';
  6. import { formatDataType } from '../../utils/string-utils';
  7. class NodeDetailsInfo extends React.Component {
  8. constructor(props, context) {
  9. super(props, context);
  10. this.state = {
  11. expanded: false
  12. };
  13. this.handleClickMore = this.handleClickMore.bind(this);
  14. }
  15. handleClickMore() {
  16. this.setState(prevState => ({
  17. expanded: !prevState.expanded
  18. }));
  19. }
  20. render() {
  21. const { timestamp, matches = makeMap() } = this.props;
  22. let rows = (this.props.rows || []);
  23. let notShown = 0;
  24. const prime = rows.filter(row => row.priority < 10);
  25. if (!this.state.expanded && prime.length < rows.length) {
  26. // check if there is a search match in non-prime fields
  27. const hasNonPrimeMatch = matches && rows.filter(row => row.priority >= 10
  28. && matches.has(row.id)).length > 0;
  29. if (!hasNonPrimeMatch) {
  30. notShown = rows.length - prime.length;
  31. rows = prime;
  32. }
  33. }
  34. return (
  35. <div className="node-details-info">
  36. {rows.map((field) => {
  37. const { value, title } = formatDataType(field, timestamp);
  38. return (
  39. <div className="node-details-info-field" key={field.id}>
  40. <div className="node-details-info-field-label truncate" title={field.label}>
  41. {field.label}
  42. </div>
  43. <div className="node-details-info-field-value truncate" title={title}>
  44. {field.dataType === 'link'
  45. ? (
  46. <a
  47. rel="noopener noreferrer"
  48. target="_blank"
  49. className="truncate node-details-table-node-link"
  50. href={value}>
  51. {value}
  52. </a>
  53. )
  54. : (
  55. <MatchedText
  56. text={value}
  57. truncate={field.truncate}
  58. match={matches.get(field.id)} />
  59. )
  60. }
  61. </div>
  62. </div>
  63. );
  64. })}
  65. <ShowMore
  66. handleClick={this.handleClickMore}
  67. collection={this.props.rows}
  68. expanded={this.state.expanded}
  69. notShown={notShown} />
  70. </div>
  71. );
  72. }
  73. }
  74. function mapStateToProps(state) {
  75. return {
  76. timestamp: state.get('pausedAt'),
  77. };
  78. }
  79. export default connect(mapStateToProps)(NodeDetailsInfo);