@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.2.5 → 4.2.6

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.
@@ -10,13 +10,12 @@ const logger_1 = __importDefault(require("../../../utils/logger"));
10
10
  const definitionUtils_1 = __importDefault(require("../../../utils/definitionUtils"));
11
11
  const reportListsHelper_1 = require("../../../utils/reportListsHelper");
12
12
  const localsHelper_1 = __importDefault(require("../../../utils/localsHelper"));
13
- const formatBookmarks = async (bookmarksData, maxRows) => {
14
- const cards = bookmarksData
13
+ const formatBookmarks = async (bookmarksData) => {
14
+ return bookmarksData
15
15
  .map((report) => {
16
16
  return (0, exports.formatBookmark)(report);
17
17
  })
18
18
  .sort((a, b) => a.text.localeCompare(b.text));
19
- return maxRows ? cards.slice(0, maxRows) : cards;
20
19
  };
21
20
  exports.formatBookmarks = formatBookmarks;
22
21
  const formatBookmark = (bookmarkData) => {
@@ -123,15 +122,18 @@ exports.default = {
123
122
  renderBookmarkList: async ({ services, maxRows, res, req, }) => {
124
123
  const { token, csrfToken, userId, bookmarks } = localsHelper_1.default.getValues(res);
125
124
  const bookmarksData = await mapBookmarkIdsToDefinition(bookmarks, req, res, token, services);
126
- const formatted = await (0, exports.formatBookmarks)(bookmarksData, maxRows);
125
+ let formatted = await (0, exports.formatBookmarks)(bookmarksData);
126
+ const formattedCount = formatted.length;
127
+ if (maxRows)
128
+ formatted = formatted.slice(0, maxRows);
127
129
  const tableData = await formatTable(bookmarksData, services.bookmarkService, csrfToken, userId, maxRows);
128
130
  const head = {
129
131
  ...(formatted.length && { href: './async-reports/bookmarks' }),
130
132
  ...(!formatted.length && { emptyMessage: 'You have 0 bookmarked reports' }),
131
133
  };
132
134
  const total = {
133
- amount: formatted.length,
134
- shown: formatted.length > maxRows ? maxRows : formatted.length,
135
+ amount: formattedCount,
136
+ shown: formattedCount > maxRows ? maxRows : formattedCount,
135
137
  max: maxRows,
136
138
  };
137
139
  const result = {
@@ -9,17 +9,12 @@ import DefinitionUtils from '../../../utils/definitionUtils'
9
9
  import { createListItemProduct, createListActions, setInitialHref } from '../../../utils/reportListsHelper'
10
10
  import LocalsHelper from '../../../utils/localsHelper'
11
11
 
12
- export const formatBookmarks = async (
13
- bookmarksData: BookmarkedReportData[],
14
- maxRows?: number,
15
- ): Promise<FormattedUserReportData[]> => {
16
- const cards = bookmarksData
12
+ export const formatBookmarks = async (bookmarksData: BookmarkedReportData[]): Promise<FormattedUserReportData[]> => {
13
+ return bookmarksData
17
14
  .map((report: BookmarkedReportData) => {
18
15
  return formatBookmark(report)
19
16
  })
20
17
  .sort((a, b) => a.text.localeCompare(b.text))
21
-
22
- return maxRows ? cards.slice(0, maxRows) : cards
23
18
  }
24
19
 
25
20
  export const formatBookmark = (bookmarkData: BookmarkedReportData): FormattedUserReportData => {
@@ -181,7 +176,11 @@ export default {
181
176
  }) => {
182
177
  const { token, csrfToken, userId, bookmarks } = LocalsHelper.getValues(res)
183
178
  const bookmarksData: BookmarkedReportData[] = await mapBookmarkIdsToDefinition(bookmarks, req, res, token, services)
184
- const formatted = await formatBookmarks(bookmarksData, maxRows)
179
+
180
+ let formatted = await formatBookmarks(bookmarksData)
181
+ const formattedCount = formatted.length
182
+
183
+ if (maxRows) formatted = formatted.slice(0, maxRows)
185
184
  const tableData = await formatTable(bookmarksData, services.bookmarkService, csrfToken, userId, maxRows)
186
185
 
187
186
  const head = {
@@ -190,8 +189,8 @@ export default {
190
189
  }
191
190
 
192
191
  const total = {
193
- amount: formatted.length,
194
- shown: formatted.length > maxRows ? maxRows : formatted.length,
192
+ amount: formattedCount,
193
+ shown: formattedCount > maxRows ? maxRows : formattedCount,
195
194
  max: maxRows,
196
195
  }
197
196
 
@@ -15,7 +15,7 @@
15
15
  <div>
16
16
  <div class="dpr-slide__header">
17
17
  {% if not emptyMessage.length and total %}
18
- <p class="govuk-body-s dpr-slide__sub-text">Showing {{ total.shown }} of {{ total.amount }} {% if total.amount > total.max %} <a class="govuk-body-s" href='{{ href }}'>Show all</a>{% endif %}</p>
18
+ <p class="govuk-body-s dpr-slide__sub-text">Showing {{ total.shown }} of {{ total.amount }}{% if total.amount > total.max %}. <a class="govuk-body-s" href='{{ href }}'>Show all</a>{% endif %}</p>
19
19
  {% endif %}
20
20
  </div>
21
21
  {% if emptyMessage.length %}
@@ -23,8 +23,9 @@ function routes({ router, services, layoutPath, prefix, }) {
23
23
  });
24
24
  router.get(`${prefix}/async-reports/bookmarks`, async (req, res) => {
25
25
  res.render(`dpr/views/async-reports`, {
26
- title: 'Requested Reports',
26
+ title: 'Bookmarks',
27
27
  layoutPath,
28
+ catId: 'dpr-bookmarks-list',
28
29
  ...(await utils_1.default.renderBookmarkList({ services, res, req })),
29
30
  });
30
31
  });
@@ -31,8 +31,9 @@ export default function routes({
31
31
 
32
32
  router.get(`${prefix}/async-reports/bookmarks`, async (req, res) => {
33
33
  res.render(`dpr/views/async-reports`, {
34
- title: 'Requested Reports',
34
+ title: 'Bookmarks',
35
35
  layoutPath,
36
+ catId: 'dpr-bookmarks-list',
36
37
  ...(await BookmarklistUtils.renderBookmarkList({ services, res, req })),
37
38
  })
38
39
  })
@@ -30,16 +30,16 @@ function routes({ router, services, layoutPath, prefix, }) {
30
30
  await services.recentlyViewedService.removeReport(req.body.executionId, userId);
31
31
  res.end();
32
32
  };
33
- router.get(`${prefix}/async-reports/recently-viewed`, async (req, res) => {
33
+ router.get(`${prefix}/async-reports/viewed`, async (req, res) => {
34
34
  const { recentlyViewedReports } = localsHelper_1.default.getValues(res);
35
35
  res.render(`dpr/views/async-reports`, {
36
- title: 'Requested Reports',
36
+ title: 'Recently viewed reports',
37
37
  layoutPath,
38
38
  ...(await utils_2.default.renderList({
39
39
  reportsData: recentlyViewedReports,
40
40
  filterFunction: utils_1.default.filterReports,
41
41
  res,
42
- type: 'requested',
42
+ type: 'viewed',
43
43
  })),
44
44
  });
45
45
  });
@@ -38,16 +38,16 @@ export default function routes({
38
38
  res.end()
39
39
  }
40
40
 
41
- router.get(`${prefix}/async-reports/recently-viewed`, async (req, res) => {
41
+ router.get(`${prefix}/async-reports/viewed`, async (req, res) => {
42
42
  const { recentlyViewedReports } = LocalsHelper.getValues(res)
43
43
  res.render(`dpr/views/async-reports`, {
44
- title: 'Requested Reports',
44
+ title: 'Recently viewed reports',
45
45
  layoutPath,
46
46
  ...(await UserReportsListUtils.renderList({
47
47
  reportsData: recentlyViewedReports,
48
48
  filterFunction: RecentReportslistUtils.filterReports,
49
49
  res,
50
- type: 'requested',
50
+ type: 'viewed',
51
51
  })),
52
52
  })
53
53
  })
@@ -1,12 +1,14 @@
1
1
  {% extends layoutPath %}
2
2
 
3
- {% from "..components/_catalogue/catalogue-list/view.njk" import dprCatalogueList %}
3
+ {% from "../components/_catalogue/catalogue-list/view.njk" import dprCatalogueList %}
4
4
 
5
5
  {% set mainClasses = "app-container govuk-body" %}
6
6
 
7
7
  {% block content %}
8
8
  <div class="govuk-width-container">
9
9
  <h1>{{ title }}</h1>
10
- {{ dprCatalogueList(tableData.head, tableData.rows, { unauthorisedToggleEnabled: false }) }}
10
+ <div id="{{ catId }}">
11
+ {{ dprCatalogueList(tableData.head, tableData.rows, { unauthorisedToggleEnabled: false }) }}
12
+ </div>
11
13
  </div>
12
14
  {% endblock %}
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": "4.2.5",
4
+ "version": "4.2.6",
5
5
  "main": "dpr/all.mjs",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {
package/package.zip CHANGED
Binary file