2
0
Эх сурвалжийг харах

Merge branch 'feat/replace-perma-link' into feat/replace-updated-markdown-link

# Conflicts:
#	src/client/js/components/PageEditor/LinkEditModal.jsx
yusuketk 5 жил өмнө
parent
commit
751f5e6d25

+ 2 - 2
resource/locales/en_US/translation.json

@@ -208,8 +208,8 @@
     "Copy to clipboard": "Copy to clipboard",
     "Copy to clipboard": "Copy to clipboard",
     "Page path": "Page path",
     "Page path": "Page path",
     "Page URL": "Page URL",
     "Page URL": "Page URL",
-    "Parmanent link": "Parmanent link",
-    "Page path and parmanent link": "Page path and parmanent link",
+    "Permanent link": "Permanent link",
+    "Page path and permanent link": "Page path and permanent link",
     "Markdown link": "Markdown link"
     "Markdown link": "Markdown link"
   },
   },
   "search_help": {
   "search_help": {

+ 2 - 2
resource/locales/ja_JP/translation.json

@@ -210,8 +210,8 @@
     "Copy to clipboard": "クリップボードにコピー",
     "Copy to clipboard": "クリップボードにコピー",
     "Page path": "ページ名",
     "Page path": "ページ名",
     "Page URL": "ページURL",
     "Page URL": "ページURL",
-    "Parmanent link": "パーマリンク",
-    "Page path and parmanent link": "ページ名とパーマリンク",
+    "Permanent link": "パーマリンク",
+    "Page path and permanent link": "ページ名とパーマリンク",
     "Markdown link": "マークダウン形式のリンク"
     "Markdown link": "マークダウン形式のリンク"
   },
   },
   "search_help": {
   "search_help": {

+ 4 - 4
src/client/js/components/Page/CopyDropdown.jsx

@@ -149,22 +149,22 @@ class CopyDropdown extends React.Component {
 
 
             <DropdownItem divider className="my-0"></DropdownItem>
             <DropdownItem divider className="my-0"></DropdownItem>
 
 
-            {/* Parmanent Link */}
+            {/* Permanent Link */}
             { pageId && (
             { pageId && (
               <CopyToClipboard text={permalink} onCopy={this.showToolTip}>
               <CopyToClipboard text={permalink} onCopy={this.showToolTip}>
                 <DropdownItem className="px-3">
                 <DropdownItem className="px-3">
-                  <DropdownItemContents title={t('copy_to_clipboard.Parmanent link')} contents={permalink} />
+                  <DropdownItemContents title={t('copy_to_clipboard.Permanent link')} contents={permalink} />
                 </DropdownItem>
                 </DropdownItem>
               </CopyToClipboard>
               </CopyToClipboard>
             )}
             )}
 
 
             <DropdownItem divider className="my-0"></DropdownItem>
             <DropdownItem divider className="my-0"></DropdownItem>
 
 
-            {/* Page path + Parmanent Link */}
+            {/* Page path + Permanent Link */}
             { pageId && (
             { pageId && (
               <CopyToClipboard text={`${pagePathWithParams}\n${permalink}`} onCopy={this.showToolTip}>
               <CopyToClipboard text={`${pagePathWithParams}\n${permalink}`} onCopy={this.showToolTip}>
                 <DropdownItem className="px-3">
                 <DropdownItem className="px-3">
-                  <DropdownItemContents title={t('copy_to_clipboard.Page path and parmanent link')} contents={<>{pagePathWithParams}<br />{permalink}</>} />
+                  <DropdownItemContents title={t('copy_to_clipboard.Page path and permanent link')} contents={<>{pagePathWithParams}<br />{permalink}</>} />
                 </DropdownItem>
                 </DropdownItem>
               </CopyToClipboard>
               </CopyToClipboard>
             )}
             )}

+ 50 - 13
src/client/js/components/PageEditor/LinkEditModal.jsx

@@ -1,6 +1,7 @@
 import React from 'react';
 import React from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 
 
+
 import {
 import {
   Modal,
   Modal,
   ModalHeader,
   ModalHeader,
@@ -31,6 +32,8 @@ class LinkEditModal extends React.PureComponent {
       labelInputValue: '',
       labelInputValue: '',
       linkerType: Linker.types.markdownLink,
       linkerType: Linker.types.markdownLink,
       markdown: '',
       markdown: '',
+      permalink: '',
+      isEnablePermanentLink: false,
     };
     };
 
 
     this.isApplyPukiwikiLikeLinkerPlugin = window.growiRenderer.preProcessors.some(process => process.constructor.name === 'PukiwikiLikeLinker');
     this.isApplyPukiwikiLikeLinkerPlugin = window.growiRenderer.preProcessors.some(process => process.constructor.name === 'PukiwikiLikeLinker');
@@ -43,17 +46,18 @@ class LinkEditModal extends React.PureComponent {
     this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this);
     this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this);
     this.handleSelecteLinkerType = this.handleSelecteLinkerType.bind(this);
     this.handleSelecteLinkerType = this.handleSelecteLinkerType.bind(this);
     this.toggleIsUseRelativePath = this.toggleIsUseRelativePath.bind(this);
     this.toggleIsUseRelativePath = this.toggleIsUseRelativePath.bind(this);
-    this.setMarkdown = this.setMarkdown.bind(this);
     this.toggleIsUsePamanentLink = this.toggleIsUsePamanentLink.bind(this);
     this.toggleIsUsePamanentLink = this.toggleIsUsePamanentLink.bind(this);
     this.save = this.save.bind(this);
     this.save = this.save.bind(this);
     this.generateLink = this.generateLink.bind(this);
     this.generateLink = this.generateLink.bind(this);
+    this.getPreviewWithLinkInputValue = this.getPreviewWithLinkInputValue.bind(this);
+    this.renderPreview = this.renderPreview.bind(this);
   }
   }
 
 
   componentDidUpdate(prevState) {
   componentDidUpdate(prevState) {
     const { linkInputValue: prevLinkInputValue } = prevState;
     const { linkInputValue: prevLinkInputValue } = prevState;
     const { linkInputValue } = this.state;
     const { linkInputValue } = this.state;
     if (linkInputValue !== prevLinkInputValue) {
     if (linkInputValue !== prevLinkInputValue) {
-      this.setMarkdown(linkInputValue);
+      this.getPreviewWithLinkInputValue(linkInputValue);
     }
     }
   }
   }
 
 
@@ -90,11 +94,18 @@ class LinkEditModal extends React.PureComponent {
     if (this.state.linkerType === Linker.types.growiLink) {
     if (this.state.linkerType === Linker.types.growiLink) {
       return;
       return;
     }
     }
-    this.setState({ isUseRelativePath: !this.state.isUseRelativePath });
+
+    // User can't use both relativePath and permalink at the same time
+    this.setState({ isUseRelativePath: !this.state.isUseRelativePath, isUsePermanentLink: false });
   }
   }
 
 
   toggleIsUsePamanentLink() {
   toggleIsUsePamanentLink() {
-    this.setState({ isUsePermanentLink: !this.state.isUsePermanentLink });
+    if (!this.state.isEnablePermanentLink) {
+      return;
+    }
+
+    // User can't use both relativePath and permalink at the same time
+    this.setState({ isUsePermanentLink: !this.state.isUsePermanentLink, isUseRelativePath: false });
   }
   }
 
 
   renderPreview() {
   renderPreview() {
@@ -152,6 +163,22 @@ class LinkEditModal extends React.PureComponent {
     this.hide();
     this.hide();
   }
   }
 
 
+  async getPreviewWithLinkInputValue(path) {
+    let markdown = '';
+    let permalink = '';
+    let isEnablePermanentLink = false;
+    try {
+      const res = await this.props.appContainer.apiGet('/pages.get', { path });
+      markdown = res.page.revision.body;
+      permalink = `${window.location.origin}/${res.page.id}`;
+      isEnablePermanentLink = true;
+    }
+    catch (err) {
+      markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
+    }
+    this.setState({ markdown, permalink, isEnablePermanentLink });
+  }
+
   generateLink() {
   generateLink() {
     const { pageContainer } = this.props;
     const { pageContainer } = this.props;
     const {
     const {
@@ -159,6 +186,8 @@ class LinkEditModal extends React.PureComponent {
       labelInputValue,
       labelInputValue,
       linkerType,
       linkerType,
       isUseRelativePath,
       isUseRelativePath,
+      isUsePermanentLink,
+      permalink,
     } = this.state;
     } = this.state;
 
 
     return new Linker(
     return new Linker(
@@ -166,6 +195,8 @@ class LinkEditModal extends React.PureComponent {
       labelInputValue,
       labelInputValue,
       linkInputValue,
       linkInputValue,
       isUseRelativePath,
       isUseRelativePath,
+      isUsePermanentLink,
+      permalink,
       pageContainer.state.path,
       pageContainer.state.path,
     );
     );
   }
   }
@@ -179,7 +210,7 @@ class LinkEditModal extends React.PureComponent {
 
 
         <ModalBody className="container">
         <ModalBody className="container">
           <div className="row">
           <div className="row">
-            <div className="col">
+            <div className="col-12 col-lg-6">
               <form className="form-group">
               <form className="form-group">
                 <div className="form-gorup my-3">
                 <div className="form-gorup my-3">
                   <label htmlFor="linkInput">Link</label>
                   <label htmlFor="linkInput">Link</label>
@@ -193,14 +224,6 @@ class LinkEditModal extends React.PureComponent {
                     />
                     />
                   </div>
                   </div>
                 </div>
                 </div>
-                <div className="form-inline">
-                  <div className="custom-control custom-checkbox custom-checkbox-info">
-                    <input className="custom-control-input" id="permanentLink" type="checkbox" checked={this.state.isUsePamanentLink} />
-                    <label className="custom-control-label" htmlFor="permanentLink" onClick={this.toggleIsUsePamanentLink}>
-                      Use permanent link
-                    </label>
-                  </div>
-                </div>
               </form>
               </form>
 
 
               <div className="d-block d-lg-none mb-3 overflow-auto">
               <div className="d-block d-lg-none mb-3 overflow-auto">
@@ -264,6 +287,20 @@ class LinkEditModal extends React.PureComponent {
                         </label>
                         </label>
                       </div>
                       </div>
                     </div>
                     </div>
+                    <div className="form-inline">
+                      <div className="custom-control custom-checkbox custom-checkbox-info">
+                        <input
+                          className="custom-control-input"
+                          id="permanentLink"
+                          type="checkbox"
+                          checked={this.state.isUsePermanentLink}
+                          disabled={!this.state.isEnablePermanentLink}
+                        />
+                        <label className="custom-control-label" htmlFor="permanentLink" onClick={this.toggleIsUsePamanentLink}>
+                          Use permanent link
+                        </label>
+                      </div>
+                    </div>
                   </form>
                   </form>
                 </div>
                 </div>
               </div>
               </div>

+ 2 - 2
src/client/js/models/Linker.js

@@ -53,9 +53,9 @@ export default class Linker {
     let type = this.types.markdownLink;
     let type = this.types.markdownLink;
 
 
     // pukiwiki with separator ">".
     // pukiwiki with separator ">".
-    if (str.match(this.patterns.pukiwikiWithLabel)) {
+    if (str.match(this.patterns.pukiwikiLinkWithLabel)) {
       type = this.types.pukiwikiLink;
       type = this.types.pukiwikiLink;
-      ({ label, link } = str.match(this.patterns.pukiwikiWithLabel).groups);
+      ({ label, link } = str.match(this.patterns.pukiwikiLinkWithLabel).groups);
     }
     }
     // pukiwiki without separator ">".
     // pukiwiki without separator ">".
     else if (str.match(this.patterns.pukiwikiLinkWithoutLabel)) {
     else if (str.match(this.patterns.pukiwikiLinkWithoutLabel)) {