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

EZP-31680: Added UDW Search language filter #1407

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
margin-right: calculateRem(16px);
}

&__selector-wrapper {
display: flex;
flex-grow: 0.1;
margin-right: calculateRem(16px);
}

&__input {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const selectedContentTypesReducer = (state, action) => {
}
};

const languages = Object.values(window.eZ.adminUiConfig.languages.mappings);

const Search = ({ itemsPerPage }) => {
const allowedContentTypes = useContext(AllowedContentTypesContext);
const [searchText, setSearchText] = useState('');
Expand All @@ -34,6 +36,9 @@ const Search = ({ itemsPerPage }) => {
const [selectedContentTypes, dispatchSelectedContentTypesAction] = useReducer(selectedContentTypesReducer, []);
const [selectedSection, setSelectedSection] = useState('');
const [selectedSubtree, setSelectedSubtree] = useState('');
const firstLanguageCode = languages.length ? languages[0].languageCode : '';
const [selectedLanguage, setSelectedLanguage] = useState(firstLanguageCode);
const updateSelectedLanguage = (event) => setSelectedLanguage(event.target.value);
const [isLoading, data, searchByQuery] = useSearchByQueryFetch();
const updateSearchQuery = ({ target: { value } }) => setSearchText(value);
const search = (forcedOffset) => {
Expand All @@ -49,7 +54,7 @@ const Search = ({ itemsPerPage }) => {

const contentTypes = !!selectedContentTypes.length ? [...selectedContentTypes] : allowedContentTypes;

searchByQuery(searchText, contentTypes, selectedSection, selectedSubtree, itemsPerPage, offset);
searchByQuery(searchText, contentTypes, selectedSection, selectedSubtree, itemsPerPage, offset, selectedLanguage);
};
const handleKeyPressed = ({ charCode }) => {
if (charCode === ENTER_CHAR_CODE) {
Expand Down Expand Up @@ -142,6 +147,21 @@ const Search = ({ itemsPerPage }) => {
Search
</button>
</div>
<div className="c-search__selector-wrapper">
<select className="form-control" onChange={updateSelectedLanguage} value={selectedLanguage}>
{languages.map((language) => {
if (!language.enabled) {
return null;
}

return (
<option key={language.id} value={language.languageCode} onChange={updateSelectedLanguage}>
{language.name}
</option>
);
})}
</select>
</div>
<div className="c-search__filters-btn-wrapper">
<button className="c-search__toggle-filters-btn btn btn-dark" onClick={toggleFiltersCollapsed}>
<Icon name="filters" extraClasses="ez-icon--small-medium ez-icon--light" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useSearchByQueryFetch = () => {
const restInfo = useContext(RestInfoContext);
const [{ isLoading, data }, dispatch] = useReducer(searchByQueryReducer, { isLoading: false, data: {} });
const searchByQuery = useCallback(
(searchText, contentTypesIdentifiers, sectionIdentifier, subtreePathString, limit, offset) => {
(searchText, contentTypesIdentifiers, sectionIdentifier, subtreePathString, limit, offset, languageCode) => {
const handleFetch = (response) => {
dispatch({ type: SEARCH_END, response });
};
Expand All @@ -43,7 +43,7 @@ export const useSearchByQueryFetch = () => {
}

dispatch({ type: SEARCH_START });
findLocationsBySearchQuery({ ...restInfo, query, limit, offset }, handleFetch);
findLocationsBySearchQuery({ ...restInfo, query, limit, offset, languageCode }, handleFetch);
},
[restInfo, dispatch]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ export const loadAccordionData = (
.catch(showErrorNotification);
};

export const findLocationsBySearchQuery = ({ token, siteaccess, query, limit = QUERY_LIMIT, offset = 0 }, callback) => {
export const findLocationsBySearchQuery = ({ token, siteaccess, query, limit = QUERY_LIMIT, offset = 0, languageCode = null }, callback) => {
const useAlwaysAvailable = true;
Copy link
Member

Choose a reason for hiding this comment

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

I'm no familiar with this option, is this something I would like to change to false in some cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

@dew326 I don't think it should be changed for false while searching in UDW, its hard-coded to true in main "Search" module as well.

Copy link
Member Author

@barw4 barw4 Jun 23, 2020

Choose a reason for hiding this comment

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

"useAlwaysAvailable defaults to true to avoid exceptions on missing translations"

const body = JSON.stringify({
ViewInput: {
identifier: `udw-locations-by-search-query-${query.FullTextCriterion}`,
public: false,
languageCode,
useAlwaysAvailable,
LocationQuery: {
FacetBuilders: {},
SortClauses: {},
Expand Down