PageTree.tsx 2.6 KB

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