IdenticalPathPage.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React, {
  2. FC,
  3. } from 'react';
  4. import { DevidedPagePath } from '@growi/core';
  5. import { useCurrentPagePath } from '~/stores/context';
  6. import PageListItem from './Page/PageListItem';
  7. import { useTranslation } from 'react-i18next';
  8. type IdenticalPathAlertProps = {
  9. path? : string | null,
  10. }
  11. const IdenticalPathAlert : FC<IdenticalPathAlertProps> = (props: IdenticalPathAlertProps) => {
  12. const { path } = props;
  13. const { t } = useTranslation();
  14. const devidedPath = new DevidedPagePath(path);
  15. const _path = path != null
  16. ? (devidedPath.isFormerRoot ? '/' : devidedPath.former)
  17. : '――';
  18. const _pageName = path != null
  19. ? devidedPath.latter
  20. : '――';
  21. return (
  22. <div className="alert alert-warning py-3">
  23. <h5 className="font-weight-bold mt-1">{t('duplicated_page_alert.same_page_name_exists', { pageName: _pageName })}</h5>
  24. <p>
  25. {t('duplicated_page_alert.same_page_name_exists_at_path',
  26. { path: _path, pageName: _pageName })}<br />
  27. <p dangerouslySetInnerHTML={{ __html: t('See_more_detail_on_new_schema', { url: t('GROWI.5.0_new_schema') }) }} />
  28. </p>
  29. <p className="mb-1">{t('duplicated_page_alert.select_page_to_see')}</p>
  30. </div>
  31. );
  32. };
  33. type IdenticalPathPageProps= {
  34. // add props and types here
  35. }
  36. const jsonNull = 'null';
  37. const IdenticalPathPage:FC<IdenticalPathPageProps> = (props:IdenticalPathPageProps) => {
  38. const identicalPageDocument = document.getElementById('identical-path-page');
  39. const pageDataList = JSON.parse(identicalPageDocument?.getAttribute('data-identical-page-data-list') || jsonNull);
  40. const shortbodyMap = JSON.parse(identicalPageDocument?.getAttribute('data-shortody-map') || jsonNull);
  41. const { data: currentPath } = useCurrentPagePath();
  42. return (
  43. <div className="d-flex flex-column flex-lg-row-reverse">
  44. <div className="grw-side-contents-container">
  45. <div className="grw-side-contents-sticky-container">
  46. <div className="border-bottom pb-1">
  47. {/* <PageAccessories isNotFoundPage={!isPageExist} /> */}
  48. </div>
  49. </div>
  50. </div>
  51. <div className="flex-grow-1 flex-basis-0 mw-0">
  52. <IdenticalPathAlert path={currentPath} />
  53. <div className="page-list">
  54. <ul className="page-list-ul list-group-flush border px-3">
  55. {pageDataList.map((data) => {
  56. return (
  57. <PageListItem
  58. key={data.pageData._id}
  59. page={data}
  60. isSelected={false}
  61. isChecked={false}
  62. isEnableActions
  63. shortBody={shortbodyMap[data.pageData._id]}
  64. // Todo: add onClickDeleteButton when delete feature implemented
  65. />
  66. );
  67. })}
  68. </ul>
  69. </div>
  70. </div>
  71. </div>
  72. );
  73. };
  74. export default IdenticalPathPage;