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-30904: UDW: Sorting settings are ignored for starting location #209

Merged
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 @@ -6,6 +6,7 @@ import { loadPreselectedLocationData, QUERY_LIMIT } from '../../services/univers
import deepClone from '../../../common/helpers/deep.clone.helper';

const ROOT_LOCATION_OBJECT = null;
const ROOT_LOCATION_ID = 1;

export default class FinderComponent extends Component {
constructor(props) {
Expand Down Expand Up @@ -41,11 +42,7 @@ export default class FinderComponent extends Component {
} else if (isPreselectedLocation) {
this.loadPreselectedData(this.props.preselectedLocation);
} else {
this.setDefaultActiveLocations();
this.props.findLocationsByParentLocationId(
{ ...this.props.restInfo, parentLocationId: this.props.startingLocationId },
this.updateLocationsData
);
this.handleStartingLocation();
}
}

Expand All @@ -65,6 +62,49 @@ export default class FinderComponent extends Component {
return { locationsMap: this.locationsMap, activeLocations: this.activeLocations };
}

/**
* Loads starting location data (if there is a need) and loads root locations
*
* @method handleStartingLocation
* @memberof FinderComponent
*/
handleStartingLocation() {
// Starting location is a root location
if (this.props.startingLocationId === ROOT_LOCATION_ID) {
this.setDefaultActiveLocations();
this.loadChildren();

return;
}

this.props.loadLocation({ ...this.props.restInfo, locationId: this.props.startingLocationId }, (response) => {
let loadedLocation = null;

if (response.View.Result.searchHits.searchHit.length) {
loadedLocation = response.View.Result.searchHits.searchHit[0].value.Location;

this.setState({ activeLocations: [loadedLocation] });
}

this.loadChildren(loadedLocation);
});
}

/**
* Loads root locations
*
* @method loadChildren
* @memberof FinderComponent
*/
loadChildren(parentLocation) {
const sortClauses = parentLocation ? this.getLocationSortClauses(parentLocation) : {};

this.props.findLocationsByParentLocationId(
{ ...this.props.restInfo, parentLocationId: this.props.startingLocationId, sortClauses },
(response) => this.updateLocationsData(response, parentLocation)
);
}

/**
* Load data of preselected location.
*
Expand Down Expand Up @@ -405,6 +445,7 @@ FinderComponent.propTypes = {
onItemSelect: PropTypes.func.isRequired,
startingLocationId: PropTypes.number.isRequired,
findLocationsByParentLocationId: PropTypes.func.isRequired,
loadLocation: PropTypes.func.isRequired,
restInfo: PropTypes.shape({
token: PropTypes.string.isRequired,
siteaccess: PropTypes.string.isRequired,
Expand Down
4 changes: 4 additions & 0 deletions src/modules/universal-discovery/universal.discovery.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ContentMetaPreviewComponent from './components/content-meta-preview/conte
import {
loadContentInfo,
loadContentTypes,
loadLocation,
findLocationsByParentLocationId,
findContentBySearchQuery,
checkCreatePermission,
Expand Down Expand Up @@ -866,6 +867,7 @@ export default class UniversalDiscoveryModule extends Component {
const {
startingLocationId,
findLocationsByParentLocationId,
loadLocation,
findContentBySearchQuery,
multiple,
searchResultsPerPage,
Expand All @@ -890,6 +892,7 @@ export default class UniversalDiscoveryModule extends Component {
allowContainersOnly,
startingLocationId,
findLocationsByParentLocationId,
loadLocation,
findContentBySearchQuery,
contentTypesMap,
multiple,
Expand Down Expand Up @@ -1166,6 +1169,7 @@ UniversalDiscoveryModule.defaultProps = {
loadContentTypes,
findContentBySearchQuery,
findLocationsByParentLocationId,
loadLocation,
canSelectContent: (item, callback) => callback(true),
extraTabs: window.eZ.adminUiConfig.universalDiscoveryWidget.extraTabs || [],
startingLocationId: 1,
Expand Down