import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import { UncontrolledButtonDropdown, Button, DropdownToggle, DropdownMenu, DropdownItem, } from 'reactstrap'; import loggerFactory from '@alias/logger'; import PageContainer from '../services/PageContainer'; import AppContainer from '../services/AppContainer'; import EditorContainer from '../services/EditorContainer'; import { createSubscribedElement } from './UnstatedUtils'; import SlackNotification from './SlackNotification'; import GrantSelector from './SavePageControls/GrantSelector'; const logger = loggerFactory('growi:SavePageControls'); class SavePageControls extends React.Component { constructor(props) { super(props); const config = this.props.appContainer.getConfig(); this.hasSlackConfig = config.hasSlackConfig; this.isAclEnabled = config.isAclEnabled; this.slackEnabledFlagChangedHandler = this.slackEnabledFlagChangedHandler.bind(this); this.slackChannelsChangedHandler = this.slackChannelsChangedHandler.bind(this); this.updateGrantHandler = this.updateGrantHandler.bind(this); this.save = this.save.bind(this); this.saveAndOverwriteScopesOfDescendants = this.saveAndOverwriteScopesOfDescendants.bind(this); } slackEnabledFlagChangedHandler(isSlackEnabled) { this.props.editorContainer.setState({ isSlackEnabled }); } slackChannelsChangedHandler(slackChannels) { this.props.editorContainer.setState({ slackChannels }); } updateGrantHandler(data) { this.props.editorContainer.setState(data); } async save() { const { pageContainer, editorContainer } = this.props; // disable unsaved warning editorContainer.disableUnsavedWarning(); try { // save await pageContainer.saveAndReload(editorContainer.getCurrentOptionsToSave()); } catch (error) { logger.error('failed to save', error); pageContainer.showErrorToastr(error); } } saveAndOverwriteScopesOfDescendants() { const { pageContainer, editorContainer } = this.props; // disable unsaved warning editorContainer.disableUnsavedWarning(); // save const optionsToSave = Object.assign(editorContainer.getCurrentOptionsToSave(), { overwriteScopesOfDescendants: true, }); pageContainer.saveAndReload(optionsToSave); } render() { const { t, pageContainer, editorContainer } = this.props; const isRootPage = pageContainer.state.path === '/'; const labelSubmitButton = pageContainer.state.pageId == null ? t('Create') : t('Update'); const labelOverwriteScopes = t('page_edit.overwrite_scopes', { operation: labelSubmitButton }); return (