SavePageControls.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.slackNotification.getCurrentOptionsToSave();
  23. const grantSelectorOptions = this.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={(c) => { this.slackNotification = c }}
  50. isSlackEnabled={false}
  51. slackChannels={this.props.slackChannels}
  52. />
  53. </div>
  54. {isAclEnabled
  55. && (
  56. <div className="mr-2">
  57. <GrantSelector
  58. crowi={this.props.crowi}
  59. ref={(elem) => {
  60. if (this.grantSelector == null) {
  61. this.grantSelector = elem.getWrappedInstance();
  62. }
  63. }}
  64. grant={this.props.grant}
  65. grantGroupId={this.props.grantGroupId}
  66. grantGroupName={this.props.grantGroupName}
  67. />
  68. </div>
  69. )
  70. }
  71. <ButtonToolbar>
  72. <SplitButton
  73. id="spl-btn-submit"
  74. bsStyle="primary"
  75. className="btn-submit"
  76. dropup
  77. pullRight
  78. onClick={this.submit}
  79. title={labelSubmitButton}
  80. >
  81. <MenuItem eventKey="1" onClick={this.submitAndOverwriteScopesOfDescendants}>{labelOverwriteScopes}</MenuItem>
  82. {/* <MenuItem divider /> */}
  83. </SplitButton>
  84. </ButtonToolbar>
  85. </div>
  86. );
  87. }
  88. }
  89. SavePageControls.propTypes = {
  90. t: PropTypes.func.isRequired, // i18next
  91. crowi: PropTypes.object.isRequired,
  92. onSubmit: PropTypes.func.isRequired,
  93. pageId: PropTypes.string,
  94. // for SlackNotification
  95. slackChannels: PropTypes.string,
  96. // for GrantSelector
  97. grant: PropTypes.number,
  98. grantGroupId: PropTypes.string,
  99. grantGroupName: PropTypes.string,
  100. };
  101. export default translate()(SavePageControls);