SavePageControls.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } 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. const config = this.props.crowi.getConfig();
  16. this.hasSlackConfig = config.hasSlackConfig;
  17. this.isAclEnabled = config.isAclEnabled;
  18. this.getCurrentOptionsToSave = this.getCurrentOptionsToSave.bind(this);
  19. this.submit = this.submit.bind(this);
  20. this.submitAndOverwriteScopesOfDescendants = this.submitAndOverwriteScopesOfDescendants.bind(this);
  21. }
  22. componentWillMount() {
  23. }
  24. getCurrentOptionsToSave() {
  25. let currentOptions = this.grantSelector.getCurrentOptionsToSave();
  26. if (this.hasSlackConfig) {
  27. currentOptions = Object.assign(currentOptions, this.slackNotification.getCurrentOptionsToSave());
  28. }
  29. return currentOptions;
  30. }
  31. /**
  32. * update pageId of state
  33. * @param {string} pageId
  34. */
  35. setPageId(pageId) {
  36. this.setState({ pageId });
  37. }
  38. submit() {
  39. this.props.crowi.setIsDocSaved(true);
  40. this.props.onSubmit();
  41. }
  42. submitAndOverwriteScopesOfDescendants() {
  43. this.props.onSubmit({ overwriteScopesOfDescendants: true });
  44. }
  45. render() {
  46. const { t } = this.props;
  47. const labelSubmitButton = this.state.pageId == null ? t('Create') : t('Update');
  48. const labelOverwriteScopes = t('page_edit.overwrite_scopes', { operation: labelSubmitButton });
  49. return (
  50. <div className="d-flex align-items-center form-inline">
  51. {this.hasSlackConfig
  52. && (
  53. <div className="mr-2">
  54. <SlackNotification
  55. ref={(c) => { this.slackNotification = c }}
  56. isSlackEnabled={false}
  57. slackChannels={this.props.slackChannels}
  58. />
  59. </div>
  60. )
  61. }
  62. {this.isAclEnabled
  63. && (
  64. <div className="mr-2">
  65. <GrantSelector
  66. crowi={this.props.crowi}
  67. ref={(elem) => {
  68. if (this.grantSelector == null) {
  69. this.grantSelector = elem;
  70. }
  71. }}
  72. grant={this.props.grant}
  73. grantGroupId={this.props.grantGroupId}
  74. grantGroupName={this.props.grantGroupName}
  75. />
  76. </div>
  77. )
  78. }
  79. <ButtonToolbar>
  80. <SplitButton
  81. id="spl-btn-submit"
  82. bsStyle="primary"
  83. className="btn-submit"
  84. dropup
  85. pullRight
  86. onClick={this.submit}
  87. title={labelSubmitButton}
  88. >
  89. <MenuItem eventKey="1" onClick={this.submitAndOverwriteScopesOfDescendants}>{labelOverwriteScopes}</MenuItem>
  90. {/* <MenuItem divider /> */}
  91. </SplitButton>
  92. </ButtonToolbar>
  93. </div>
  94. );
  95. }
  96. }
  97. SavePageControls.propTypes = {
  98. t: PropTypes.func.isRequired, // i18next
  99. crowi: PropTypes.object.isRequired,
  100. onSubmit: PropTypes.func.isRequired,
  101. pageId: PropTypes.string,
  102. // for SlackNotification
  103. slackChannels: PropTypes.string,
  104. // for GrantSelector
  105. grant: PropTypes.number,
  106. grantGroupId: PropTypes.string,
  107. grantGroupName: PropTypes.string,
  108. };
  109. export default withTranslation(null, { withRef: true })(SavePageControls);