Skip to content

Commit

Permalink
EZP-30904: UDW: Sorting settings are ignored for starting location (#209
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SerheyDolgushev authored and lserwatka committed Sep 2, 2019
1 parent 270130c commit 16089c3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
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

0 comments on commit 16089c3

Please sign in to comment.