IdenticalPathPage.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import React, { FC } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { DevidedPagePath } from '@growi/core';
  4. import { IPageHasId, IPageWithMeta } from '~/interfaces/page';
  5. import { useCurrentPagePath, useIsSharedUser } from '~/stores/context';
  6. import { useDescendantsPageListModal } from '~/stores/modal';
  7. import { useSWRxPageInfoForList } from '~/stores/page';
  8. import PageListIcon from './Icons/PageListIcon';
  9. import { PageListItemL } from './PageList/PageListItemL';
  10. type IdenticalPathAlertProps = {
  11. path? : string | null,
  12. }
  13. const IdenticalPathAlert : FC<IdenticalPathAlertProps> = (props: IdenticalPathAlertProps) => {
  14. const { path } = props;
  15. const { t } = useTranslation();
  16. let _path = '――';
  17. let _pageName = '――';
  18. if (path != null) {
  19. const devidedPath = new DevidedPagePath(path);
  20. _path = devidedPath.isFormerRoot ? '/' : devidedPath.former;
  21. _pageName = devidedPath.latter;
  22. }
  23. return (
  24. <div className="alert alert-warning py-3">
  25. <h5 className="font-weight-bold mt-1">{t('duplicated_page_alert.same_page_name_exists', { pageName: _pageName })}</h5>
  26. <p>
  27. {t('duplicated_page_alert.same_page_name_exists_at_path',
  28. { path: _path, pageName: _pageName })}<br />
  29. <span
  30. // eslint-disable-next-line react/no-danger
  31. dangerouslySetInnerHTML={{ __html: t('See_more_detail_on_new_schema', { url: t('GROWI.5.0_new_schema') }) }}
  32. />
  33. </p>
  34. <p className="mb-1">{t('duplicated_page_alert.select_page_to_see')}</p>
  35. </div>
  36. );
  37. };
  38. type IdenticalPathPageProps= {
  39. // add props and types here
  40. }
  41. const jsonNull = 'null';
  42. const IdenticalPathPage:FC<IdenticalPathPageProps> = (props: IdenticalPathPageProps) => {
  43. const { t } = useTranslation();
  44. const identicalPageDocument = document.getElementById('identical-path-page');
  45. const pages = JSON.parse(identicalPageDocument?.getAttribute('data-identical-path-pages') || jsonNull) as IPageHasId[];
  46. const pageIds = pages.map(page => page._id) as string[];
  47. const { data: currentPath } = useCurrentPagePath();
  48. const { data: isSharedUser } = useIsSharedUser();
  49. const { data: idToPageInfoMap } = useSWRxPageInfoForList(pageIds);
  50. const { open: openDescendantPageListModal } = useDescendantsPageListModal();
  51. return (
  52. <div className="d-flex flex-column flex-lg-row-reverse">
  53. <div className="grw-side-contents-container">
  54. <div className="grw-page-accessories-control pb-1">
  55. { currentPath != null && !isSharedUser && (
  56. <button
  57. type="button"
  58. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between"
  59. onClick={() => openDescendantPageListModal(currentPath)}
  60. >
  61. <PageListIcon />
  62. {t('page_list')}
  63. <span></span> {/* for a count badge */}
  64. </button>
  65. ) }
  66. </div>
  67. </div>
  68. <div className="flex-grow-1 flex-basis-0 mw-0">
  69. <IdenticalPathAlert path={currentPath} />
  70. <div className="page-list">
  71. <ul className="page-list-ul list-group list-group-flush">
  72. {pages.map((page) => {
  73. const pageId = page._id;
  74. const pageInfo = (idToPageInfoMap ?? {})[pageId];
  75. const pageWithMeta: IPageWithMeta = {
  76. pageData: page,
  77. pageMeta: pageInfo,
  78. };
  79. return (
  80. <PageListItemL
  81. key={pageId}
  82. page={pageWithMeta}
  83. isSelected={false}
  84. isEnableActions
  85. showPageUpdatedTime
  86. />
  87. );
  88. })}
  89. </ul>
  90. </div>
  91. </div>
  92. </div>
  93. );
  94. };
  95. export default IdenticalPathPage;