@ministryofjustice/hmpps-digital-prison-reporting-frontend 1.2.0 → 1.3.0

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 +1 @@
1
- $(".autocomplete-text-input-box").each((t,i)=>{$(i).on("keyup",t=>{var a=$(i).attr("aria-owns");const e=Number($(i).data("minimum-length")),o=t.target.value.toLowerCase();$(`#${a} li`).each((t,a)=>{o.length>=e&&$(a).text().trim().toLowerCase().startsWith(o)?$(a).css("display",""):$(a).css("display","none")})})}),$(".autocomplete-text-input-list-button").each((t,e)=>{$(e).on("click",()=>{var t="#"+$(e).data("parent-input").replaceAll(".","\\."),t=$(t),a=t.attr("aria-owns");t.val($(e).text().trim()),t.trigger("focus"),$(`#${a} li`).each((t,a)=>{$(a).css("display","none")})})}),$("[data-click-navigate-to]").each((t,a)=>{const e=$(a);e.on("click",()=>{window.location.href=e.attr("data-click-navigate-to")})}),$("[data-navigate-to]").each((t,a)=>{const e=$(a);e.on("change",()=>(window.location.href=e.attr("data-navigate-to").replace(/thisValue/,e.val()),!1))}),$(function(){$("[data-apply-form-to-querystring=true]").on("click",function(){var t=$(this).data("apply-form-selector");let a=$(this).data("apply-base-url");-1===a.indexOf("?")?a+="?":a+="&",a=(a+=$(t).serialize()).replaceAll("?&","?").replaceAll("&&","&"),window.location.href=a})}),$(function(){$("#filter-bar").each(function(t,a){new MOJFrontend.FilterToggleButton({startHidden:!0,toggleButton:{container:$(a),showText:"Show filter",hideText:"Hide filter",classes:"govuk-button--primary filter-summary-show-filter-button"},filter:{container:$(".moj-filter")}})})});
1
+ $(".autocomplete-text-input-box").each((t,s)=>{$(s).on("keyup",t=>{var e=$(s).attr("aria-owns");const a=Number($(s).data("minimum-length"));var n=$(s).data("resource-endpoint");const o=t.target.value.toLowerCase(),i=`#${e} li`,r=`#${e} ul`;function l(){var t=$(i).first().clone(!0,!0);return $(i).remove(),$(r).append(t),t}function c(t,e,a){t=t.clone(e,!0);t.children("button").html(a),t.css("display",""),$(r).append(t)}n?o.length>=a?(c(l(),!1,"<i>Searching...</i>"),$.get(n.replace("{prefix}",encodeURI(o))).done(t=>{const e=l();t.forEach(t=>{c(e,!0,t)})}).fail((t,e,a)=>{c(l(),!1,"Failed to retrieve results: "+a)})):l():$(i).each((t,e)=>{o.length>=a&&$(e).text().trim().toLowerCase().startsWith(o)?$(e).css("display",""):$(e).css("display","none")})})}),$(".autocomplete-text-input-list-button").each((t,e)=>{$(e).on("click",t=>{var e="#"+$(t.target).data("parent-input").replaceAll(".","\\."),e=$(e),a=e.attr("aria-owns");e.val($(t.target).text().trim()),e.trigger("focus"),$(`#${a} li`).each((t,e)=>{$(e).css("display","none")})})}),$("[data-click-navigate-to]").each((t,e)=>{const a=$(e);a.on("click",()=>{window.location.href=a.attr("data-click-navigate-to")})}),$("[data-navigate-to]").each((t,e)=>{const a=$(e);a.on("change",()=>(window.location.href=a.attr("data-navigate-to").replace(/thisValue/,a.val()),!1))}),$(function(){$("[data-apply-form-to-querystring=true]").on("click",function(){var t=$(this).data("apply-form-selector");let e=$(this).data("apply-base-url");-1===e.indexOf("?")?e+="?":e+="&",e=(e+=$(t).serialize()).replaceAll("?&","?").replaceAll("&&","&"),window.location.href=e})}),$(function(){$("#filter-bar").each(function(t,e){new MOJFrontend.FilterToggleButton({startHidden:!0,toggleButton:{container:$(e),showText:"Show filter",hideText:"Hide filter",classes:"govuk-button--primary filter-summary-show-filter-button"},filter:{container:$(".moj-filter")}})})});
@@ -19,7 +19,8 @@
19
19
  "aria-owns": listId,
20
20
  "haspopup": "true",
21
21
  "placeholder": "Search",
22
- "data-minimum-length": options.dynamicOptions.minimumLength if options.dynamicOptions
22
+ "data-minimum-length": options.minimumLength,
23
+ "data-resource-endpoint": options.dynamicResourceEndpoint
23
24
  },
24
25
  autocomplete: "off",
25
26
  suffix: {
@@ -29,17 +30,29 @@
29
30
  }) }}
30
31
  <div id="{{ listId }}" class="autocomplete-text-input-list">
31
32
  <ul role="listbox">
32
- {% for item in options.items %}
33
+ {% if (options.dynamicResourceEndpoint) %}
33
34
  <li style='display: none'>
34
35
  {{ govukButton({
35
- text: item.text,
36
+ text: '~Template~',
36
37
  classes: "govuk-button--inverse autocomplete-text-input-list-button",
37
38
  attributes: {
38
39
  "data-parent-input": options.id
39
40
  }
40
41
  }) }}
41
42
  </li>
42
- {% endfor %}
43
+ {% else %}
44
+ {% for item in options.items %}
45
+ <li style='display: none'>
46
+ {{ govukButton({
47
+ text: item.text,
48
+ classes: "govuk-button--inverse autocomplete-text-input-list-button",
49
+ attributes: {
50
+ "data-parent-input": options.id
51
+ }
52
+ }) }}
53
+ </li>
54
+ {% endfor %}
55
+ {% endif %}
43
56
  </ul>
44
57
  </div>
45
58
  </div>
@@ -15,11 +15,8 @@ export interface FilterValue {
15
15
  type: FilterType
16
16
  value?: string | DateRange
17
17
  options?: Array<FilterOption>
18
- dynamicOptions: FilterDynamicOptions
19
- }
20
-
21
- export interface FilterDynamicOptions {
22
- minimumLength: number
18
+ minimumLength?: number
19
+ dynamicResourceEndpoint?: string
23
20
  }
24
21
 
25
22
  export interface SelectedFilter {
@@ -4,7 +4,7 @@ const enum_1 = require("./enum");
4
4
  const LOCALE = 'en-GB';
5
5
  const toLocaleDate = (isoDate) => (isoDate ? new Date(isoDate).toLocaleDateString(LOCALE) : null);
6
6
  exports.default = {
7
- getFilters: (format, filterValues) => format
7
+ getFilters: (variantDefinition, filterValues, dynamicAutocompleteEndpoint = null) => variantDefinition.specification.fields
8
8
  .filter((f) => f.filter)
9
9
  .map((f) => {
10
10
  const filter = {
@@ -15,11 +15,10 @@ exports.default = {
15
15
  ? f.filter.staticOptions.map((o) => ({ value: o.name, text: o.display }))
16
16
  : null,
17
17
  value: filterValues[f.name],
18
- dynamicOptions: f.filter.dynamicOptions
19
- ? {
20
- minimumLength: f.filter.dynamicOptions.minimumLength,
21
- }
22
- : null,
18
+ minimumLength: f.filter.dynamicOptions ? f.filter.dynamicOptions.minimumLength : null,
19
+ dynamicResourceEndpoint: (f.filter.dynamicOptions && f.filter.dynamicOptions.returnAsStaticOptions) || !dynamicAutocompleteEndpoint
20
+ ? null
21
+ : dynamicAutocompleteEndpoint.replace('{fieldName}', f.name),
23
22
  };
24
23
  if (f.filter.type === enum_1.FilterType.dateRange.toLowerCase()) {
25
24
  filter.value = {
@@ -9,8 +9,12 @@ const LOCALE = 'en-GB'
9
9
  const toLocaleDate = (isoDate?: string) => (isoDate ? new Date(isoDate).toLocaleDateString(LOCALE) : null)
10
10
 
11
11
  export default {
12
- getFilters: (format: Array<components['schemas']['FieldDefinition']>, filterValues: Dict<string>) =>
13
- format
12
+ getFilters: (
13
+ variantDefinition: components['schemas']['VariantDefinition'],
14
+ filterValues: Dict<string>,
15
+ dynamicAutocompleteEndpoint: string = null,
16
+ ) =>
17
+ variantDefinition.specification.fields
14
18
  .filter((f) => f.filter)
15
19
  .map((f) => {
16
20
  const filter: FilterValue = {
@@ -21,11 +25,11 @@ export default {
21
25
  ? f.filter.staticOptions.map((o) => ({ value: o.name, text: o.display }))
22
26
  : null,
23
27
  value: filterValues[f.name],
24
- dynamicOptions: f.filter.dynamicOptions
25
- ? {
26
- minimumLength: f.filter.dynamicOptions.minimumLength,
27
- }
28
- : null,
28
+ minimumLength: f.filter.dynamicOptions ? f.filter.dynamicOptions.minimumLength : null,
29
+ dynamicResourceEndpoint:
30
+ (f.filter.dynamicOptions && f.filter.dynamicOptions.returnAsStaticOptions) || !dynamicAutocompleteEndpoint
31
+ ? null
32
+ : dynamicAutocompleteEndpoint.replace('{fieldName}', f.name),
29
33
  }
30
34
 
31
35
  if (f.filter.type === FilterType.dateRange.toLowerCase()) {
@@ -83,7 +83,8 @@
83
83
  items: filter.options,
84
84
  value: filter.value,
85
85
  labelText: filter.text,
86
- dynamicOptions: filter.dynamicOptions
86
+ minimumLength: filter.minimumLength,
87
+ dynamicResourceEndpoint: filter.dynamicResourceEndpoint
87
88
  }) }}
88
89
  {% endif %}
89
90
  {%- endfor %}
@@ -1,7 +1,8 @@
1
1
  import { NextFunction, Request, Response } from 'express'
2
2
  import Dict = NodeJS.Dict
3
3
  import ReportQuery from '../../types/ReportQuery'
4
- import ReportingClient, { ListWithWarnings } from './data/reportingClient'
4
+ import ReportingClient from '../../data/reportingClient'
5
+ import { ListWithWarnings } from '../../data/types'
5
6
  import defaultTokenProvider from './defaultTokenProvider'
6
7
  import { components } from '../../types/api'
7
8
 
@@ -12,13 +13,14 @@ export interface ListDataSources {
12
13
 
13
14
  export interface RenderListWithDataInput {
14
15
  title: string
15
- fields: components['schemas']['FieldDefinition'][]
16
+ variantDefinition: components['schemas']['VariantDefinition']
16
17
  request: Request
17
18
  response: Response
18
19
  next: NextFunction
19
20
  getListDataSources: (reportQuery: ReportQuery) => ListDataSources
20
21
  otherOptions?: Dict<object>
21
22
  layoutTemplate: string
23
+ dynamicAutocompleteEndpoint?: string
22
24
  }
23
25
 
24
26
  export interface RenderListWithDefinitionInput {
@@ -32,6 +34,7 @@ export interface RenderListWithDefinitionInput {
32
34
  layoutTemplate: string
33
35
  token: string
34
36
  reportingClient: ReportingClient
37
+ dynamicAutocompleteEndpoint?: string
35
38
  }
36
39
 
37
40
  export class CreateRequestHandlerInput {
@@ -51,6 +54,8 @@ export class CreateRequestHandlerInput {
51
54
 
52
55
  tokenProvider: (request: Request, response: Response, next: NextFunction) => string
53
56
 
57
+ dynamicAutocompleteEndpoint?: string
58
+
54
59
  constructor(
55
60
  title?: string,
56
61
  definitionName: string,
@@ -58,6 +63,7 @@ export class CreateRequestHandlerInput {
58
63
  apiUrl: string,
59
64
  otherOptions?: Dict<object>,
60
65
  layoutTemplate: string,
66
+ dynamicAutocompleteEndpoint?: string,
61
67
  apiTimeout = 8000,
62
68
  tokenProvider: (request: Request, response: Response, next: NextFunction) => string = defaultTokenProvider,
63
69
  ) {
@@ -69,5 +75,6 @@ export class CreateRequestHandlerInput {
69
75
  this.otherOptions = otherOptions
70
76
  this.layoutTemplate = layoutTemplate
71
77
  this.tokenProvider = tokenProvider
78
+ this.dynamicAutocompleteEndpoint = dynamicAutocompleteEndpoint
72
79
  }
73
80
  }
@@ -7,7 +7,7 @@ const ReportQuery_1 = __importDefault(require("../../types/ReportQuery"));
7
7
  const urlHelper_1 = __importDefault(require("../../utils/urlHelper"));
8
8
  const utils_1 = __importDefault(require("../data-table/utils"));
9
9
  const utils_2 = __importDefault(require("../filters/utils"));
10
- const reportingClient_1 = __importDefault(require("./data/reportingClient"));
10
+ const reportingClient_1 = __importDefault(require("../../data/reportingClient"));
11
11
  const filtersQueryParameterPrefix = 'filters.';
12
12
  function getDefaultSortColumn(fields) {
13
13
  var _a;
@@ -17,11 +17,12 @@ function getDefaultSortColumn(fields) {
17
17
  function isListWithWarnings(data) {
18
18
  return data.data !== undefined;
19
19
  }
20
- function renderList(listData, fields, reportQuery, request, response, next, title, layoutTemplate, otherOptions) {
20
+ function renderList(listData, variantDefinition, reportQuery, request, response, next, title, layoutTemplate, dynamicAutocompleteEndpoint, otherOptions) {
21
21
  Promise.all([listData.data, listData.count])
22
22
  .then((resolvedData) => {
23
23
  let data;
24
24
  let warnings = {};
25
+ const { fields } = variantDefinition.specification;
25
26
  if (isListWithWarnings(resolvedData[0])) {
26
27
  // eslint-disable-next-line prefer-destructuring
27
28
  data = resolvedData[0].data;
@@ -38,7 +39,7 @@ function renderList(listData, fields, reportQuery, request, response, next, titl
38
39
  currentQueryParams: reportQuery.toRecordWithFilterPrefix(),
39
40
  };
40
41
  const filterOptions = {
41
- filters: utils_2.default.getFilters(fields, reportQuery.filters),
42
+ filters: utils_2.default.getFilters(variantDefinition, reportQuery.filters, dynamicAutocompleteEndpoint),
42
43
  selectedFilters: utils_2.default.getSelectedFilters(fields, reportQuery, urlHelper_1.default),
43
44
  };
44
45
  response.render('dpr/components/report-list/list', {
@@ -52,7 +53,7 @@ function renderList(listData, fields, reportQuery, request, response, next, titl
52
53
  })
53
54
  .catch((err) => next(err));
54
55
  }
55
- const renderListWithDefinition = ({ title, definitionName, variantName, request, response, next, otherOptions, layoutTemplate, token, reportingClient, }) => {
56
+ const renderListWithDefinition = ({ title, definitionName, variantName, request, response, next, otherOptions, layoutTemplate, token, reportingClient, dynamicAutocompleteEndpoint, }) => {
56
57
  reportingClient.getDefinition(token, definitionName, variantName).then((reportDefinition) => {
57
58
  const reportName = reportDefinition.name;
58
59
  const variantDefinition = reportDefinition.variant;
@@ -61,17 +62,18 @@ const renderListWithDefinition = ({ title, definitionName, variantName, request,
61
62
  data: reportingClient.getListWithWarnings(variantDefinition.resourceName, token, reportQuery),
62
63
  count: reportingClient.getCount(variantDefinition.resourceName, token, reportQuery),
63
64
  };
64
- renderList(getListData, variantDefinition.specification.fields, reportQuery, request, response, next, title !== null && title !== void 0 ? title : `${reportName} - ${variantDefinition.name}`, layoutTemplate, otherOptions);
65
+ renderList(getListData, variantDefinition, reportQuery, request, response, next, title !== null && title !== void 0 ? title : `${reportName} - ${variantDefinition.name}`, layoutTemplate, dynamicAutocompleteEndpoint, otherOptions);
65
66
  });
66
67
  };
67
68
  exports.default = {
68
69
  filtersQueryParameterPrefix,
69
- renderListWithData: ({ title, fields, request, response, next, getListDataSources, otherOptions, layoutTemplate, }) => {
70
+ renderListWithData: ({ title, variantDefinition, request, response, next, getListDataSources, otherOptions, layoutTemplate, dynamicAutocompleteEndpoint, }) => {
71
+ const { fields } = variantDefinition.specification;
70
72
  const reportQuery = new ReportQuery_1.default(fields, request.query, getDefaultSortColumn(fields), filtersQueryParameterPrefix);
71
73
  const listData = getListDataSources(reportQuery);
72
- renderList(listData, fields, reportQuery, request, response, next, title, layoutTemplate, otherOptions);
74
+ renderList(listData, variantDefinition, reportQuery, request, response, next, title, layoutTemplate, dynamicAutocompleteEndpoint, otherOptions);
73
75
  },
74
- createReportListRequestHandler: ({ title, definitionName, variantName, apiUrl, apiTimeout, otherOptions, layoutTemplate, tokenProvider, }) => {
76
+ createReportListRequestHandler: ({ title, definitionName, variantName, apiUrl, apiTimeout, otherOptions, layoutTemplate, tokenProvider, dynamicAutocompleteEndpoint, }) => {
75
77
  const reportingClient = new reportingClient_1.default({
76
78
  url: apiUrl,
77
79
  agent: {
@@ -90,6 +92,7 @@ exports.default = {
90
92
  layoutTemplate,
91
93
  token: tokenProvider(request, response, next),
92
94
  reportingClient,
95
+ dynamicAutocompleteEndpoint,
93
96
  });
94
97
  };
95
98
  },
@@ -10,7 +10,8 @@ import {
10
10
  RenderListWithDataInput,
11
11
  RenderListWithDefinitionInput,
12
12
  } from './types'
13
- import ReportingClient, { ListWithWarnings, Warnings } from './data/reportingClient'
13
+ import ReportingClient from '../../data/reportingClient'
14
+ import { ListWithWarnings, Warnings } from '../../data/types'
14
15
  import { components } from '../../types/api'
15
16
  import Dict = NodeJS.Dict
16
17
 
@@ -27,19 +28,21 @@ function isListWithWarnings(data: Dict<string>[] | ListWithWarnings): data is Li
27
28
 
28
29
  function renderList(
29
30
  listData: ListDataSources,
30
- fields: components['schemas']['FieldDefinition'][],
31
+ variantDefinition: components['schemas']['VariantDefinition'],
31
32
  reportQuery: ReportQuery,
32
33
  request: Request,
33
34
  response: Response,
34
35
  next: NextFunction,
35
36
  title: string,
36
37
  layoutTemplate: string,
37
- otherOptions: NodeJS.Dict<object>,
38
+ dynamicAutocompleteEndpoint?: string,
39
+ otherOptions?: NodeJS.Dict<object>,
38
40
  ) {
39
41
  Promise.all([listData.data, listData.count])
40
42
  .then((resolvedData) => {
41
43
  let data
42
44
  let warnings: Warnings = {}
45
+ const { fields } = variantDefinition.specification
43
46
 
44
47
  if (isListWithWarnings(resolvedData[0])) {
45
48
  // eslint-disable-next-line prefer-destructuring
@@ -58,7 +61,7 @@ function renderList(
58
61
  }
59
62
 
60
63
  const filterOptions = {
61
- filters: FilterUtils.getFilters(fields, reportQuery.filters),
64
+ filters: FilterUtils.getFilters(variantDefinition, reportQuery.filters, dynamicAutocompleteEndpoint),
62
65
  selectedFilters: FilterUtils.getSelectedFilters(fields, reportQuery, createUrlForParameters),
63
66
  }
64
67
 
@@ -85,6 +88,7 @@ const renderListWithDefinition = ({
85
88
  layoutTemplate,
86
89
  token,
87
90
  reportingClient,
91
+ dynamicAutocompleteEndpoint,
88
92
  }: RenderListWithDefinitionInput) => {
89
93
  reportingClient.getDefinition(token, definitionName, variantName).then((reportDefinition) => {
90
94
  const reportName: string = reportDefinition.name
@@ -103,13 +107,14 @@ const renderListWithDefinition = ({
103
107
  }
104
108
  renderList(
105
109
  getListData,
106
- variantDefinition.specification.fields,
110
+ variantDefinition,
107
111
  reportQuery,
108
112
  request,
109
113
  response,
110
114
  next,
111
115
  title ?? `${reportName} - ${variantDefinition.name}`,
112
116
  layoutTemplate,
117
+ dynamicAutocompleteEndpoint,
113
118
  otherOptions,
114
119
  )
115
120
  })
@@ -120,14 +125,16 @@ export default {
120
125
 
121
126
  renderListWithData: ({
122
127
  title,
123
- fields,
128
+ variantDefinition,
124
129
  request,
125
130
  response,
126
131
  next,
127
132
  getListDataSources,
128
133
  otherOptions,
129
134
  layoutTemplate,
135
+ dynamicAutocompleteEndpoint,
130
136
  }: RenderListWithDataInput) => {
137
+ const { fields } = variantDefinition.specification
131
138
  const reportQuery = new ReportQuery(
132
139
  fields,
133
140
  request.query,
@@ -136,7 +143,18 @@ export default {
136
143
  )
137
144
  const listData = getListDataSources(reportQuery)
138
145
 
139
- renderList(listData, fields, reportQuery, request, response, next, title, layoutTemplate, otherOptions)
146
+ renderList(
147
+ listData,
148
+ variantDefinition,
149
+ reportQuery,
150
+ request,
151
+ response,
152
+ next,
153
+ title,
154
+ layoutTemplate,
155
+ dynamicAutocompleteEndpoint,
156
+ otherOptions,
157
+ )
140
158
  },
141
159
 
142
160
  createReportListRequestHandler: ({
@@ -148,6 +166,7 @@ export default {
148
166
  otherOptions,
149
167
  layoutTemplate,
150
168
  tokenProvider,
169
+ dynamicAutocompleteEndpoint,
151
170
  }: CreateRequestHandlerInput): RequestHandler => {
152
171
  const reportingClient = new ReportingClient({
153
172
  url: apiUrl,
@@ -168,6 +187,7 @@ export default {
168
187
  layoutTemplate,
169
188
  token: tokenProvider(request, response, next),
170
189
  reportingClient,
190
+ dynamicAutocompleteEndpoint,
171
191
  })
172
192
  }
173
193
  },
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const logger_1 = __importDefault(require("../../../utils/logger"));
6
+ const logger_1 = __importDefault(require("../utils/logger"));
7
7
  const restClient_1 = __importDefault(require("./restClient"));
8
8
  class ReportingClient {
9
9
  constructor(config) {
@@ -61,5 +61,16 @@ class ReportingClient {
61
61
  })
62
62
  .then((response) => response);
63
63
  }
64
+ getFieldValues({ token, definitionName, variantName, fieldName, prefix, }) {
65
+ return this.restClient
66
+ .get({
67
+ path: `/reports/${definitionName}/${variantName}/${fieldName}`,
68
+ token,
69
+ query: {
70
+ prefix,
71
+ },
72
+ })
73
+ .then((response) => response);
74
+ }
64
75
  }
65
76
  exports.default = ReportingClient;
@@ -1,24 +1,11 @@
1
- import ReportQuery from '../../../types/ReportQuery'
2
- import logger from '../../../utils/logger'
1
+ import ReportQuery from '../types/ReportQuery'
2
+ import logger from '../utils/logger'
3
3
  import RestClient from './restClient'
4
4
  import Dict = NodeJS.Dict
5
- import { components, operations } from '../../../types/api'
6
- import { ApiConfig } from './types'
5
+ import { components, operations } from '../types/api'
6
+ import { ApiConfig, Count, FieldValuesRequest, ListWithWarnings } from './types'
7
7
  import type { ResultWithHeaders } from './restClient'
8
8
 
9
- export interface Count {
10
- count: number
11
- }
12
-
13
- export interface ListWithWarnings {
14
- data: Array<Dict<string>>
15
- warnings: Warnings
16
- }
17
-
18
- export interface Warnings {
19
- noDataAvailable?: string
20
- }
21
-
22
9
  export default class ReportingClient {
23
10
  restClient: RestClient
24
11
 
@@ -91,4 +78,22 @@ export default class ReportingClient {
91
78
  })
92
79
  .then((response) => <components['schemas']['SingleVariantReportDefinition']>response)
93
80
  }
81
+
82
+ getFieldValues({
83
+ token,
84
+ definitionName,
85
+ variantName,
86
+ fieldName,
87
+ prefix,
88
+ }: FieldValuesRequest): Promise<Array<string>> {
89
+ return this.restClient
90
+ .get({
91
+ path: `/reports/${definitionName}/${variantName}/${fieldName}`,
92
+ token,
93
+ query: {
94
+ prefix,
95
+ },
96
+ })
97
+ .then((response) => <Array<string>>response)
98
+ }
94
99
  }
@@ -28,8 +28,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const superagent_1 = __importDefault(require("superagent"));
30
30
  const agentkeepalive_1 = __importStar(require("agentkeepalive"));
31
- const logger_1 = __importDefault(require("../../../utils/logger"));
32
- const sanitisedError_1 = __importDefault(require("../../../utils/sanitisedError"));
31
+ const logger_1 = __importDefault(require("../utils/logger"));
32
+ const sanitisedError_1 = __importDefault(require("../utils/sanitisedError"));
33
33
  class RestClient {
34
34
  constructor(name, config) {
35
35
  this.name = name;
@@ -1,8 +1,8 @@
1
1
  import superagent from 'superagent'
2
2
  import Agent, { HttpsAgent } from 'agentkeepalive'
3
3
 
4
- import logger from '../../../utils/logger'
5
- import sanitiseError from '../../../utils/sanitisedError'
4
+ import logger from '../utils/logger'
5
+ import sanitiseError from '../utils/sanitisedError'
6
6
  import { ApiConfig, GetRequest } from './types'
7
7
  import Dict = NodeJS.Dict
8
8
 
@@ -0,0 +1,36 @@
1
+ import AgentConfig from './agentConfig'
2
+
3
+ export interface GetRequest {
4
+ path?: string
5
+ query?: object
6
+ headers?: Record<string, string>
7
+ responseType?: string
8
+ raw?: boolean
9
+ token: string
10
+ }
11
+
12
+ export interface ApiConfig {
13
+ url: string
14
+ agent: AgentConfig
15
+ }
16
+
17
+ export interface Count {
18
+ count: number
19
+ }
20
+
21
+ export interface ListWithWarnings {
22
+ data: Array<Dict<string>>
23
+ warnings: Warnings
24
+ }
25
+
26
+ export interface Warnings {
27
+ noDataAvailable?: string
28
+ }
29
+
30
+ export interface FieldValuesRequest {
31
+ token: string
32
+ definitionName: string
33
+ variantName: string
34
+ fieldName: string
35
+ prefix: string
36
+ }
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": "1.2.0",
4
+ "version": "1.3.0",
5
5
  "main": "dpr/assets/js/client.js",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {
package/package.zip CHANGED
Binary file
@@ -1,15 +0,0 @@
1
- import AgentConfig from './agentConfig'
2
-
3
- export interface GetRequest {
4
- path?: string
5
- query?: object
6
- headers?: Record<string, string>
7
- responseType?: string
8
- raw?: boolean
9
- token: string
10
- }
11
-
12
- export interface ApiConfig {
13
- url: string
14
- agent: AgentConfig
15
- }