SavePageControls.jsx 3.5 KB

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