Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breadcrumbs Refactor #4858

Merged
merged 39 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ff912de
refactor breadcrumbs
Tishasoumya-02 Jun 7, 2023
085acac
refactor breadcrumbs
Tishasoumya-02 Jun 7, 2023
4188c99
refactor-breadcrumbs
Tishasoumya-02 Jun 7, 2023
1951d12
refactor-breadcrumbs
Tishasoumya-02 Jun 7, 2023
e38f7b7
Refactored useBreadcrumbs
Tishasoumya-02 Jun 9, 2023
c105f10
Prettier formatted
Tishasoumya-02 Jun 9, 2023
888c105
/new
Tishasoumya-02 Jun 9, 2023
1784f21
Merge branch 'master' into breadcrumbs-refactor
Tishasoumya-02 Jun 9, 2023
3e1795d
Prettier formated
Tishasoumya-02 Jun 9, 2023
b13a244
Merge branch 'breadcrumbs-refactor' of https://github.com/plone/volto…
Tishasoumya-02 Jun 9, 2023
64be354
Prettier & propTypes
Tishasoumya-02 Jun 15, 2023
58c6698
Merge branch 'master' into breadcrumbs-refactor
Tishasoumya-02 Jun 19, 2023
2edf200
Merge branch 'master' of https://github.com/plone/volto into breadcru…
Tishasoumya-02 Jun 19, 2023
21ac068
Add Documentation to hooks, restore test
Tishasoumya-02 Jun 19, 2023
7f9bc86
Merge branch 'breadcrumbs-refactor' of https://github.com/plone/volto…
Tishasoumya-02 Jun 19, 2023
64df0b4
Restore test file
Tishasoumya-02 Jun 19, 2023
9e8abe4
Merge branch 'master' into breadcrumbs-refactor
Tishasoumya-02 Jun 19, 2023
9dbde43
removing error
Tishasoumya-02 Jun 19, 2023
bd4a555
Merge branch 'master' of https://github.com/plone/volto into breadcru…
Tishasoumya-02 Jun 19, 2023
d633280
Merge branch 'breadcrumbs-refactor' of https://github.com/plone/volto…
Tishasoumya-02 Jun 19, 2023
74e4c96
removing error
Tishasoumya-02 Jun 19, 2023
b98fcdd
Remove unecessary proptypes
Tishasoumya-02 Jun 20, 2023
05224df
Remove error
Tishasoumya-02 Jun 20, 2023
b36b112
Merge branch 'master' into breadcrumbs-refactor
nileshgulia1 Jun 24, 2023
dd71fdc
Merge branch 'master' of https://github.com/plone/volto into breadcru…
Tishasoumya-02 Jun 25, 2023
62cec9c
Add hooks to index
Tishasoumya-02 Jun 25, 2023
fb76c3f
Merge branch 'breadcrumbs-refactor' of https://github.com/plone/volto…
Tishasoumya-02 Jun 25, 2023
4e1b129
prettier
Tishasoumya-02 Jun 25, 2023
52b45ee
prettier
Tishasoumya-02 Jun 25, 2023
3007a82
Merge branch 'master' of https://github.com/plone/volto into breadcru…
Tishasoumya-02 Jun 28, 2023
eb8670b
Storybook
Tishasoumya-02 Jun 28, 2023
0df3d85
Merge branch 'master' of https://github.com/plone/volto into breadcru…
Tishasoumya-02 Jul 5, 2023
e451000
useSelector hook moved in the functional component
Tishasoumya-02 Jul 5, 2023
04dd890
delete unwanted hook
Tishasoumya-02 Jul 6, 2023
ba415e2
Merge branch 'master' into breadcrumbs-refactor
Tishasoumya-02 Jul 6, 2023
5e9aa0a
use redux hooks directly
Tishasoumya-02 Jul 8, 2023
e0d6322
Merge branch 'master' of https://github.com/plone/volto into breadcru…
Tishasoumya-02 Jul 8, 2023
28c46a2
Merge branch 'breadcrumbs-refactor' of https://github.com/plone/volto…
Tishasoumya-02 Jul 8, 2023
a9cc08b
merge conflict resolve
Tishasoumya-02 Jul 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/4858.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor BreadcrumbsComponent @Tishasoumya-02
151 changes: 52 additions & 99 deletions src/components/theme/Breadcrumbs/Breadcrumbs.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
/**
* Breadcrumbs components.
* @module components/theme/Breadcrumbs/Breadcrumbs
*/

import React, { Component } from 'react';
import { useEffect } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { compose } from 'redux';
import { Link } from 'react-router-dom';
import { Breadcrumb, Container, Segment } from 'semantic-ui-react';
import { defineMessages, injectIntl } from 'react-intl';
import { defineMessages, useIntl } from 'react-intl';
import { useDispatch, useSelector, shallowEqual } from 'react-redux';

import { Icon } from '@plone/volto/components';
import { getBreadcrumbs } from '@plone/volto/actions';
import { getBaseUrl, hasApiExpander } from '@plone/volto/helpers';

import { Icon } from '@plone/volto/components';
import homeSVG from '@plone/volto/icons/home.svg';

const messages = defineMessages({
Expand All @@ -28,96 +21,56 @@ const messages = defineMessages({
},
});

/**
* Breadcrumbs container class.
*/
export class BreadcrumbsComponent extends Component {
/**
* Property types.
* @property {Object} propTypes Property types.
* @static
*/
static propTypes = {
getBreadcrumbs: PropTypes.func.isRequired,
pathname: PropTypes.string.isRequired,
root: PropTypes.string,
items: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.string,
url: PropTypes.string,
}),
).isRequired,
};
const BreadcrumbsComponent = ({ pathname }) => {
const intl = useIntl();
const dispatch = useDispatch();

componentDidMount() {
if (!hasApiExpander('breadcrumbs', getBaseUrl(this.props.pathname))) {
this.props.getBreadcrumbs(getBaseUrl(this.props.pathname));
}
}
const items = useSelector((state) => state.breadcrumbs.items, shallowEqual);
const root = useSelector((state) => state.breadcrumbs.root);

/**
* Component will receive props
* @method componentWillReceiveProps
* @param {Object} nextProps Next properties
* @returns {undefined}
*/
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.pathname !== this.props.pathname) {
if (!hasApiExpander('breadcrumbs', getBaseUrl(this.props.pathname))) {
this.props.getBreadcrumbs(getBaseUrl(nextProps.pathname));
}
useEffect(() => {
if (!hasApiExpander('breadcrumbs', getBaseUrl(pathname))) {
dispatch(getBreadcrumbs(getBaseUrl(pathname)));
}
}
}, [dispatch, pathname]);

return (
<Segment
role="navigation"
aria-label={intl.formatMessage(messages.breadcrumbs)}
className="breadcrumbs"
secondary
vertical
>
<Container>
<Breadcrumb>
<Link
to={root || '/'}
className="section"
title={intl.formatMessage(messages.home)}
>
<Icon name={homeSVG} size="18px" />
</Link>
{items.map((item, index, items) => [
<Breadcrumb.Divider key={`divider-${item.url}`} />,
index < items.length - 1 ? (
<Link key={item.url} to={item.url} className="section">
{item.title}
</Link>
) : (
<Breadcrumb.Section key={item.url} active>
{item.title}
</Breadcrumb.Section>
),
])}
</Breadcrumb>
</Container>
</Segment>
);
};

/**
* Render method.
* @method render
* @returns {string} Markup for the component.
*/
render() {
return (
<Segment
role="navigation"
aria-label={this.props.intl.formatMessage(messages.breadcrumbs)}
className="breadcrumbs"
secondary
vertical
>
<Container>
<Breadcrumb>
<Link
to={this.props.root || '/'}
className="section"
title={this.props.intl.formatMessage(messages.home)}
>
<Icon name={homeSVG} size="18px" />
</Link>
{this.props.items.map((item, index, items) => [
<Breadcrumb.Divider key={`divider-${item.url}`} />,
index < items.length - 1 ? (
<Link key={item.url} to={item.url} className="section">
{item.title}
</Link>
) : (
<Breadcrumb.Section key={item.url} active>
{item.title}
</Breadcrumb.Section>
),
])}
</Breadcrumb>
</Container>
</Segment>
);
}
}
BreadcrumbsComponent.propTypes = {
pathname: PropTypes.string.isRequired,
};

export default compose(
injectIntl,
connect(
(state) => ({
items: state.breadcrumbs.items,
root: state.breadcrumbs.root,
}),
{ getBreadcrumbs },
),
)(BreadcrumbsComponent);
export default BreadcrumbsComponent;
27 changes: 14 additions & 13 deletions src/components/theme/Breadcrumbs/Breadcrumbs.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { injectIntl } from 'react-intl';
import React from 'react';
import { BreadcrumbsComponent } from './Breadcrumbs';
import BreadcrumbsComponent from './Breadcrumbs';
import Wrapper from '@plone/volto/storybook';

export const Breadcrumb = injectIntl(({ children, ...args }) => {
return (
<Wrapper location={{ pathname: '/folder2/folder21/doc212' }}>
<Wrapper
anonymous
location={{ pathname: '/folder2/folder21/doc212' }}
customStore={{
breadcrumbs: {
items: [
{ title: 'Blog', url: '/blog' },
{ title: 'My first blog', url: '/blog/my-first-blog' },
],
},
}}
>
<div className="ui segment form attached" style={{ width: '400px' }}>
<BreadcrumbsComponent
pathname=""
items={[
{
'@id': 'https://volto.kitconcept.com/api/Members',
title: 'Users',
},
]}
getBreadcrumbs={() => {}}
{...args}
/>
<BreadcrumbsComponent pathname="" />
</div>
</Wrapper>
);
Expand Down