DuplicatedPathsTable.jsx 1.8 KB

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