Skip to content

Commit

Permalink
Add a dropdown for selecting the page size on the workbench
Browse files Browse the repository at this point in the history
  • Loading branch information
mensinda committed Feb 29, 2024
1 parent a8edcfe commit 31dfb92
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions webapp/src/main/resources/properties/de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ search.result.empty=Es gibt keine Ergebnisse. Aktualisieren Sie Ihre Parametersu
# Message displayed when the user has not selected repository and locales
search.result.selectRepoAndLocale=Wählen Sie mindestens ein Speicher und Locale aus bevor Sie suchen können.

search.unitsPerPage=Texte pro Seite: {pageSize}

# Label used in the header loggedInUser dropdown to show user's profile
header.loggedInUser.profile=Mein Profil

Expand Down
2 changes: 2 additions & 0 deletions webapp/src/main/resources/properties/en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ search.result.empty=There are no results. Update your search parameter to find w
# Message displayed when the user has not selected repository and locales
search.result.selectRepoAndLocale=Select at least one repository and locale before you can search.

search.unitsPerPage=Texts per page: {pageSize}

# Label used in the header loggedInUser dropdown to show user's profile
header.loggedInUser.profile=My Profile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ let SearchResults = createReactClass({
/** @type {Number} Indicates the current page number of the search results. */
"currentPageNumber": searchParamsStoreState.currentPageNumber,

/** @type {Number} The number of items on each page. */
"pageSize": searchParamsStoreState.pageSize,

/** @type {Number} The index of the currently active textunit. */
"activeTextUnitIndex": 0,

Expand Down Expand Up @@ -348,6 +351,7 @@ let SearchResults = createReactClass({
"searchHadNoResults": resultsStoreState.searchHadNoResults,
"noMoreResults": resultsStoreState.noMoreResults,
"currentPageNumber": paramsStoreState.currentPageNumber,
"pageSize": paramsStoreState.pageSize,
"mustShowToolbar": mustShowToolbar,
"activeTextUnitIndex": this.getActiveTextUnitIndex(),
"isErrorOccurred": resultsStoreState.isErrorOccurred,
Expand Down Expand Up @@ -557,6 +561,22 @@ let SearchResults = createReactClass({
let nextPageButtonDisabled = isSearching || noMoreResults;
let previousPageButtonDisabled = isSearching || isFirstPage;

let pageSizes = [];
for (let i of [10, 25, 50, 100]) {
pageSizes.push(
<MenuItem
key={i}
eventKey={i}
active={i == this.state.pageSize}
onSelect={(s, _) => WorkbenchActions.searchParamsChanged({changedParam: SearchConstants.PAGE_SIZE_CHANGED, pageSize: s})}
>
{i}
</MenuItem>
);
}

const title = <FormattedMessage values={{"pageSize": this.state.pageSize}} id="search.unitsPerPage" />;

if (this.state.mustShowToolbar) {
ui = (
<div>
Expand Down Expand Up @@ -586,6 +606,10 @@ let SearchResults = createReactClass({
</div>
<div className="pull-right">
<TextUnitSelectorCheckBox numberOfSelectedTextUnits={numberOfSelectedTextUnits}/>

<DropdownButton id="text-units-per-page" title={title} className="mrm">
{pageSizes}
</DropdownButton>
<Button bsSize="small" disabled={previousPageButtonDisabled}
onClick={this.onFetchPreviousPageClicked}><span
className="glyphicon glyphicon-chevron-left"></span></Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ class SearchParamsStore {
this.decrementPageNumber();
break;

case SearchConstants.PAGE_SIZE_CHANGED:

this.changePageSize(paramData.pageSize);
break;

default:
console.error("SearchParamsStore::Unknown param type");
break;
Expand Down Expand Up @@ -367,6 +372,11 @@ class SearchParamsStore {
this.setCurrentPageNumber(this.currentPageNumber + 1);
}

changePageSize(pageSize) {
this.pageSize = pageSize;
this.setCurrentPageNumber(1);
}

setCurrentPageNumber(pageNumber) {
if (pageNumber >= 1) {
this.currentPageNumber = pageNumber;
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/main/resources/public/js/utils/SearchConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ let SearchConstants = keymirror({
"UPDATE_ALL_LOCATION_UPDATE": null,
"UPDATE_ALL_LOCATION_NONE": null,
"NEXT_PAGE_REQUESTED" : null,
"PREVIOUS_PAGE_REQUESTED" : null
"PREVIOUS_PAGE_REQUESTED" : null,
"PAGE_SIZE_CHANGED": null,
});

export default SearchConstants;

0 comments on commit 31dfb92

Please sign in to comment.