GrowiZipImportItem.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. // eslint-disable-next-line no-unused-vars
  4. import { withTranslation } from 'react-i18next';
  5. import GrowiZipImportOption from '../../../models/GrowiZipImportOption';
  6. export const DEFAULT_MODE = 'insert';
  7. export default class GrowiZipImportItem extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. this.changeHandler = this.changeHandler.bind(this);
  11. this.modeSelectedHandler = this.modeSelectedHandler.bind(this);
  12. }
  13. get currentModeLabel() {
  14. const { option } = this.props;
  15. const { mode } = option;
  16. // convert 'insert' -> 'Insert'
  17. return mode.substring(0, 1).toUpperCase() + mode.substring(1);
  18. }
  19. changeHandler(e) {
  20. const { collectionName, onChange } = this.props;
  21. if (onChange != null) {
  22. onChange(collectionName, e.target.checked);
  23. }
  24. }
  25. modeSelectedHandler(mode) {
  26. const { collectionName, onOptionChange } = this.props;
  27. if (onOptionChange == null) {
  28. return;
  29. }
  30. const { option } = this.props;
  31. option.mode = mode;
  32. onOptionChange(collectionName, option);
  33. }
  34. renderControls() {
  35. const {
  36. collectionName, isSelected,
  37. } = this.props;
  38. return (
  39. <div className="d-flex justify-content-between align-items-center">
  40. {/* left */}
  41. <div className="checkbox checkbox-info">
  42. <input
  43. type="checkbox"
  44. id={collectionName}
  45. name={collectionName}
  46. className="form-check-input"
  47. value={collectionName}
  48. checked={isSelected}
  49. onChange={this.changeHandler}
  50. />
  51. <label className="text-capitalize form-check-label" htmlFor={collectionName}>
  52. {collectionName}
  53. </label>
  54. </div>
  55. {/* right */}
  56. <span className="d-inline-flex align-items-center">
  57. Mode:
  58. <div className="dropdown d-inline-block">
  59. <button className="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
  60. {this.currentModeLabel}
  61. <span className="caret ml-2"></span>
  62. </button>
  63. <ul className="dropdown-menu" aria-labelledby="dropdownMenu1">
  64. <li><a href="#" onClick={() => this.modeSelectedHandler('insert')}>Insert</a></li>
  65. <li><a href="#" onClick={() => this.modeSelectedHandler('upsert')}>Upsert</a></li>
  66. <li><a href="#" onClick={() => this.modeSelectedHandler('flushAndInsert')}>Flush and Insert</a></li>
  67. </ul>
  68. </div>
  69. </span>
  70. </div>
  71. );
  72. }
  73. render() {
  74. const {
  75. isSelected,
  76. } = this.props;
  77. const cotrols = this.renderControls();
  78. return (
  79. <div className="panel panel-default">
  80. <div className="panel-heading">
  81. {cotrols}
  82. </div>
  83. { isSelected && (
  84. <div className="panel-body">
  85. Ready
  86. </div>
  87. ) }
  88. </div>
  89. );
  90. }
  91. }
  92. GrowiZipImportItem.propTypes = {
  93. collectionName: PropTypes.string.isRequired,
  94. isSelected: PropTypes.bool.isRequired,
  95. option: PropTypes.instanceOf(GrowiZipImportOption).isRequired,
  96. onChange: PropTypes.func,
  97. onOptionChange: PropTypes.func,
  98. };