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.

855 lines (854 loc) 30.9 kB
import { Request } from 'express'; import { components } from '../../../types/api'; import { FilterValue, GranularDateRange, GranularDateRangeFilterValue } from '../../_filters/types'; import { Granularity, QuickFilters } from './types'; import { defaultFilterValue, DefaultGranularDateFilterValue } from '../../../utils/Personalisation/types'; export declare const setValueFromRequest: (filter: FilterValue, req: Request, prefix: string) => GranularDateRangeFilterValue["value"]; export declare const setDefaultValue: (req: Request, name: string) => { value: string | DefaultGranularDateFilterValue; name: string; }; export declare const setFilterValueFromDefault: (defaultValue: defaultFilterValue, filter: FilterValue) => { value: GranularDateRange; min?: string; max?: string; relativeOptions?: { value: string; text: string; disabled?: boolean; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; } | { value: GranularDateRange; minimumLength?: number | undefined | null; pattern?: string | undefined | null; text: string; name: string; type: import("../../_filters/filter-input/enum").FilterType; mandatory?: boolean | undefined; index?: number | undefined | null; } | { value: GranularDateRange; options: Array<import("../../_filters/types").FilterOption>; staticOptionNameValue?: string; dynamicResourceEndpoint?: string; text: string; name: string; type: import("../../_filters/filter-input/enum").FilterType; mandatory?: boolean | undefined; index?: number | undefined | null; } | { value: GranularDateRange; values: string[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; options: Array<import("../../_filters/types").FilterOption>; staticOptionNameValue?: string; dynamicResourceEndpoint?: string; } | { value: GranularDateRange; min?: string; max?: string; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; } | { value: GranularDateRange; min?: string; max?: string; relativeOptions?: { value: string; text: string; disabled?: boolean; }[]; quickFilterOptions?: { value: string; text: string; disabled?: boolean; }[]; granularityOptions?: { value: string; text: string; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; }; export declare const getFilterFromDefinition: (filter: components["schemas"]["FilterDefinition"], filterData: FilterValue) => { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; relativeOptions?: { value: string; text: string; disabled?: boolean; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; minimumLength?: number | undefined | null; pattern?: string | undefined | null; text: string; name: string; type: import("../../_filters/filter-input/enum").FilterType; mandatory?: boolean | undefined; index?: number | undefined | null; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; options: Array<import("../../_filters/types").FilterOption>; staticOptionNameValue?: string; dynamicResourceEndpoint?: string; text: string; name: string; type: import("../../_filters/filter-input/enum").FilterType; mandatory?: boolean | undefined; index?: number | undefined | null; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; values: string[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; options: Array<import("../../_filters/types").FilterOption>; staticOptionNameValue?: string; dynamicResourceEndpoint?: string; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; relativeOptions?: { value: string; text: string; disabled?: boolean; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; }; /** * Creates and appends the granular daterange query string * to an existing URLSearchParams * * @param {URLSearchParams} params * @param {string} fieldName * @param {string} defaultValue */ export declare const appendGranularDateRangeValue: (params: URLSearchParams, fieldName: string, options: { start?: string; end?: string; granularity?: components["schemas"]["FilterDefinition"]["defaultGranularity"]; quickFilter?: components["schemas"]["FilterDefinition"]["defaultQuickFilterValue"]; }) => void; type GranularDateRangeDefaults = { start?: string; end?: string; granularity?: components['schemas']['FilterDefinition']['defaultGranularity']; quickFilter?: components['schemas']['FilterDefinition']['defaultQuickFilterValue']; }; /** * Resolves default values for a `granulardaterange` filter definition. * * Applies precedence rules: * 1. `defaultQuickFilterValue` (derives start, end, and granularity) * 2. `defaultGranularity` combined with `defaultValue` (explicit range) * 3. `defaultGranularity` only * * Returns plain resolved values suitable for query construction, or * `undefined` if the definition does not specify any usable defaults. * * @param {components['schemas']['FilterDefinition']} filter * @return {*} {(GranularDateRangeDefaults | undefined)} */ export declare const resolveGranularDateRangeDefaults: (filter: components["schemas"]["FilterDefinition"]) => GranularDateRangeDefaults | undefined; declare const _default: { getFilterFromDefinition: (filter: components["schemas"]["FilterDefinition"], filterData: FilterValue) => { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; relativeOptions?: { value: string; text: string; disabled?: boolean; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; minimumLength?: number | undefined | null; pattern?: string | undefined | null; text: string; name: string; type: import("../../_filters/filter-input/enum").FilterType; mandatory?: boolean | undefined; index?: number | undefined | null; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; options: Array<import("../../_filters/types").FilterOption>; staticOptionNameValue?: string; dynamicResourceEndpoint?: string; text: string; name: string; type: import("../../_filters/filter-input/enum").FilterType; mandatory?: boolean | undefined; index?: number | undefined | null; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; values: string[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; options: Array<import("../../_filters/types").FilterOption>; staticOptionNameValue?: string; dynamicResourceEndpoint?: string; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; } | { min: string | null | undefined; max: string | null | undefined; value: { start: string; end: string; granularity: { value: Granularity.DAILY | Granularity.MONTHLY | Granularity.ANNUALLY; display: string; }; quickFilter: { value: "today" | "yesterday" | "last-seven-days" | "last-thirty-days" | "last-month" | "last-full-month" | "last-ninety-days" | "last-three-months" | "last-full-three-months" | "last-year" | "last-full-year" | "tomorrow" | "next-seven-days" | "next-thirty-days" | "next-month" | "next-full-month" | "next-ninety-days" | "next-three-months" | "next-full-three-months" | "next-year" | "next-full-year"; display: string; }; partialDate: { start: boolean; end: boolean; }; } | { granularity: { value: Granularity; display: string; }; quickFilter: { value: QuickFilters; display: string; }; partialDate: { start: boolean; end: boolean; }; start: string; end: string; relative?: import("../date-range/types").RelativeDateRange | undefined; }; quickFilterOptions: { value: QuickFilters; text: string; disabled?: boolean; }[]; granularityOptions: { value: Granularity; text: string; disabled?: boolean; }[]; relativeOptions?: { value: string; text: string; disabled?: boolean; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; }; setValueFromRequest: (filter: FilterValue, req: Request, prefix: string) => GranularDateRangeFilterValue["value"]; setDefaultValue: (req: Request, name: string) => { value: string | DefaultGranularDateFilterValue; name: string; }; setFilterValueFromDefault: (defaultValue: defaultFilterValue, filter: FilterValue) => { value: GranularDateRange; min?: string; max?: string; relativeOptions?: { value: string; text: string; disabled?: boolean; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; } | { value: GranularDateRange; minimumLength?: number | undefined | null; pattern?: string | undefined | null; text: string; name: string; type: import("../../_filters/filter-input/enum").FilterType; mandatory?: boolean | undefined; index?: number | undefined | null; } | { value: GranularDateRange; options: Array<import("../../_filters/types").FilterOption>; staticOptionNameValue?: string; dynamicResourceEndpoint?: string; text: string; name: string; type: import("../../_filters/filter-input/enum").FilterType; mandatory?: boolean | undefined; index?: number | undefined | null; } | { value: GranularDateRange; values: string[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; options: Array<import("../../_filters/types").FilterOption>; staticOptionNameValue?: string; dynamicResourceEndpoint?: string; } | { value: GranularDateRange; min?: string; max?: string; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; } | { value: GranularDateRange; min?: string; max?: string; relativeOptions?: { value: string; text: string; disabled?: boolean; }[]; quickFilterOptions?: { value: string; text: string; disabled?: boolean; }[]; granularityOptions?: { value: string; text: string; }[]; type: import("../../_filters/filter-input/enum").FilterType; name: string; text: string; mandatory?: boolean | undefined | undefined; index?: number | undefined | null | undefined; }; appendGranularDateRangeValue: (params: URLSearchParams, fieldName: string, options: { start?: string; end?: string; granularity?: components["schemas"]["FilterDefinition"]["defaultGranularity"]; quickFilter?: components["schemas"]["FilterDefinition"]["defaultQuickFilterValue"]; }) => void; resolveGranularDateRangeDefaults: (filter: components["schemas"]["FilterDefinition"]) => GranularDateRangeDefaults | undefined; }; export default _default;