Skip to content

Commit

Permalink
Show related items
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleybl committed Feb 8, 2023
1 parent 2dc7836 commit 01573a8
Show file tree
Hide file tree
Showing 21 changed files with 345 additions and 1 deletion.
5 changes: 5 additions & 0 deletions locales/ca/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,11 @@ msgstr "Registrar-se"
msgid "Registration form"
msgstr "Formulari d'inscripció"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/de/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,11 @@ msgstr "Registrieren"
msgid "Registration form"
msgstr "Registrierungsformular"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/en/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,11 @@ msgstr ""
msgid "Registration form"
msgstr ""

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/es/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,11 @@ msgstr "Registro"
msgid "Registration form"
msgstr "Formulario de registro"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/eu/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,11 @@ msgstr "Izena eman"
msgid "Registration form"
msgstr "Erregistro formularioa"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/fr/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,11 @@ msgstr "S'enregistrer"
msgid "Registration form"
msgstr "Formulaire d'enregistrement"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/it/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,11 @@ msgstr "Registrati"
msgid "Registration form"
msgstr "Form di iscrizione"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/ja/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2561,6 +2561,11 @@ msgstr "登録"
msgid "Registration form"
msgstr "登録フォーム"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/nl/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,11 @@ msgstr "Registreren"
msgid "Registration form"
msgstr "Registratieformulier"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/pt/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2561,6 +2561,11 @@ msgstr "Registar"
msgid "Registration form"
msgstr "Formulário de registo"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/pt_BR/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,11 @@ msgstr "Cadastro"
msgid "Registration form"
msgstr "Formulário de cadastro"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr "Itens relacionados"

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/ro/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,11 @@ msgstr "Înregistrare"
msgid "Registration form"
msgstr "Formular de înregistrare"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
7 changes: 6 additions & 1 deletion locales/volto.pot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
"POT-Creation-Date: 2022-12-12T12:33:16.481Z\n"
"POT-Creation-Date: 2023-02-08T17:02:07.814Z\n"
"Last-Translator: Plone i18n <[email protected]>\n"
"Language-Team: Plone i18n <[email protected]>\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -2555,6 +2555,11 @@ msgstr ""
msgid "Registration form"
msgstr ""

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
5 changes: 5 additions & 0 deletions locales/zh_CN/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,11 @@ msgstr "注册"
msgid "Registration form"
msgstr "注册表单"

#: components/theme/RelatedItems/RelatedItems
# defaultMessage: Related Items
msgid "Related Items"
msgstr ""

#: components/theme/Search/Search
# defaultMessage: Relevance
msgid "Relevance"
Expand Down
2 changes: 2 additions & 0 deletions news/3740.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Show related items.
@wesleybl
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export Title from '@plone/volto/components/theme/Title/Title';
export DefaultView from '@plone/volto/components/theme/View/DefaultView';
export Pagination from '@plone/volto/components/theme/Pagination/Pagination';
export Tags from '@plone/volto/components/theme/Tags/Tags';
export RelatedItems from '@plone/volto/components/theme/RelatedItems/RelatedItems';
export OutdatedBrowser from '@plone/volto/components/theme/OutdatedBrowser/OutdatedBrowser';
export LanguageSelector from '@plone/volto/components/theme/LanguageSelector/LanguageSelector';
export RenderBlocks from '@plone/volto/components/theme/View/RenderBlocks';
Expand Down
74 changes: 74 additions & 0 deletions src/components/theme/RelatedItems/RelatedItems.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* RelatedItems component.
* @module components/theme/RelatedItems/RelatedItems
*/

import React from 'react';
import { UniversalLink } from '@plone/volto/components';
import { defineMessages, injectIntl } from 'react-intl';
import PropTypes from 'prop-types';
import { Container } from 'semantic-ui-react';

const messages = defineMessages({
relatedItems: {
id: 'Related Items',
defaultMessage: 'Related Items',
},
});

/**
* Related Items component.
* @function RelatedItems
* @param {array} tags Array of related items.
* @returns {string} Markup of the component.
*/

const RelatedItems = ({ relatedItems, intl }) =>
relatedItems && relatedItems.length > 0 ? (
<Container>
<h4 className="ui header">{intl.formatMessage(messages.relatedItems)}</h4>
<div className="ui list">
{relatedItems.map((relatedItem) =>
relatedItem ? (
<div className="item" key={relatedItem['@id']}>
<div className="content">
<UniversalLink className="header" item={relatedItem}>
<div>{relatedItem['title']}</div>
<div className="description">
{relatedItem['description']}
</div>
</UniversalLink>
</div>
</div>
) : null,
)}
</div>
</Container>
) : (
<span />
);

/**
* Property types.
* @property {Object} propTypes Property types.
* @static
*/
RelatedItems.propTypes = {
relatedItems: PropTypes.arrayOf(
PropTypes.shape({
'@id': PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
}),
),
};

/**
* Default properties.
* @property {Object} defaultProps Default properties.
* @static
*/
RelatedItems.defaultProps = {
RelatedItems: null,
};

export default injectIntl(RelatedItems);
85 changes: 85 additions & 0 deletions src/components/theme/RelatedItems/RelatedItems.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react';
import renderer from 'react-test-renderer';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-intl-redux';
import { MemoryRouter } from 'react-router-dom';

import RelatedItems from './RelatedItems';

const mockStore = configureStore();

describe('Related Items', () => {
it('renders without related items', () => {
const store = mockStore({
intl: {
locale: 'en',
messages: {},
},
});
const component = renderer.create(
<Provider store={store}>
<MemoryRouter>
<RelatedItems />
</MemoryRouter>
</Provider>,
);
const json = component.toJSON();
expect(json).toMatchSnapshot();
});

it('renders with related items', () => {
const store = mockStore({
intl: {
locale: 'en',
messages: {},
},
});
const relatedItems = [
{
'@id': '/test-1',
title: 'Title 1',
description: 'Description 1',
},
{
'@id': '/test-2',
title: 'Title 2',
description: 'Description 2',
},
];
const component = renderer.create(
<Provider store={store}>
<MemoryRouter>
<RelatedItems relatedItems={relatedItems} />
</MemoryRouter>
</Provider>,
);
const json = component.toJSON();
expect(json).toMatchSnapshot();
});

it('renders with related items has null', () => {
const store = mockStore({
intl: {
locale: 'en',
messages: {},
},
});
const relatedItems = [
{
'@id': '/test-1',
title: 'Title 1',
description: 'Description 1',
},
null,
];
const component = renderer.create(
<Provider store={store}>
<MemoryRouter>
<RelatedItems relatedItems={relatedItems} />
</MemoryRouter>
</Provider>,
);
const json = component.toJSON();
expect(json).toMatchSnapshot();
});
});
Loading

0 comments on commit 01573a8

Please sign in to comment.