Przeglądaj źródła

Merge branch 'imprv/duplicate-Page-with-child' into imprv/gw3374

# Conflicts:
#	src/client/js/components/PageRenameModal.jsx
白石誠 5 lat temu
rodzic
commit
7817b66308

+ 12 - 2
src/client/js/components/PageDuplicateModal.jsx

@@ -15,6 +15,7 @@ import PagePathAutoComplete from './PagePathAutoComplete';
 import ApiErrorMessageList from './PageManagement/ApiErrorMessageList';
 import ComparePathsTable from './ComparePathsTable';
 
+const LIMIT_FOR_LIST = 10;
 
 const PageDuplicateModal = (props) => {
   const { t, appContainer, pageContainer } = props;
@@ -31,6 +32,7 @@ const PageDuplicateModal = (props) => {
   const [subordinatedPages, setSubordinatedPages] = useState([]);
   const [isDuplicateRecursively, setIsDuplicateRecursively] = useState(false);
   const [isDuplicateRecursivelyWithoutExistPath, setIsDuplicateRecursivelyWithoutExistPath] = useState(false);
+  const [isDuplicateRecursivelyExist] = useState(false);
 
   function getSubordinatedDuplicateList(value) {
 
@@ -42,6 +44,7 @@ const PageDuplicateModal = (props) => {
     // setIsDuplicateExist(duplicatedList);
 
     // ToDo: for now we use dummy path
+    return [];
   }
 
   /**
@@ -70,7 +73,7 @@ const PageDuplicateModal = (props) => {
 
   const getSubordinatedList = useCallback(async() => {
     try {
-      const res = await appContainer.apiv3Get('/pages/subordinated-list', { path });
+      const res = await appContainer.apiv3Get('/pages/subordinated-list', { path, limit: LIMIT_FOR_LIST });
       const { subordinatedPaths } = res.data;
       setSubordinatedPages(subordinatedPaths);
     }
@@ -175,7 +178,14 @@ const PageDuplicateModal = (props) => {
       </ModalBody>
       <ModalFooter>
         <ApiErrorMessageList errs={errs} targetPath={pageNameInput} />
-        <button type="button" className="btn btn-primary" onClick={duplicate}>Duplicate page</button>
+        <button
+          type="button"
+          className="btn btn-primary"
+          onClick={duplicate}
+          disabled={(isDuplicateRecursively && isDuplicateRecursivelyExist && !isDuplicateRecursivelyWithoutExistPath) || (path === pageNameInput)}
+        >
+          { t('modal_duplicate.label.Duplicate page') }
+        </button>
       </ModalFooter>
     </Modal>
   );

+ 1 - 17
src/client/js/components/PageRenameModal.jsx

@@ -32,24 +32,9 @@ const PageRenameModal = (props) => {
   const [isRenameRedirect, SetIsRenameRedirect] = useState(false);
   const [isRenameMetadata, SetIsRenameMetadata] = useState(false);
   const [getSubordinatedError] = useState(null);
-  const [isDuplicateExistList, setIsDuplicateExistList] = useState([]);
   const [isDuplicateRecursivelyWithoutExistPath, setIsDuplicateRecursivelyWithoutExistPath] = useState(true);
 
 
-  function createSubordinatedList(value) {
-
-    // ToDo: get the duplicated list from sever
-    // below is psuedo code
-    // let duplicatedList = get.apiv3......
-    // duplicatedList = duplicatedList.map((value) =>
-    // <li className="duplicate-exist" key={value}> {value}: { t('modal_duplicate.label.Same page already exists') } </li>; )
-    // setIsDuplicateExist(duplicatedList);
-
-    // ToDo: for now we use dummy path
-    setIsDuplicateExistList(['/test146/test147', value]);
-  }
-
-
   function changeIsRenameRecursivelyHandler() {
     SetIsRenameRecursively(!isRenameRecursively);
   }
@@ -89,7 +74,6 @@ const PageRenameModal = (props) => {
    * @param {string} value
    */
   function inputChangeHandler(value) {
-    createSubordinatedList(value);
     setErrs(null);
     setPageNameInput(value);
   }
@@ -161,7 +145,7 @@ const PageRenameModal = (props) => {
           </label>
           <div
             className="custom-control custom-checkbox custom-checkbox-warning"
-            style={{ display: (isDuplicateExistList.length !== 0) && isRenameRecursively ? '' : 'none' }}
+            style={{ display: isRenameRecursively ? '' : 'none' }}
           >
             <input
               className="custom-control-input"

+ 1 - 1
src/client/styles/scss/_create-page.scss

@@ -18,7 +18,7 @@
 
     tbody {
       width: 100%;
-      height: 200px;
+      max-height: 200px;
       overflow-y: auto;
     }
 

+ 37 - 2
src/server/routes/apiv3/pages.js

@@ -11,6 +11,8 @@ const ErrorV3 = require('../../models/vo/error-apiv3');
 
 const router = express.Router();
 
+const LIMIT_FOR_LIST = 10;
+
 /**
  * @swagger
  *  tags:
@@ -555,13 +557,46 @@ module.exports = (crowi) => {
     return res.apiv3({ result });
   });
 
-
+  /**
+   * @swagger
+   *
+   *
+   *    /pages/subordinated-list:
+   *      get:
+   *        tags: [Pages]
+   *        operationId: subordinatedList
+   *        description: Get subordinated pages
+   *        parameters:
+   *          - name: path
+   *            in: query
+   *            description: Parent path of search
+   *            schema:
+   *              type: string
+   *          - name: limit
+   *            in: query
+   *            description: Limit of acquisitions
+   *            schema:
+   *              type: number
+   *        responses:
+   *          200:
+   *            description: Succeeded to retrieve pages.
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    subordinatedPaths:
+   *                      type: object
+   *                      description: descendants page
+   *          500:
+   *            description: Internal server error.
+   */
   router.get('/subordinated-list', accessTokenParser, loginRequired, async(req, res) => {
     const { path } = req.query;
+    const limit = parseInt(req.query.limit) || LIMIT_FOR_LIST;
 
     try {
       const pageData = await Page.findByPath(path);
-      const result = await Page.findManageableListWithDescendants(pageData, req.user);
+      const result = await Page.findManageableListWithDescendants(pageData, req.user, { limit });
 
       return res.apiv3({ subordinatedPaths: result });
     }