Quellcode durchsuchen

add includeEmpty option in page-listing

reiji-h vor 1 Jahr
Ursprung
Commit
d7161324fc

+ 4 - 3
apps/app/src/server/routes/apiv3/page/index.ts

@@ -125,6 +125,7 @@ module.exports = (crowi) => {
       query('path').optional().isString(),
       query('findAll').optional().isBoolean(),
       query('shareLinkId').optional().isMongoId(),
+      query('includeEmpty').optional().isBoolean(),
     ],
     likes: [
       body('pageId').isString(),
@@ -209,7 +210,7 @@ module.exports = (crowi) => {
   router.get('/', certifySharedPage, accessTokenParser, loginRequired, validator.getPage, apiV3FormValidator, async(req, res) => {
     const { user, isSharedPage } = req;
     const {
-      pageId, path, findAll, revisionId, shareLinkId,
+      pageId, path, findAll, revisionId, shareLinkId, includeEmpty,
     } = req.query;
 
     const isValid = (shareLinkId != null && pageId != null && path == null) || (shareLinkId == null && (pageId != null || path != null));
@@ -231,10 +232,10 @@ module.exports = (crowi) => {
         page = await Page.findByIdAndViewer(pageId, user);
       }
       else if (!findAll) {
-        page = await Page.findByPathAndViewer(path, user, null, true);
+        page = await Page.findByPathAndViewer(path, user, null, true, false);
       }
       else {
-        pages = await Page.findByPathAndViewer(path, user, null, false);
+        pages = await Page.findByPathAndViewer(path, user, null, false, includeEmpty);
       }
     }
     catch (err) {

+ 3 - 2
apps/app/src/stores/page-listing.tsx

@@ -22,9 +22,10 @@ import type {
 
 export const useSWRxPagesByPath = (path?: Nullable<string>): SWRResponse<IPageHasId[], Error> => {
   const findAll = true;
+  const includeEmpty = true;
   return useSWR(
-    path != null ? ['/page', path, findAll] : null,
-    ([endpoint, path, findAll]) => apiv3Get(endpoint, { path, findAll }).then(result => result.data.pages),
+    path != null ? ['/page', path, findAll, includeEmpty] : null,
+    ([endpoint, path, findAll, includeEmpty]) => apiv3Get(endpoint, { path, findAll, includeEmpty }).then(result => result.data.pages),
   );
 };