-
-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
355 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Plone\n" | ||
"POT-Creation-Date: 2024-07-24T09:39:31.887Z\n" | ||
"POT-Creation-Date: 2024-07-30T20:44:58.534Z\n" | ||
"Last-Translator: Plone i18n <[email protected]>\n" | ||
"Language-Team: Plone i18n <[email protected]>\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
|
@@ -2797,6 +2797,11 @@ msgstr "" | |
msgid "Registration form" | ||
msgstr "" | ||
|
||
#. Default: "Related Items" | ||
#: components/theme/RelatedItems/RelatedItems | ||
msgid "Related Items" | ||
msgstr "" | ||
|
||
#. Default: "Relation" | ||
#: components/manage/Controlpanels/Relations/RelationsMatrix | ||
#: helpers/MessageLabels/MessageLabels | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Show related items. | ||
@wesleybl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/volto/src/components/theme/RelatedItems/RelatedItems.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
85
packages/volto/src/components/theme/RelatedItems/RelatedItems.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
Oops, something went wrong.