SavePageControls.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 hasSlackConfig = config.hasSlackConfig;
  43. const isAclEnabled = config.isAclEnabled;
  44. const labelSubmitButton = this.state.pageId == null ? t('Create') : t('Update');
  45. const labelOverwriteScopes = t('page_edit.overwrite_scopes', { operation: labelSubmitButton });
  46. return (
  47. <div className="d-flex align-items-center form-inline">
  48. {hasSlackConfig
  49. && (
  50. <div className="mr-2">
  51. <SlackNotification
  52. ref={(c) => { this.slackNotification = c }}
  53. crowi={this.props.crowi}
  54. pageId={this.props.pageId}
  55. pagePath={this.props.pagePath}
  56. isSlackEnabled={false}
  57. slackChannels={this.props.slackChannels}
  58. />
  59. </div>
  60. )
  61. }
  62. {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.getWrappedInstance();
  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. pagePath: PropTypes.string,
  104. slackChannels: PropTypes.string,
  105. // for GrantSelector
  106. grant: PropTypes.number,
  107. grantGroupId: PropTypes.string,
  108. grantGroupName: PropTypes.string,
  109. };
  110. export default translate()(SavePageControls);