IdenticalPathPage.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import React, { FC } from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import { DevidedPagePath } from '@growi/core';
  4. import { IPageHasId } 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 { injectTo } = useSWRxPageInfoForList(pageIds, true, true);
  50. const { open: openDescendantPageListModal } = useDescendantsPageListModal();
  51. const injectedPages = injectTo(pages);
  52. return (
  53. <div className="d-flex flex-column flex-lg-row-reverse">
  54. <div className="grw-side-contents-container">
  55. <div className="grw-page-accessories-control pb-1">
  56. { currentPath != null && !isSharedUser && (
  57. <button
  58. type="button"
  59. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between"
  60. onClick={() => openDescendantPageListModal(currentPath)}
  61. >
  62. <PageListIcon />
  63. {t('page_list')}
  64. <span></span> {/* for a count badge */}
  65. </button>
  66. ) }
  67. </div>
  68. </div>
  69. <div className="flex-grow-1 flex-basis-0 mw-0">
  70. <IdenticalPathAlert path={currentPath} />
  71. <div className="page-list">
  72. <ul className="page-list-ul list-group list-group-flush">
  73. {injectedPages.map((pageWithMeta) => {
  74. const pageId = pageWithMeta.data._id;
  75. return (
  76. <PageListItemL
  77. key={pageId}
  78. page={pageWithMeta}
  79. isSelected={false}
  80. isEnableActions
  81. showPageUpdatedTime
  82. />
  83. );
  84. })}
  85. </ul>
  86. </div>
  87. </div>
  88. </div>
  89. );
  90. };
  91. export default IdenticalPathPage;