PageTree.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React, { FC, memo } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useSWRxV5MigrationStatus } from '~/stores/page-listing';
  4. import {
  5. useCurrentPagePath, useCurrentPageId, useRevisionId, useTargetAndAncestors, useIsGuestUser, useNotFoundTargetPathOrId,
  6. } from '~/stores/context';
  7. import ItemsTree from './PageTree/ItemsTree';
  8. import PrivateLegacyPages from './PageTree/PrivateLegacyPages';
  9. import { IPageForPageDeleteModal } from '~/stores/ui';
  10. const PageTree: FC = memo(() => {
  11. const { t } = useTranslation();
  12. const { data: isGuestUser } = useIsGuestUser();
  13. const { data: currentPath } = useCurrentPagePath();
  14. const { data: targetId } = useCurrentPageId();
  15. const { data: revisionId } = useRevisionId();
  16. const { data: targetAndAncestorsData } = useTargetAndAncestors();
  17. const { data: notFoundTargetPathOrIdData } = useNotFoundTargetPathOrId();
  18. const { data: migrationStatus } = useSWRxV5MigrationStatus();
  19. const targetPathOrId = targetId || notFoundTargetPathOrIdData?.notFoundTargetPathOrId;
  20. if (migrationStatus == null) {
  21. return (
  22. <>
  23. <div className="grw-sidebar-content-header p-3">
  24. <h3 className="mb-0">{t('Page Tree')}</h3>
  25. </div>
  26. <div className="mt-5 mx-2 text-center">
  27. <h3 className="text-gray">Page Tree now loading...</h3>
  28. </div>
  29. </>
  30. );
  31. }
  32. if (!migrationStatus?.isV5Compatible) {
  33. // TODO : improve design
  34. // Story : https://redmine.weseek.co.jp/issues/83755
  35. return (
  36. <>
  37. <div className="grw-sidebar-content-header p-3">
  38. <h3 className="mb-0">{t('Page Tree')}</h3>
  39. </div>
  40. <div className="mt-5 mx-2 text-center">
  41. <h3 className="text-gray">{t('admin:v5_page_migration.page_tree_not_avaliable')}</h3>
  42. <a href="/admin">{t('admin:v5_page_migration.go_to_settings')}</a>
  43. </div>
  44. </>
  45. );
  46. }
  47. /*
  48. * dependencies
  49. */
  50. if (isGuestUser == null) {
  51. return null;
  52. }
  53. const path = currentPath || '/';
  54. const pageId = targetId != null ? targetId : '';
  55. const pageToDelete: IPageForPageDeleteModal = {
  56. pageId,
  57. path,
  58. revisionId,
  59. };
  60. return (
  61. <>
  62. <div className="grw-sidebar-content-header p-3">
  63. <h3 className="mb-0">{t('Page Tree')}</h3>
  64. </div>
  65. <div className="grw-sidebar-content-body">
  66. <ItemsTree
  67. isEnableActions={!isGuestUser}
  68. targetPath={path}
  69. targetPathOrId={targetPathOrId}
  70. targetAndAncestorsData={targetAndAncestorsData}
  71. pageToDelete={pageToDelete}
  72. />
  73. </div>
  74. {!isGuestUser && migrationStatus?.migratablePagesCount != null && migrationStatus.migratablePagesCount !== 0 && (
  75. <div className="grw-pagetree-footer border-top p-3 w-100">
  76. <PrivateLegacyPages />
  77. </div>
  78. )}
  79. </>
  80. );
  81. });
  82. export default PageTree;