Skip to content

Commit

Permalink
fix: sitemap in multilingual sites was erroring (#639)
Browse files Browse the repository at this point in the history
* fix: sitemap in multilingual sites was erroring, volto bug, fixed

* fix: sitemap in multilingual sites was erroring, volto bug, fixed

---------

Co-authored-by: Piero Nicolli <[email protected]>
  • Loading branch information
deodorhunter and pnicolli authored Apr 9, 2024
1 parent a957571 commit c86add5
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 36 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

- Nel blocco Argomenti in Evidenza se non ci sono card ma etichette argomento, il blocco non renderizza più lo sfondo per un maggiore contrasto con le etichette, di conseguenza il titolo del blocco rimane nero e non bianco.
- Aggiunto il titolo per la sezione "Organizzatore esterno" quando il campo è compilato nel tipo di contenuto Evento.
- Sistemato un problema per cui la visualizzazione della sitemap in presenza di un sito multilingua generava errore.
- Migliorata l'accessibilità dei link nel footer.

## Versione 11.9.1 (03/04/2024)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,41 +72,32 @@ function SelectFacetFilterListEntry(props) {
</>
) : (
<>
{facets[facet]?.length > 0 && (
{((Array.isArray(facets?.[facet]) && facets?.[facet]?.length > 0) ||
(!Array.isArray(facets?.[facet]) && Boolean(facets?.[facet]))) && (
<span className="label-title mb-2">
{facetSettings.title ?? facetSettings?.field?.label}
</span>
)}
{facets[facet].map((entry, i) => {
const label = Array.isArray(selectedValue)
? selectedValue?.find((sv) => sv.value === entry)?.label ?? ''
: '';
return (
<Label key={i} className="d-flex w-100 py-1">
<span>{label}</span>
<Button
className="p-0"
onClick={() => {
const entries = facets[facet].filter((item) => item !== entry);
!isEditMode &&
setFacets({
...facets,
[facet]: entries,
});
}}
aria-label={intl.formatMessage(
commonSearchBlockMessages.clearFilter,
{
filterName: label,
},
)}
title={intl.formatMessage(commonSearchBlockMessages.clearFilter, {
filterName: label,
})}
>
<Icon
icon="it-close"
size="md"
{Array.isArray(facets?.[facet]) &&
facets?.[facet]?.map((entry, i) => {
const label = Array.isArray(selectedValue)
? selectedValue?.find((sv) => sv.value === entry)?.label ?? ''
: '';
return (
<Label key={i} className="d-flex w-100 py-1">
<span>{label}</span>
<Button
className="p-0"
onClick={() => {
const entries = facets?.[facet]?.filter(
(item) => item !== entry,
);
!isEditMode &&
setFacets({
...facets,
[facet]: entries,
});
}}
aria-label={intl.formatMessage(
commonSearchBlockMessages.clearFilter,
{
Expand All @@ -119,11 +110,27 @@ function SelectFacetFilterListEntry(props) {
filterName: label,
},
)}
/>
</Button>
</Label>
);
})}
>
<Icon
icon="it-close"
size="md"
aria-label={intl.formatMessage(
commonSearchBlockMessages.clearFilter,
{
filterName: label,
},
)}
title={intl.formatMessage(
commonSearchBlockMessages.clearFilter,
{
filterName: label,
},
)}
/>
</Button>
</Label>
);
})}
</>
);
}
Expand Down
126 changes: 126 additions & 0 deletions src/customizations/volto/components/theme/Sitemap/Sitemap.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
CUSTOMIZATIONS:
- make it work, prop name lang was wrong, remove in volto 18
*/

import { useEffect } from 'react';
import PropTypes from 'prop-types';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { asyncConnect } from '@plone/volto/helpers';
import { defineMessages, injectIntl } from 'react-intl';
import { Container as SemanticContainer } from 'semantic-ui-react';
import { Helmet, toBackendLang } from '@plone/volto/helpers';
import { Link } from 'react-router-dom';
import config from '@plone/volto/registry';

import { getNavigation } from '@plone/volto/actions';

const messages = defineMessages({
Sitemap: {
id: 'Sitemap',
defaultMessage: 'Sitemap',
},
});

export function getSitemapPath(pathname = '', lang) {
const prefix = pathname.replace(/\/sitemap$/gm, '').replace(/^\//, '');
const path = prefix || lang || '';
return path;
}

/**
* Sitemap function component.
* @function Sitemap
* @param {Object} props - Component properties.
* @returns {JSX.Element} - Rendered component.
*/
function Sitemap(props) {
const {
location: { pathname },
lang,
getNavigation,
} = props;

useEffect(() => {
const { settings } = config;
const language = settings.isMultilingual ? `${toBackendLang(lang)}` : null;
const path = getSitemapPath(pathname, language);
getNavigation(path, 4);
}, [pathname, lang, getNavigation]);

const renderItems = (items) => {
return (
<ul>
{items.map((item) => (
<li
key={item.url}
className={item.items?.length > 0 ? 'with-children' : ''}
>
<Link to={item.url}>{item.title}</Link>
{item.items && renderItems(item.items)}
</li>
))}
</ul>
);
};

const Container =
config.getComponent({ name: 'Container' }).component || SemanticContainer;

return (
<div id="page-sitemap">
<Helmet title={props.intl.formatMessage(messages.Sitemap)} />
<Container className="view-wrapper">
<h1>{props.intl.formatMessage(messages.Sitemap)} </h1>
{props.items && renderItems(props.items)}
</Container>
</div>
);
}

Sitemap.propTypes = {
getNavigation: PropTypes.func.isRequired,
location: PropTypes.object.isRequired,
intl: PropTypes.object.isRequired,
lang: PropTypes.string.isRequired,
items: PropTypes.array.isRequired,
};

export const __test__ = compose(
injectIntl,
connect(
(state) => ({
items: state.navigation.items,
lang: state.intl.locale,
}),
{ getNavigation },
),
)(Sitemap);

export default compose(
injectIntl,
connect(
(state) => ({
items: state.navigation.items,
lang: state.intl.locale,
}),
{ getNavigation },
),
asyncConnect([
{
key: 'navigation',
promise: ({ location, store: { dispatch, getState } }) => {
if (!__SERVER__) return;
const { settings } = config;
const path = getSitemapPath(
location.pathname,
settings.isMultilingual
? toBackendLang(getState().intl.locale)
: null,
);
return dispatch(getNavigation(path, 4));
},
},
]),
)(Sitemap);

0 comments on commit c86add5

Please sign in to comment.