DuplicatedPathsTable.jsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { pagePathUtils } from '@growi/core';
  5. import { withUnstatedContainers } from './UnstatedUtils';
  6. import PageContainer from '~/client/services/PageContainer';
  7. const { convertToNewAffiliationPath } = pagePathUtils;
  8. function DuplicatedPathsTable(props) {
  9. const {
  10. pageContainer, oldPagePath, existingPaths, t,
  11. } = props;
  12. const { path } = pageContainer.state;
  13. return (
  14. <table className="table table-bordered grw-duplicated-paths-table">
  15. <thead>
  16. <tr className="d-flex">
  17. <th className="w-50">{t('original_path')}</th>
  18. <th className="w-50 text-danger">{t('duplicated_path')}</th>
  19. </tr>
  20. </thead>
  21. <tbody className="overflow-auto d-block">
  22. {existingPaths.map((existPath) => {
  23. const convertedPath = convertToNewAffiliationPath(oldPagePath, path, existPath);
  24. return (
  25. <tr key={existPath} className="d-flex">
  26. <td className="text-break w-50">
  27. <a href={convertedPath}>
  28. {convertedPath}
  29. </a>
  30. </td>
  31. <td className="text-break text-danger w-50">
  32. {existPath}
  33. </td>
  34. </tr>
  35. );
  36. })}
  37. </tbody>
  38. </table>
  39. );
  40. }
  41. /**
  42. * Wrapper component for using unstated
  43. */
  44. const PageDuplicateModallWrapper = withUnstatedContainers(DuplicatedPathsTable, [PageContainer]);
  45. DuplicatedPathsTable.propTypes = {
  46. t: PropTypes.func.isRequired, // i18next
  47. pageContainer: PropTypes.instanceOf(PageContainer).isRequired,
  48. existingPaths: PropTypes.array.isRequired,
  49. oldPagePath: PropTypes.string.isRequired,
  50. };
  51. export default withTranslation()(PageDuplicateModallWrapper);