embedded-terminal.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { brightenColor, getNodeColorDark } from '../utils/color-utils';
  4. import { DETAILS_PANEL_WIDTH, DETAILS_PANEL_MARGINS } from '../constants/styles';
  5. import Terminal from './terminal';
  6. class EmeddedTerminal extends React.Component {
  7. constructor(props, context) {
  8. super(props, context);
  9. this.state = {
  10. animated: null,
  11. mounted: null,
  12. };
  13. this.handleTransitionEnd = this.handleTransitionEnd.bind(this);
  14. }
  15. componentDidMount() {
  16. this.mountedTimeout = setTimeout(() => {
  17. this.setState({mounted: true});
  18. });
  19. this.animationTimeout = setTimeout(() => {
  20. this.setState({ animated: true });
  21. }, 2000);
  22. }
  23. componentWillUnmount() {
  24. clearTimeout(this.mountedTimeout);
  25. clearTimeout(this.animationTimeout);
  26. }
  27. getTransform() {
  28. const dx = this.state.mounted ? 0
  29. : window.innerWidth - DETAILS_PANEL_WIDTH - DETAILS_PANEL_MARGINS.right;
  30. return `translateX(${dx}px)`;
  31. }
  32. handleTransitionEnd() {
  33. this.setState({ animated: true });
  34. }
  35. render() {
  36. const { pipe, details } = this.props;
  37. const nodeId = pipe.get('nodeId');
  38. const node = details.get(nodeId);
  39. const d = node && node.details;
  40. const titleBarColor = d && getNodeColorDark(d.rank, d.label, d.pseudo);
  41. const statusBarColor = d && brightenColor(titleBarColor);
  42. const title = d && d.label;
  43. // React unmount/remounts when key changes, this is important for cleaning up
  44. // the term.js and creating a new one for the new pipe.
  45. return (
  46. <div className="tour-step-anchor terminal-embedded">
  47. <div
  48. onTransitionEnd={this.handleTransitionEnd}
  49. className="terminal-animation-wrapper"
  50. style={{transform: this.getTransform()}}>
  51. <Terminal
  52. key={pipe.get('id')}
  53. pipe={pipe}
  54. connect={this.state.animated}
  55. titleBarColor={titleBarColor}
  56. statusBarColor={statusBarColor}
  57. title={title} />
  58. </div>
  59. </div>
  60. );
  61. }
  62. }
  63. function mapStateToProps(state) {
  64. return {
  65. details: state.get('nodeDetails'),
  66. pipe: state.get('controlPipes').last()
  67. };
  68. }
  69. export default connect(mapStateToProps)(EmeddedTerminal);