SavePageControls.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { translate } from 'react-i18next';
  4. import ButtonToolbar from 'react-bootstrap/es/ButtonToolbar';
  5. import SplitButton from 'react-bootstrap/es/SplitButton';
  6. import MenuItem from 'react-bootstrap/es/MenuItem';
  7. import SlackNotification from './SlackNotification';
  8. import GrantSelector from './SavePageControls/GrantSelector';
  9. class SavePageControls extends React.PureComponent {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. pageId: this.props.pageId,
  14. };
  15. this.getCurrentOptionsToSave = this.getCurrentOptionsToSave.bind(this);
  16. this.submit = this.submit.bind(this);
  17. this.submitAndOverwriteScopesOfDescendants = this.submitAndOverwriteScopesOfDescendants.bind(this);
  18. }
  19. componentWillMount() {
  20. }
  21. getCurrentOptionsToSave() {
  22. const slackNotificationOptions = this.refs.slackNotification.getCurrentOptionsToSave();
  23. const grantSelectorOptions = this.refs.grantSelector.getCurrentOptionsToSave();
  24. return Object.assign(slackNotificationOptions, grantSelectorOptions);
  25. }
  26. /**
  27. * update pageId of state
  28. * @param {string} pageId
  29. */
  30. setPageId(pageId) {
  31. this.setState({pageId});
  32. }
  33. submit() {
  34. this.props.onSubmit();
  35. }
  36. submitAndOverwriteScopesOfDescendants() {
  37. this.props.onSubmit({ overwriteScopesOfDescendants: true });
  38. }
  39. render() {
  40. const { t } = this.props;
  41. const config = this.props.crowi.getConfig();
  42. const isAclEnabled = config.isAclEnabled;
  43. const labelSubmitButton = this.state.pageId == null ? t('Create') : t('Update');
  44. const labelOverwriteScopes = t('page_edit.overwrite_scopes', { operation: labelSubmitButton });
  45. return (
  46. <div className="d-flex align-items-center form-inline">
  47. <div className="mr-2">
  48. <SlackNotification
  49. ref='slackNotification'
  50. crowi={this.props.crowi}
  51. pageId={this.props.pageId}
  52. pagePath={this.props.pagePath}
  53. isSlackEnabled={false}
  54. slackChannels={this.props.slackChannels} />
  55. </div>
  56. {isAclEnabled &&
  57. <div className="mr-2">
  58. <GrantSelector crowi={this.props.crowi}
  59. ref={(elem) => {
  60. if (this.refs.grantSelector == null) {
  61. this.refs.grantSelector = elem.getWrappedInstance();
  62. }
  63. }}
  64. grant={this.props.grant}
  65. grantGroupId={this.props.grantGroupId}
  66. grantGroupName={this.props.grantGroupName} />
  67. </div>
  68. }
  69. <ButtonToolbar>
  70. <SplitButton id="spl-btn-submit" bsStyle="primary" className="btn-submit" dropup pullRight onClick={this.submit}
  71. title={labelSubmitButton}>
  72. <MenuItem eventKey="1" onClick={this.submitAndOverwriteScopesOfDescendants}>{labelOverwriteScopes}</MenuItem>
  73. {/* <MenuItem divider /> */}
  74. </SplitButton>
  75. </ButtonToolbar>
  76. </div>
  77. );
  78. }
  79. }
  80. SavePageControls.propTypes = {
  81. t: PropTypes.func.isRequired, // i18next
  82. crowi: PropTypes.object.isRequired,
  83. onSubmit: PropTypes.func.isRequired,
  84. pageId: PropTypes.string,
  85. // for SlackNotification
  86. pagePath: PropTypes.string,
  87. slackChannels: PropTypes.string,
  88. // for GrantSelector
  89. grant: PropTypes.number,
  90. grantGroupId: PropTypes.string,
  91. grantGroupName: PropTypes.string,
  92. };
  93. export default translate()(SavePageControls);