<commit_before>/* @flow */

import React from 'react';
import LocationSubscriber from '@ncigdc/components/LocationSubscriber';

import { mergeQuery as mq } from '@ncigdc/utils/filters';

import type { TRawQuery } from '@ncigdc/utils/uri/types';

import InternalLink from './InternalLink';

import type { TLinkProps } from './types';

const InternalLinkWithContext = ({ pathname, query, merge, mergeQuery, whitelist, ...rest }: TLinkProps) => (
  <LocationSubscriber>{
    (ctx: {| pathname: string, query: TRawQuery |}) => {
      const pn = pathname || ctx.pathname;

      const q = (merge && mergeQuery)
        ? mergeQuery(
          query,
          ctx.query,
          merge,
          whitelist)
        : query;

      return (
        <InternalLink
          pathname={pn}
          query={q}
          {...rest}
        />
      );
    }
  }</LocationSubscriber>
);

InternalLinkWithContext.defaultProps = { // eslint-disable-line fp/no-mutation
  mergeQuery: mq,
};

export default InternalLinkWithContext;<commit_msg>✨PRTL-909 updating filter should reset pagination<commit_after>/* @flow */

import React from 'react';
import _ from 'lodash';
import LocationSubscriber from '@ncigdc/components/LocationSubscriber';

import { mergeQuery as mq } from '@ncigdc/utils/filters';

import type { TRawQuery } from '@ncigdc/utils/uri/types';

import InternalLink from './InternalLink';

import type { TLinkProps } from './types';

const InternalLinkWithContext = ({ pathname, query, merge, mergeQuery, whitelist, ...rest }: TLinkProps) => (
  <LocationSubscriber>{
    (ctx: {| pathname: string, query: TRawQuery |}) => {
      const pn = pathname || ctx.pathname;

      const mergedQuery = (merge && mergeQuery)
        ? mergeQuery(
          query,
          ctx.query,
          merge,
          whitelist)
        : query;

      const hasFilterChanged = _.some([
        // Note: empty {} passed in b/c
        // mergeQuery(ctx.query).filters is a jsurl string
        // mergeQuery({}, ctx.query).filters is an object
        _.isEqual(mergedQuery.filters, mergeQuery({}, ctx.query).filters),
        _.every([ctx.query.filters, mergedQuery.filters], _.isNil),
      ]);

      const queryWithOffsetsReset = (
        hasFilterChanged
          ? mergedQuery
          : _.mapValues(mergedQuery,
              (value, paramName) => (paramName.endsWith('offset') ? 0 : value)
            )
      );

      return (
        <InternalLink
          pathname={pn}
          query={queryWithOffsetsReset}
          {...rest}
        />
      );
    }
  }</LocationSubscriber>
);

InternalLinkWithContext.defaultProps = { // eslint-disable-line fp/no-mutation
  mergeQuery: mq,
};

export default InternalLinkWithContext;
{'fraction_non_alphanumeric': 0.12967032967032968, 'fraction_numerical': 0.0014652014652014652, 'mean_word_length': 2.551365409622887, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1220759', 'n_tokens_mistral': 808, 'n_tokens_neox': 792, 'n_words': 187}