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

Use navroot to render the sitemap (targets 17.x.x) #5185

Merged
merged 39 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ee2675a
use a config setting to set the sitemap depth
erral Sep 14, 2023
5265143
use navroot to render the sitemap
erral Sep 14, 2023
d8ca93f
changelog
erral Sep 14, 2023
ffa4463
restore config
erral Sep 14, 2023
c1a2552
Add external className to slate Link view. (#5188)
iFlameing Sep 15, 2023
8592c34
Update delete content modal for link integrity (#4786)
danalvrz Sep 18, 2023
3f03d9f
TypeScript support in core (#4662)
sneridagh Sep 18, 2023
fc4992d
Release 17.0.0-alpha.27
sneridagh Sep 18, 2023
d3ff128
Release generate-volto 7.0.0-alpha.7
sneridagh Sep 18, 2023
58cfb4c
Add missing empty lock to acceptance generator addon folder (#5193)
sneridagh Sep 18, 2023
de072db
Release generate-volto 7.0.0-alpha.8
sneridagh Sep 18, 2023
435699b
Remove JSON files from being linted by ESlint, since it's not its pur…
sneridagh Sep 18, 2023
2c33991
Fix instruction to fetch add-on from repo (#5196)
ksuess Sep 18, 2023
2db6c3a
Fix api convenience buildout build
sneridagh Sep 19, 2023
9e95e9c
Fix standalone navigation action call if expander is set (#5197)
sneridagh Sep 19, 2023
bb9e6af
Refactor PersonalTool component (#4954)
Tishasoumya-02 Sep 19, 2023
be53691
Refactor Sidebar (#4965)
Tishasoumya-02 Sep 19, 2023
cba0763
Refactor Content Property Model (#4968)
Tishasoumya-02 Sep 19, 2023
4d4110f
Refactor Content workflow Modal (#4969)
Tishasoumya-02 Sep 19, 2023
8e2a13e
Refactor Content Tags Modal (#4970)
Tishasoumya-02 Sep 19, 2023
33c1306
Refactor Content Rename Model (#4971)
Tishasoumya-02 Sep 19, 2023
9e7d3e7
tests
erral Sep 15, 2023
86d4a9e
Merge branch 'master' into erral-sitemap
erral Sep 19, 2023
025ba57
fix
erral Sep 19, 2023
3833b31
Merge branch 'master' into erral-sitemap
erral Sep 26, 2023
da608fc
Merge branch 'main' into erral-sitemap
erral Oct 19, 2023
568aee0
keep the getSitemapPath function and mark it as deprecated
erral Oct 22, 2023
7eed6c2
keep functionality
erral Oct 22, 2023
b354ed4
keep tests
erral Oct 22, 2023
41ce501
merge
erral Dec 1, 2023
8850c07
adapt code to the changes in the component
erral Dec 1, 2023
007b388
delete unneeded
erral Dec 1, 2023
334057a
Merge branch '17.x.x' into erral-sitemap
erral Dec 23, 2023
9a51a6d
Merge branch '17.x.x' into erral-sitemap
erral Jan 4, 2024
b7ae8c0
Merge branch '17.x.x' into erral-sitemap
erral Jan 28, 2024
673ac6c
Merge branch '17.x.x' into erral-sitemap
erral Mar 8, 2024
a059b03
lint
erral Mar 8, 2024
d4e5c02
fix test
erral Mar 10, 2024
68f57b1
adjust state attribute
erral Mar 10, 2024
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/5185.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use navroot to render the sitemap @erral
43 changes: 14 additions & 29 deletions src/components/theme/Sitemap/Sitemap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { asyncConnect } from '@plone/volto/helpers';
import { asyncConnect, flattenToAppURL } from '@plone/volto/helpers';
import { defineMessages, injectIntl } from 'react-intl';
import { Container } from 'semantic-ui-react';
import { Helmet, toBackendLang } from '@plone/volto/helpers';
import { Helmet } from '@plone/volto/helpers';
import { Link } from 'react-router-dom';
import config from '@plone/volto/registry';

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

const messages = defineMessages({
Sitemap: {
Expand All @@ -23,12 +23,6 @@ const messages = defineMessages({
},
});

export function getSitemapPath(pathname = '', lang) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a breaking change because the getSitemapPath is removed. Let's keep it and mark it as deprecated? @sneridagh your thoughts on this?

Copy link
Member Author

@erral erral Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have kept the function and the tests, but mark it as deprecated with a docstring. This way, as you say, if anyone is using the function, it keeps working.

Would that be enough?

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

/**
* Sitemap class.
* @class Sitemap
Expand All @@ -45,14 +39,10 @@ class Sitemap extends Component {
};

componentDidMount() {
const { settings } = config;

const lang = settings.isMultilingual
? `${toBackendLang(this.props.lang)}`
: null;

const path = getSitemapPath(this.props.location.pathname, lang);
this.props.getNavigation(path, 4);
this.props.getNavigation(
flattenToAppURL(this.props.navroot?.navroot?.['@id']),
config.settings.siteMapDepth,
);
}

/**
Expand Down Expand Up @@ -95,9 +85,9 @@ export const __test__ = compose(
connect(
(state) => ({
items: state.navigation.items,
lang: state.intl.locale,
navroot: state.navroot.data,
}),
{ getNavigation },
{ getNavigation, getNavroot },
),
)(Sitemap);

Expand All @@ -106,25 +96,20 @@ export default compose(
connect(
(state) => ({
items: state.navigation.items,
lang: state.intl.locale,
navroot: state.navroot.data,
}),
{ getNavigation },
{ getNavigation, getNavroot },
),
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,
const navroot = getState().navroot.data?.navroot?.navroot?.['@id'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the navroot available in both 7.x and 8.x branches of plone.restapi?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No right now it is not. But I can try to add a PR to backport them .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it need to be backported? This fix will go in Volto 17 and maybe Volto 16, which both expect plone.restapi 8.x, even on Plone 5.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/plone/plone.restapi/blob/ed192208499989b379de8534a3aa12d037316db4/setup.py#L11

Volto 16 works fine with Plone 4, we're using it in production on a complex site. If this PR is backported to Volto 16, it will be a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I didn't know you are using Volto 16 with Plone 4. That is not officially supported, as far as I am aware, and there are no automated tests for it in volto. So this is a risk you took on in using Volto 16 with an unsupported Plone version. But, I agree we should avoid breaking that, unless it's really hard to avoid.

Copy link
Member Author

@erral erral Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The navroot endpoints are not that complex, I would say that they could be backported to 7.x easily. But let's see what the tests say 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return dispatch(
getNavigation(flattenToAppURL(navroot), config.settings.siteMapDepth),
);

return dispatch(getNavigation(path, 4));
},
},
]),
Expand Down
28 changes: 6 additions & 22 deletions src/components/theme/Sitemap/Sitemap.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import configureStore from 'redux-mock-store';
import { Provider } from 'react-intl-redux';
import { MemoryRouter } from 'react-router-dom';

import { __test__ as Sitemap, getSitemapPath } from './Sitemap';
import { __test__ as Sitemap } from './Sitemap';

const mockStore = configureStore();

Expand Down Expand Up @@ -42,6 +42,11 @@ describe('Sitemap', () => {
locale: 'en',
messages: {},
},
navroot: {
navroot: {
'@id': 'http://localhost:8080/Plone',
},
},
});
const component = renderer.create(
<Provider store={store}>
Expand All @@ -54,24 +59,3 @@ describe('Sitemap', () => {
expect(json).toMatchSnapshot();
});
});

describe('getSitemapPath', () => {
it('accepts empty path', () => {
expect(getSitemapPath('', null)).toBe('');
});

it('accepts a path', () => {
expect(getSitemapPath('/page-1/sitemap', null)).toBe('page-1');
});
it('accepts a path', () => {
expect(getSitemapPath('/page-1/sitemap', null)).toBe('page-1');
});

it('uses a language as default root', () => {
expect(getSitemapPath('/', 'de')).toBe('de');
});

it('accepts language-rooted paths', () => {
expect(getSitemapPath('/de/mission', 'de')).toBe('de/mission');
});
});
1 change: 1 addition & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ let config = {
supportedLanguages: ['en'],
defaultLanguage: 'en',
navDepth: 1,
siteMapDepth: 4,
expressMiddleware: serverConfig.expressMiddleware, // BBB
defaultBlockType: 'slate',
verticalFormTabs: false,
Expand Down