details-card.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import NodeDetails from './node-details';
  4. import EmbeddedTerminal from './embedded-terminal';
  5. import {
  6. DETAILS_PANEL_WIDTH as WIDTH,
  7. DETAILS_PANEL_OFFSET as OFFSET,
  8. DETAILS_PANEL_MARGINS as MARGINS
  9. } from '../constants/styles';
  10. class DetailsCard extends React.Component {
  11. constructor(props, context) {
  12. super(props, context);
  13. this.state = {
  14. mounted: null
  15. };
  16. }
  17. componentDidMount() {
  18. setTimeout(() => {
  19. this.setState({mounted: true});
  20. });
  21. }
  22. render() {
  23. console.log(444444444,'details-card')
  24. let transform;
  25. const { origin, showingTerminal } = this.props;
  26. const panelHeight = window.innerHeight - MARGINS.bottom - MARGINS.top;
  27. if (origin && !this.state.mounted) {
  28. // render small panel near origin, will transition into normal panel after being mounted
  29. const scaleY = origin.height / (window.innerHeight - MARGINS.bottom - MARGINS.top) / 2;
  30. const scaleX = origin.width / WIDTH / 2;
  31. const centerX = window.innerWidth - MARGINS.right - (WIDTH / 2);
  32. const centerY = (panelHeight / 2) + MARGINS.top;
  33. const dx = (origin.left + (origin.width / 2)) - centerX;
  34. const dy = (origin.top + (origin.height / 2)) - centerY;
  35. transform = `translate(${dx}px, ${dy}px) scale(${scaleX},${scaleY})`;
  36. } else {
  37. // stack effect: shift top cards to the left, shrink lower cards vertically
  38. const shiftX = -1 * this.props.index * OFFSET;
  39. const position = this.props.cardCount - this.props.index - 1; // reverse index
  40. const scaleY = (position === 0) ? 1 : (panelHeight - (2 * OFFSET * position)) / panelHeight;
  41. if (scaleY !== 1) {
  42. transform = `translateX(${shiftX}px) scaleY(${scaleY})`;
  43. } else {
  44. // scale(1) is sometimes blurry
  45. transform = `translateX(${shiftX}px)`;
  46. }
  47. }
  48. const style = {
  49. left: showingTerminal ? MARGINS.right : null,
  50. transform,
  51. width: showingTerminal ? null : WIDTH
  52. };
  53. return (
  54. <div className="details-wrapper" style={style}>
  55. {showingTerminal && <EmbeddedTerminal />}
  56. <NodeDetails
  57. key={this.props.id}
  58. nodeId={this.props.id}
  59. mounted={this.state.mounted}
  60. renderNodeDetailsExtras={this.props.renderNodeDetailsExtras}
  61. {...this.props}
  62. />
  63. </div>
  64. );
  65. }
  66. }
  67. function mapStateToProps(state, props) {
  68. const pipe = state.get('controlPipes').last();
  69. return {
  70. showingTerminal: pipe && pipe.get('nodeId') === props.id,
  71. };
  72. }
  73. export default connect(mapStateToProps)(DetailsCard);