UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

120 lines (116 loc) 3.82 kB
import { ParsedQs } from 'qs'; import { FilteredListRequest } from './index.d.js'; import { components } from './api.d.js'; import { Template } from './Templates.d.js'; import { ReportType } from './UserReports.js'; import Dict = NodeJS.Dict; declare class ReportQuery implements FilteredListRequest { selectedPage: number; pageSize: number; sortColumn?: string | undefined; columns: Array<string>; sortedAsc: boolean; filters: Dict<string>; filtersPrefix: string; dataProductDefinitionsPath?: string | undefined; constructor({ fields, template, queryParams, definitionsPath, filtersPrefix, reportType, }: { fields: components['schemas']['FieldDefinition'][]; template?: Template; queryParams: ParsedQs; definitionsPath?: string; filtersPrefix?: string; reportType?: ReportType; }); /** * Set the filers from the query params * - trims the start/end dates to min/max * - removes no-filter options * * @private * @param {ParsedQs} queryParams * @param {string} [min] * @param {string} [max] * @memberof ReportQuery */ private setAndTrimFiltersFromQuery; /** * Validates that all staticOption values are correct * * - checks/validates value against the staticOptions in the filter definition * - if not present then it is dropped from the query, * - and logged * * @private * @param {unknown} rawValue * @param {string} type * @param {components['schemas']['FilterDefinition']['staticOptions']} [staticOptions] * @param {string} [fieldName] * @return {*} {(string | undefined)} * @memberof ReportQuery */ private validateSelectFilterValue; /** * Handles the setting of default values for date type filters * when no user input value has been applied * * - if min/max bounds in definition we ensure the date in within bounds * before being sent to the API * * @private * @param {components['schemas']['FieldDefinition'][]} fields * @memberof ReportQuery */ private handleUnsetDateTypeDefaultsAndBounds; /** * Set the default value for date filters where min/max is provided * * - If min / max exist and the user hasn’t already provided date bounds in the request, * - the code injects them as defaults so the filtering stays within those bounds. * * @private * @memberof ReportQuery */ private setDefaultBoundsOnUnsetDatefields; private setColumns; /** * Sets the default sort column * * @private * @param {components['schemas']['FieldDefinition'][]} fields * @return {*} * @memberof ReportQuery */ private getDefaultSortColumn; /** * Gets the default sort direction * - Default if not set in DPD: ASC * * @private * @param {components['schemas']['FieldDefinition'][]} fields * @return {*} * @memberof ReportQuery */ private getDefaultSortDirection; /** * Get the pagesize for the request * - from query, otherwise set meaningful default * * @param {ParsedQs} queryParams * @param {Template} [template] * @param {ReportType} [reportType] * @return {*} {number} * @memberof ReportQuery */ getPageSize(queryParams: ParsedQs, template?: Template, reportType?: ReportType): number; toRecordWithFilterPrefix(removeClearedFilters?: boolean): Record<string, string | Array<string>>; /** * Gets a meaningful default pagesize for a request * * @private * @param {Template} template * @return {*} * @memberof ReportQuery */ private getDefaultPageSize; } export { ReportQuery, ReportQuery as default };