Parcourir la source

Merge pull request #2702 from weseek/imprv/add-limit-at-subordinated-list

Imprv/add limit at subordinated list
Yuki Takei il y a 5 ans
Parent
commit
1a5c0e4fdb

+ 2 - 1
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;
@@ -72,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);
     }

+ 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 });
     }