datahub/datahub-web-react/src/app/shared/updateQueryParams.ts
John Joyce 4da49fb1b4
refactor(ui): Make Navigating DataHub UI easier, fix duplicate tracking, duplicate networks calls, + misc optimizations (#7592)
Co-authored-by: david-leifker <114954101+david-leifker@users.noreply.github.com>
2023-03-21 18:36:21 -07:00

21 lines
627 B
TypeScript

import * as QueryString from 'query-string';
import { Location, History } from 'history';
type QueryParam = {
[key: string]: string | undefined;
};
export default function updateQueryParams(newParams: QueryParam, location: Location, history: History) {
const parsedParams = QueryString.parse(location.search, { arrayFormat: 'comma' });
const updatedParams = {
...parsedParams,
...newParams,
};
const stringifiedParams = QueryString.stringify(updatedParams, { arrayFormat: 'comma' });
history.replace({
pathname: location.pathname,
search: stringifiedParams,
});
}