Skip to content

Commit

Permalink
Merge branch '4.6' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 10, 2024
2 parents 52b6aff + 08cac67 commit edfa824
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/bundle/ui-dev/src/modules/sub-items/sub.items.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default class SubItemsModule extends Component {
this.hideMorePanel = this.hideMorePanel.bind(this);
this.renderExtraActions = this.renderExtraActions.bind(this);
this.renderActionBtnWrapper = this.renderActionBtnWrapper.bind(this);
this.requestParamsHaveChanged = this.requestParamsHaveChanged.bind(this);

this._refListViewWrapper = React.createRef();
this._refMainContainerWrapper = React.createRef();
Expand Down Expand Up @@ -132,6 +133,7 @@ export default class SubItemsModule extends Component {
columnsVisibility: this.getColumnsVisibilityFromLocalStorage(),
morePanelVisible: false,
morePanelVisibleItemsIndexes: [],
queryParams: {},
};
}

Expand Down Expand Up @@ -184,13 +186,23 @@ export default class SubItemsModule extends Component {

const shouldLoadPage = !activePageItems;

if (shouldLoadPage) {
if (shouldLoadPage && this.requestParamsHaveChanged(activePageIndex)) {
this.loadPage(activePageIndex);
}

ibexa.helpers.tooltips.parse();
}

requestParamsHaveChanged(activePageIndex) {
const { queryParams } = this.state;

return (
queryParams.cursor !== this.calculateCursor(activePageIndex) ||
queryParams.sortClause !== this.state.sortClause ||
queryParams.sortOrder !== this.state.sortOrder
);
}

componentWillUnmount() {
document.body.removeChild(this.bulkActionModalContainer);
}
Expand Down Expand Up @@ -240,10 +252,17 @@ export default class SubItemsModule extends Component {
loadPage(pageIndex) {
const { limit: itemsPerPage, parentLocationId: locationId, loadLocation, restInfo } = this.props;
const { sortClause, sortOrder } = this.state;
const page = this.state.pages.find(({ number }) => number === pageIndex + 1);
const cursor = page ? page.cursor : null;
const cursor = this.calculateCursor(pageIndex);
const queryConfig = { locationId, limit: itemsPerPage, sortClause, sortOrder, cursor };

this.setState({
queryParams: {
sortClause,
sortOrder,
cursor,
},
});

loadLocation(restInfo, queryConfig, (response) => {
const { totalCount, pages, edges } = response.data._repository.location.children;
const activePageItems = edges.map((edge) => edge.node);
Expand All @@ -256,6 +275,12 @@ export default class SubItemsModule extends Component {
});
}

calculateCursor(pageIndex) {
const page = this.state.pages.find(({ number }) => number === pageIndex + 1);

return page ? page.cursor : null;
}

updateTotalCountState(totalCount) {
this.setState(() => ({
totalCount,
Expand Down

0 comments on commit edfa824

Please sign in to comment.