PageTree.tsx 2.5 KB

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