@ministryofjustice/hmpps-digital-prison-reporting-frontend 3.17.2 → 3.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const SELECTED_PAGE_PARAM = 'selectedPage';
|
|
4
|
+
const PAGE_SIZE_PARAM = 'pageSize';
|
|
4
5
|
const DEFAULT_PAGE = 1;
|
|
5
6
|
const DEFAULT_PAGE_SIZE = 20;
|
|
6
7
|
/**
|
|
@@ -13,8 +14,7 @@ const DEFAULT_PAGE_SIZE = 20;
|
|
|
13
14
|
* @param currentPage
|
|
14
15
|
* @return {*} {{ pages: page[]; pagesLength: number }}
|
|
15
16
|
*/
|
|
16
|
-
const createPages = (pathname,
|
|
17
|
-
const queryParams = new URLSearchParams(search);
|
|
17
|
+
const createPages = (pathname, queryParams, totalRows, pageSize, currentPage) => {
|
|
18
18
|
const pagesLength = Math.ceil(totalRows / pageSize);
|
|
19
19
|
const pages = [];
|
|
20
20
|
Array(pagesLength)
|
|
@@ -100,9 +100,12 @@ const setPageSizes = (totalRows) => {
|
|
|
100
100
|
* @return {*}
|
|
101
101
|
*/
|
|
102
102
|
exports.default = {
|
|
103
|
-
getPaginationData: (url, totalRows
|
|
103
|
+
getPaginationData: (url, totalRows) => {
|
|
104
104
|
const { pathname, search } = url;
|
|
105
|
-
const
|
|
105
|
+
const queryParams = new URLSearchParams(search);
|
|
106
|
+
const pageSize = +queryParams.get(PAGE_SIZE_PARAM) || DEFAULT_PAGE_SIZE;
|
|
107
|
+
const currentPage = +queryParams.get(SELECTED_PAGE_PARAM) || DEFAULT_PAGE;
|
|
108
|
+
const { pages, pagesLength } = createPages(pathname, queryParams, totalRows, pageSize, currentPage);
|
|
106
109
|
return {
|
|
107
110
|
next: createNext(pathname, search, pagesLength, totalRows, currentPage),
|
|
108
111
|
prev: createPrev(pathname, search, currentPage),
|
|
@@ -2,6 +2,7 @@ import { Url } from 'url'
|
|
|
2
2
|
import { Page, PageSize, Pagination } from './types'
|
|
3
3
|
|
|
4
4
|
const SELECTED_PAGE_PARAM = 'selectedPage'
|
|
5
|
+
const PAGE_SIZE_PARAM = 'pageSize'
|
|
5
6
|
const DEFAULT_PAGE = 1
|
|
6
7
|
const DEFAULT_PAGE_SIZE = 20
|
|
7
8
|
|
|
@@ -17,12 +18,11 @@ const DEFAULT_PAGE_SIZE = 20
|
|
|
17
18
|
*/
|
|
18
19
|
const createPages = (
|
|
19
20
|
pathname: string,
|
|
20
|
-
|
|
21
|
+
queryParams: URLSearchParams,
|
|
21
22
|
totalRows: number,
|
|
22
23
|
pageSize: number,
|
|
23
24
|
currentPage: number,
|
|
24
25
|
): { pages: Page[]; pagesLength: number } => {
|
|
25
|
-
const queryParams = new URLSearchParams(search)
|
|
26
26
|
const pagesLength = Math.ceil(totalRows / pageSize)
|
|
27
27
|
|
|
28
28
|
const pages: Page[] = []
|
|
@@ -126,14 +126,13 @@ const setPageSizes = (totalRows: number): PageSize[] => {
|
|
|
126
126
|
* @return {*}
|
|
127
127
|
*/
|
|
128
128
|
export default {
|
|
129
|
-
getPaginationData: (
|
|
130
|
-
url: Url,
|
|
131
|
-
totalRows: number,
|
|
132
|
-
pageSize: number = DEFAULT_PAGE_SIZE,
|
|
133
|
-
currentPage: number = DEFAULT_PAGE,
|
|
134
|
-
): Pagination => {
|
|
129
|
+
getPaginationData: (url: Url, totalRows: number): Pagination => {
|
|
135
130
|
const { pathname, search } = url
|
|
136
|
-
const
|
|
131
|
+
const queryParams = new URLSearchParams(search)
|
|
132
|
+
const pageSize = +queryParams.get(PAGE_SIZE_PARAM) || DEFAULT_PAGE_SIZE
|
|
133
|
+
const currentPage = +queryParams.get(SELECTED_PAGE_PARAM) || DEFAULT_PAGE
|
|
134
|
+
|
|
135
|
+
const { pages, pagesLength } = createPages(pathname, queryParams, totalRows, pageSize, currentPage)
|
|
137
136
|
return {
|
|
138
137
|
next: createNext(pathname, search, pagesLength, totalRows, currentPage),
|
|
139
138
|
prev: createPrev(pathname, search, currentPage),
|
|
@@ -93,7 +93,7 @@ function renderList(listData, variantDefinition, reportQuery, request, response,
|
|
|
93
93
|
...dataTable,
|
|
94
94
|
classification,
|
|
95
95
|
printable,
|
|
96
|
-
pagination: utils_4.default.getPaginationData(url, count
|
|
96
|
+
pagination: utils_4.default.getPaginationData(url, count),
|
|
97
97
|
};
|
|
98
98
|
const filterOptions = utils_1.default.getFilterOptions(variantDefinition, reportQuery.filters, reportQuery, urlHelper_1.default, dynamicAutocompleteEndpoint);
|
|
99
99
|
const actions = utils_3.default.initReportActions(reportName, variantDefinition.name, variantDefinition.printable, `${request.protocol}://${request.get('host')}${request.originalUrl}`);
|
|
@@ -107,7 +107,7 @@ function renderList(
|
|
|
107
107
|
...dataTable,
|
|
108
108
|
classification,
|
|
109
109
|
printable,
|
|
110
|
-
pagination: PaginationUtils.getPaginationData(url, count
|
|
110
|
+
pagination: PaginationUtils.getPaginationData(url, count),
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
const filterOptions: FilterOptions = FilterUtils.getFilterOptions(
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ministryofjustice/hmpps-digital-prison-reporting-frontend",
|
|
3
3
|
"description": "The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.",
|
|
4
|
-
"version": "3.17.
|
|
4
|
+
"version": "3.17.3",
|
|
5
5
|
"main": "dpr/assets/js/all.mjs",
|
|
6
6
|
"sass": "dpr/all.scss",
|
|
7
7
|
"engines": {
|
package/package.zip
CHANGED
|
Binary file
|