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

Refactor Search Tags #4873

Merged
merged 33 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f057bf9
Refactored
Tishasoumya-02 Jun 12, 2023
073b5fe
Refactored
Tishasoumya-02 Jun 12, 2023
092bfe8
Adding facade hook
Tishasoumya-02 Jun 12, 2023
fbc1e28
Adding facade hook
Tishasoumya-02 Jun 12, 2023
78a4e94
Merge branch 'master' of https://github.com/plone/volto into searchta…
Tishasoumya-02 Jun 15, 2023
5297065
Added isRequired to propTypes
Tishasoumya-02 Jun 15, 2023
c699abd
/news
Tishasoumya-02 Jun 15, 2023
6b2f4d3
/news
Tishasoumya-02 Jun 15, 2023
b0a5806
Deleting news/4871.feature created by mistake
Tishasoumya-02 Jun 15, 2023
832c9da
Prettier , Added required props in test
Tishasoumya-02 Jun 15, 2023
2741cee
Merge branch 'master' of https://github.com/plone/volto into searchta…
Tishasoumya-02 Jun 19, 2023
9a3f3e1
Add docs to hooks ,proptypes
Tishasoumya-02 Jun 19, 2023
4e9ef1c
Prettier
Tishasoumya-02 Jun 19, 2023
77db26b
Test file restore
Tishasoumya-02 Jun 19, 2023
0703dc5
Update useVocabularies.js
Tishasoumya-02 Jun 20, 2023
69f902a
Remove Proptypes
Tishasoumya-02 Jun 20, 2023
3da0b82
Merge branch 'searchtag-refactor' of https://github.com/plone/volto i…
Tishasoumya-02 Jun 20, 2023
108700c
Remove Proptypes
Tishasoumya-02 Jun 20, 2023
d311f61
Merge branch 'master' into searchtag-refactor
nileshgulia1 Jun 26, 2023
d14f35c
Merge branch 'master' of https://github.com/plone/volto into searchta…
Tishasoumya-02 Jun 26, 2023
c4a38d4
Pass vocabulary as prop
Tishasoumya-02 Jun 26, 2023
2d5682c
Merge branch 'searchtag-refactor' of https://github.com/plone/volto i…
Tishasoumya-02 Jun 26, 2023
0bd8cca
Merge branch 'master' into searchtag-refactor
Tishasoumya-02 Jun 28, 2023
3298d1d
Merge branch 'master' of https://github.com/plone/volto into searchta…
Tishasoumya-02 Jul 5, 2023
c45c358
useSelector in the component
Tishasoumya-02 Jul 5, 2023
27eb001
Merge branch 'searchtag-refactor' of https://github.com/plone/volto i…
Tishasoumya-02 Jul 5, 2023
8302ed7
use redux hooks directly
Tishasoumya-02 Jul 8, 2023
2fe8c8b
Merge branch 'master' into searchtag-refactor
Tishasoumya-02 Jul 8, 2023
818e717
Merge branch 'master' of https://github.com/plone/volto into searchta…
Tishasoumya-02 Jul 11, 2023
72f25ac
Merge branch 'searchtag-refactor' of https://github.com/plone/volto i…
Tishasoumya-02 Jul 11, 2023
25e2d98
Merge branch 'master' into searchtag-refactor
Tishasoumya-02 Jul 12, 2023
a8a0cf8
Merge branch 'master' into searchtag-refactor
Tishasoumya-02 Jul 31, 2023
14f3dc5
Merge branch 'master' into searchtag-refactor
nileshgulia1 Aug 14, 2023
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/4873.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactore SearchTags @Tishasoumya-02
90 changes: 30 additions & 60 deletions src/components/theme/Search/SearchTags.jsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,41 @@
/**
* Search tags components.
* @module components/theme/Search/SearchTags
*/

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { useEffect } from 'react';
import { useDispatch, useSelector, shallowEqual } from 'react-redux';
import { Link } from 'react-router-dom';

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

const vocabulary = 'plone.app.vocabularies.Keywords';

/**
* Search tags container class.
* @class SearchTags
* @extends Component
*/
class SearchTags extends Component {
/**
* Property types.
* @property {Object} propTypes Property types.
* @static
*/
static propTypes = {
getVocabulary: PropTypes.func.isRequired,
items: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string,
}),
).isRequired,
};

componentDidMount() {
this.props.getVocabulary({ vocabNameOrURL: vocabulary });
}
const SearchTags = () => {
const dispatch = useDispatch();

/**
* Render method.
* @method render
* @returns {string} Markup for the component.
*/
render() {
return this.props.items && this.props.items.length > 0 ? (
<div>
{this.props.items.map((item) => (
<Link
className="ui label"
to={`/search?Subject=${item.label}`}
key={item.label}
>
{item.label}
</Link>
))}
</div>
) : (
<span />
);
}
}
useEffect(() => {
dispatch(getVocabulary({ vocabNameOrURL: vocabulary }));
Tishasoumya-02 marked this conversation as resolved.
Show resolved Hide resolved
}, [dispatch]);

export default connect(
(state) => ({
items:
const items = useSelector(
(state) =>
state.vocabularies[vocabulary] && state.vocabularies[vocabulary].items
? state.vocabularies[vocabulary].items
: [],
}),
{ getVocabulary },
)(SearchTags);
shallowEqual,
);

return items && items.length > 0 ? (
<div>
{items.map((item) => (
<Link
className="ui label"
to={`/search?Subject=${item.label}`}
key={item.label}
>
{item.label}
</Link>
))}
</div>
) : (
<span />
);
};

export default SearchTags;