|
@@ -0,0 +1,159 @@
|
|
|
|
|
+import React, { useState } from 'react';
|
|
|
|
|
+import PropTypes from 'prop-types';
|
|
|
|
|
+
|
|
|
|
|
+import {
|
|
|
|
|
+ Modal, ModalHeader, ModalBody, ModalFooter,
|
|
|
|
|
+} from 'reactstrap';
|
|
|
|
|
+
|
|
|
|
|
+import { withTranslation } from 'react-i18next';
|
|
|
|
|
+
|
|
|
|
|
+import { createSubscribedElement } from './UnstatedUtils';
|
|
|
|
|
+
|
|
|
|
|
+import AppContainer from '../services/AppContainer';
|
|
|
|
|
+import PageContainer from '../services/PageContainer';
|
|
|
|
|
+import ApiErrorMessage from './PageManagement/ApiErrorMessage';
|
|
|
|
|
+
|
|
|
|
|
+const PageRenameModal = (props) => {
|
|
|
|
|
+ const {
|
|
|
|
|
+ t, appContainer, pageContainer,
|
|
|
|
|
+ } = props;
|
|
|
|
|
+
|
|
|
|
|
+ const { path } = pageContainer.state;
|
|
|
|
|
+
|
|
|
|
|
+ const { crowi } = appContainer.config;
|
|
|
|
|
+
|
|
|
|
|
+ const [pageNameInput, setPageNameInput] = useState(path);
|
|
|
|
|
+ const [errorCode, setErrorCode] = useState(null);
|
|
|
|
|
+ const [errorMessage, setErrorMessage] = useState(null);
|
|
|
|
|
+
|
|
|
|
|
+ const [isRenameRecursively, SetIsRenameRecursively] = useState(true);
|
|
|
|
|
+ const [isRenameRedirect, SetIsRenameRedirect] = useState(true);
|
|
|
|
|
+ const [isRenameMetadata, SetIsRenameMetadata] = useState(true);
|
|
|
|
|
+
|
|
|
|
|
+ function changeIsRenameRecursivelyHandler() {
|
|
|
|
|
+ SetIsRenameRecursively(!isRenameRecursively);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * change pageNameInput
|
|
|
|
|
+ * @param {string} value
|
|
|
|
|
+ */
|
|
|
|
|
+ function inputChangeHandler(value) {
|
|
|
|
|
+ setPageNameInput(value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async function rename() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ setErrorCode(null);
|
|
|
|
|
+ setErrorMessage(null);
|
|
|
|
|
+
|
|
|
|
|
+ const response = await pageContainer.rename(
|
|
|
|
|
+ pageNameInput,
|
|
|
|
|
+ isRenameRedirect,
|
|
|
|
|
+ isRenameMetadata,
|
|
|
|
|
+ isRenameRecursively,
|
|
|
|
|
+ );
|
|
|
|
|
+ const { page } = response;
|
|
|
|
|
+ window.location.href = encodeURI(`${page.path}?rename=${path}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ setErrorCode(err.code);
|
|
|
|
|
+ setErrorMessage(err.message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <Modal isOpen={pageContainer.state.isPageRenameModalShown} toggle={pageContainer.closePageRenameModal} className="grw-create-page">
|
|
|
|
|
+ <ModalHeader tag="h4" toggle={pageContainer.closePageRenameModal} className="bg-primary text-light">
|
|
|
|
|
+ { t('modal_rename.label.Move/Rename page') }
|
|
|
|
|
+ </ModalHeader>
|
|
|
|
|
+ <ModalBody>
|
|
|
|
|
+ <div className="form-group">
|
|
|
|
|
+ <label>{ t('modal_rename.label.Current page name') }</label><br />
|
|
|
|
|
+ <code>{ path }</code>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="form-group">
|
|
|
|
|
+ <label htmlFor="newPageName">{ t('modal_rename.label.New page name') }</label><br />
|
|
|
|
|
+ <div className="input-group">
|
|
|
|
|
+ <div className="input-group-prepend">
|
|
|
|
|
+ <span className="input-group-text">{crowi.url}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="flex-fill">
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ value={pageNameInput}
|
|
|
|
|
+ className="form-control"
|
|
|
|
|
+ onChange={e => inputChangeHandler(e.target.value)}
|
|
|
|
|
+ required
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="custom-control custom-checkbox custom-checkbox-warning">
|
|
|
|
|
+ <input
|
|
|
|
|
+ className="custom-control-input"
|
|
|
|
|
+ name="recursively"
|
|
|
|
|
+ id="cbRenameRecursively"
|
|
|
|
|
+ type="checkbox"
|
|
|
|
|
+ checked={isRenameRecursively}
|
|
|
|
|
+ onChange={changeIsRenameRecursivelyHandler}
|
|
|
|
|
+ />
|
|
|
|
|
+ <label className="custom-control-label" htmlFor="cbRenameRecursively">
|
|
|
|
|
+ { t('modal_rename.label.Recursively') }
|
|
|
|
|
+ <p className="form-text text-muted mt-0">{ t('modal_rename.help.recursive') }</p>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="custom-control custom-checkbox custom-checkbox-success">
|
|
|
|
|
+ <input
|
|
|
|
|
+ className="custom-control-input"
|
|
|
|
|
+ name="create_redirect"
|
|
|
|
|
+ id="cbRenameRedirect"
|
|
|
|
|
+ type="checkbox"
|
|
|
|
|
+ onChange={SetIsRenameRedirect}
|
|
|
|
|
+ />
|
|
|
|
|
+ <label className="custom-control-label" htmlFor="cbRenameRedirect">
|
|
|
|
|
+ { t('modal_rename.label.Redirect') }
|
|
|
|
|
+ <p className="form-text text-muted mt-0">{ t('modal_rename.help.redirect') }</p>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="custom-control custom-checkbox custom-checkbox-primary">
|
|
|
|
|
+ <input
|
|
|
|
|
+ className="custom-control-input"
|
|
|
|
|
+ name="remain_metadata"
|
|
|
|
|
+ id="cbRenameMetadata"
|
|
|
|
|
+ type="checkbox"
|
|
|
|
|
+ onChange={SetIsRenameMetadata}
|
|
|
|
|
+ />
|
|
|
|
|
+ <label className="custom-control-label" htmlFor="cbRenameMetadata">
|
|
|
|
|
+ { t('modal_rename.label.Do not update metadata') }
|
|
|
|
|
+ <p className="form-text text-muted mt-0">{ t('modal_rename.help.metadata') }</p>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </ModalBody>
|
|
|
|
|
+ <ModalFooter>
|
|
|
|
|
+ <ApiErrorMessage errorCode={errorCode} errorMessage={errorMessage} linkPath={path} />
|
|
|
|
|
+ <button type="button" className="btn btn-primary" onClick={rename}>Rename</button>
|
|
|
|
|
+ </ModalFooter>
|
|
|
|
|
+ </Modal>
|
|
|
|
|
+ );
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Wrapper component for using unstated
|
|
|
|
|
+ */
|
|
|
|
|
+const PageRenameModalWrapper = (props) => {
|
|
|
|
|
+ return createSubscribedElement(PageRenameModal, props, [AppContainer, PageContainer]);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+PageRenameModal.propTypes = {
|
|
|
|
|
+ t: PropTypes.func.isRequired, // i18next
|
|
|
|
|
+ appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
|
|
+ pageContainer: PropTypes.instanceOf(PageContainer).isRequired,
|
|
|
|
|
+
|
|
|
|
|
+ path: PropTypes.string.isRequired,
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+export default withTranslation()(PageRenameModalWrapper);
|