RevisionPath.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import DevidedPagePath from '@commons/models/devided-page-path';
  5. import LinkedPagePath from '@commons/models/linked-page-path';
  6. import PagePathHierarchicalLink from '@commons/components/PagePathHierarchicalLink';
  7. import CopyDropdown from './CopyDropdown';
  8. const RevisionPath = (props) => {
  9. // define styles
  10. const buttonStyle = {
  11. marginLeft: '0.5em',
  12. padding: '0 2px',
  13. };
  14. const {
  15. pageId, isPageInTrash, isPageForbidden,
  16. } = props;
  17. const dPagePath = new DevidedPagePath(props.pagePath, false, true);
  18. const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter);
  19. return (
  20. <>
  21. <span className="d-flex align-items-center flex-wrap">
  22. <PagePathHierarchicalLink linkedPagePath={linkedPagePathLatter} basePath={dPagePath.isRoot ? undefined : dPagePath.former} />
  23. <CopyDropdown pagePath={props.pagePath} pageId={pageId} buttonStyle={buttonStyle} />
  24. { !isPageInTrash && !isPageForbidden && (
  25. <a href="#edit" className="d-block d-edit-none text-muted btn btn-secondary bg-transparent btn-edit border-0" style={buttonStyle}>
  26. <i className="icon-note" />
  27. </a>
  28. ) }
  29. </span>
  30. </>
  31. );
  32. };
  33. RevisionPath.propTypes = {
  34. t: PropTypes.func.isRequired, // i18next
  35. pagePath: PropTypes.string.isRequired,
  36. pageId: PropTypes.string,
  37. isPageForbidden: PropTypes.bool,
  38. isPageInTrash: PropTypes.bool,
  39. };
  40. RevisionPath.defaultProps = {
  41. isPageForbidden: false,
  42. isPageInTrash: false,
  43. };
  44. export default withTranslation()(RevisionPath);