datahub/datahub-web/@datahub/utils/addon/routes/refresh-model-for-query-params.ts
Ignacio Bona Piedrabuena 89c78551cc
1604086049622-ui-sync (#1981)
Co-authored-by: Ignacio Bona <ibonapiedrabuena@linkedin.com>
2020-11-09 12:17:51 -08:00

19 lines
574 B
TypeScript

import { reduce } from 'lodash-es';
/**
* Shorthand to reduce visual complexity of code below
*/
type QueryParam = Record<string, { refreshModel: true }>;
/**
* For each given query param, creates an object with `refreshModel` set to true
* @param {Array<string>} [params=[]]
* @returns {Record<string, { refreshModel: true }>}
*/
export const refreshModelForQueryParams = (params: Array<string> = []): QueryParam =>
reduce(
params,
(queryParams: QueryParam, param: string): QueryParam => ({ ...queryParams, [param]: { refreshModel: true } }),
{}
);