import React from 'react';
import PropTypes from 'prop-types';
import urljoin from 'url-join';
import LinkedPagePath from '../models/linked-page-path';
const PagePathHierarchicalLink = (props) => {
const { linkedPagePath, basePath } = props;
// render root element
if (linkedPagePath.isRoot) {
if (basePath != null) {
return null;
}
return props.isPageInTrash
? (
<>
/
>
)
: (
<>
/
>
);
}
const isParentExists = linkedPagePath.parent != null;
const isParentRoot = isParentExists && linkedPagePath.parent.isRoot;
const isSeparatorRequired = isParentExists && !isParentRoot;
const href = encodeURI(urljoin(basePath || '/', linkedPagePath.href));
return (
<>
{ isParentExists && (
) }
{ isSeparatorRequired && (
/
) }
{linkedPagePath.pathName}
>
);
};
PagePathHierarchicalLink.propTypes = {
linkedPagePath: PropTypes.instanceOf(LinkedPagePath).isRequired,
basePath: PropTypes.string,
isPageInTrash: PropTypes.bool, // TODO: omit
};
export default PagePathHierarchicalLink;