@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
54 lines (53 loc) • 2.94 kB
TypeScript
import { components } from '../../types/api';
import { DashboardDataResponse } from '../../types/Metrics';
/**
* Returns whether the keys array contains optional ones
*
* @param {components['schemas']['DashboardVisualisationColumnDefinition'][]} keys
* @return {*} {boolean}
*/
export declare const hasOptionalKeys: (keys: components["schemas"]["DashboardVisualisationColumnDefinition"][]) => boolean;
/**
* Filters dashboard data rows based on the most complete valid set of column IDs.
*
* Workflow:
* 1. Generate all fallback key combinations using getKeyVariations().
* 2. Use getKeyIds() to determine the "best" set of required keys — meaning:
* the largest set of IDs for which *at least one* row has valid data
* (non-empty, non-null, non-undefined).
* 3. Filter the entire dataset to keep only rows that have valid values
* for all selected required keys.
*
* @param {DashboardDataResponse[]} dashboardData The full dataset to filter.
* @param {components['schemas']['DashboardVisualisationColumnDefinition'][]} keys Column definitions used to derive key combinations.
* @returns {DashboardDataResponse[]} Rows that satisfy the selected required-key validity rules.
*/
export declare const filterRowsByKeys: (dashboardData: DashboardDataResponse[], keys: components["schemas"]["DashboardVisualisationColumnDefinition"][]) => DashboardDataResponse[];
/**
* Generate all valid column ID variations based on trailing optional keys.
*
* Behaviour rules:
* 1. Begin with the full list of column IDs.
* 2. Iterate backward through the keys:
* - Add the current remaining IDs as a variation.
* - If the current key is optional, remove its ID from the end.
* - If the current key is NOT optional, stop removing afterward.
* 3. If *all* keys are optional, append an empty list.
*
* @param {components['schemas']['DashboardVisualisationColumnDefinition'][]} keys The visualisation column definitions.
* @returns {string[][]} An array of ID combinations representing valid fallback sets.
*/
export declare const getKeyVariations: (keys: components["schemas"]["DashboardVisualisationColumnDefinition"][]) => string[][];
/**
* Given dashboard data and a list of column-ID variations (from getKeyVariations),
* this function returns the *first* ID set for which there exists at least one
* row where all referenced fields contain valid (non-empty, non-null) raw values.
*
* If *none* of the variations produce any valid rows, the function returns the
* *last* variation tested.
*
* @param {DashboardDataResponse[]} dashboardData Array of dataset rows to validate.
* @param {string[][]} colIdVariations Variations of column IDs, ordered from most strict → least strict.
* @returns {string[]} The first ID set that has at least one fully-valid row, or the last set.
*/
export declare const getKeyIds: (dashboardData: DashboardDataResponse[], colIdVariations: string[][]) => string[];