Skip to content

Commit e5c66c0

Browse files
committed
Use container from component registry in sitemap component and also refactor the class to functional component(#5418)
1 parent 251ea7a commit e5c66c0

File tree

2 files changed

+42
-50
lines changed

2 files changed

+42
-50
lines changed

news/5418.feature

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use container from component registry in sitemap component and also refactor the class
2+
to functional component. @iRohitSingh

src/components/theme/Sitemap/Sitemap.jsx

+40-50
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
/**
2-
* Login container.
3-
* @module components/theme/Sitemap/Sitemap
4-
*/
5-
6-
import React, { Component } from 'react';
1+
import { useEffect } from 'react';
72
import PropTypes from 'prop-types';
83
import { compose } from 'redux';
94
import { connect } from 'react-redux';
105
import { asyncConnect } from '@plone/volto/helpers';
116
import { defineMessages, injectIntl } from 'react-intl';
12-
import { Container } from 'semantic-ui-react';
7+
import { Container as SemanticContainer } from 'semantic-ui-react';
138
import { Helmet, toBackendLang } from '@plone/volto/helpers';
149
import { Link } from 'react-router-dom';
1510
import config from '@plone/volto/registry';
@@ -30,38 +25,26 @@ export function getSitemapPath(pathname = '', lang) {
3025
}
3126

3227
/**
33-
* Sitemap class.
34-
* @class Sitemap
35-
* @extends Component
28+
* Sitemap function component.
29+
* @function Sitemap
30+
* @param {Object} props - Component properties.
31+
* @returns {JSX.Element} - Rendered component.
3632
*/
37-
class Sitemap extends Component {
38-
/**
39-
* Property types.
40-
* @property {Object} propTypes Property types.
41-
* @static
42-
*/
43-
static propTypes = {
44-
getNavigation: PropTypes.func.isRequired,
45-
};
33+
function Sitemap(props) {
34+
const {
35+
location: { pathname },
36+
language,
37+
getNavigation,
38+
} = props;
4639

47-
componentDidMount() {
40+
useEffect(() => {
4841
const { settings } = config;
42+
const lang = settings.isMultilingual ? `${toBackendLang(language)}` : null;
43+
const path = getSitemapPath(pathname, lang);
44+
getNavigation(path, 4);
45+
}, [pathname, language, getNavigation]);
4946

50-
const lang = settings.isMultilingual
51-
? `${toBackendLang(this.props.lang)}`
52-
: null;
53-
54-
const path = getSitemapPath(this.props.location.pathname, lang);
55-
this.props.getNavigation(path, 4);
56-
}
57-
58-
/**
59-
* Render method.
60-
* @method render
61-
* @returns {string} Markup for the component.
62-
*/
63-
64-
renderItems = (items) => {
47+
const renderItems = (items) => {
6548
return (
6649
<ul>
6750
{items.map((item) => (
@@ -70,26 +53,35 @@ class Sitemap extends Component {
7053
className={item.items?.length > 0 ? 'with-children' : ''}
7154
>
7255
<Link to={item.url}>{item.title}</Link>
73-
{item.items && this.renderItems(item.items)}
56+
{item.items && renderItems(item.items)}
7457
</li>
7558
))}
7659
</ul>
7760
);
7861
};
79-
render() {
80-
const { items } = this.props;
81-
return (
82-
<div id="page-sitemap">
83-
<Helmet title={this.props.intl.formatMessage(messages.Sitemap)} />
84-
<Container className="view-wrapper">
85-
<h1>{this.props.intl.formatMessage(messages.Sitemap)} </h1>
86-
{items && this.renderItems(items)}
87-
</Container>
88-
</div>
89-
);
90-
}
62+
63+
const Container =
64+
config.getComponent({ name: 'Container' }).component || SemanticContainer;
65+
66+
return (
67+
<div id="page-sitemap">
68+
<Helmet title={props.intl.formatMessage(messages.Sitemap)} />
69+
<Container className="view-wrapper">
70+
<h1>{props.intl.formatMessage(messages.Sitemap)} </h1>
71+
{props.items && renderItems(props.items)}
72+
</Container>
73+
</div>
74+
);
9175
}
9276

77+
Sitemap.propTypes = {
78+
getNavigation: PropTypes.func.isRequired,
79+
location: PropTypes.object.isRequired,
80+
intl: PropTypes.object.isRequired,
81+
lang: PropTypes.string.isRequired,
82+
items: PropTypes.array.isRequired,
83+
};
84+
9385
export const __test__ = compose(
9486
injectIntl,
9587
connect(
@@ -116,14 +108,12 @@ export default compose(
116108
promise: ({ location, store: { dispatch, getState } }) => {
117109
if (!__SERVER__) return;
118110
const { settings } = config;
119-
120111
const path = getSitemapPath(
121112
location.pathname,
122113
settings.isMultilingual
123114
? toBackendLang(getState().intl.locale)
124115
: null,
125116
);
126-
127117
return dispatch(getNavigation(path, 4));
128118
},
129119
},

0 commit comments

Comments
 (0)