import { filters2cql } from '@folio/stripes-components/lib/FilterGroups';

function makePathFunction(basePath, findAll, queryTemplate, sortMap, filterConfig) {
  return (queryParams, _pathComponents, _resourceValues, logger) => {
    const { query, filters, sort } = queryParams || {};

    let cql = !query ? undefined : queryTemplate.replace(/\${query}/g, query);
    const filterCql = filters2cql(filterConfig, filters);
    if (filterCql) {
      if (cql) {
        cql = `(${cql}) and ${filterCql}`;
      } else {
        cql = filterCql;
      }
    }

    if (sort) {
      const sortIndex = sortMap[sort] || sort;
      if (cql === undefined) cql = findAll;
      cql += ` sortby ${sortIndex}`;
    }

    let path = basePath;
    if (cql) path += `?query=${encodeURIComponent(cql)}`;

    logger.log('mpath', `query='${query}' filters='${filters}' sort='${sort}' -> ${path}`);
    return path;
  };
}

export default makePathFunction;

import { filters2cql } from '@folio/stripes-components/lib/FilterGroups';

function makePathFunction(basePath, findAll, queryTemplate, sortMap, filterConfig) {
  return (queryParams, _pathComponents, _resourceValues, logger) => {
    const { query, filters, sort } = queryParams || {};

    let cql = !query ? undefined : queryTemplate.replace(/\$QUERY/g, query);
    const filterCql = filters2cql(filterConfig, filters);
    if (filterCql) {
      if (cql) {
        cql = `(${cql}) and ${filterCql}`;
      } else {
        cql = filterCql;
      }
    }

    if (sort) {
      const sortIndex = sortMap[sort] || sort;
      if (cql === undefined) cql = findAll;
      cql += ` sortby ${sortIndex}`;
    }

    let path = basePath;
    if (cql) path += `?query=${encodeURIComponent(cql)}`;

    logger.log('mpath', `query='${query}' filters='${filters}' sort='${sort}' -> ${path}`);
    return path;
  };
}

export default makePathFunction;

Change substitution syntax in queryTemplate from ${query} to $QUERY. The former misleading resembled ES6 string-template notations, but that's not really what was happening here -- as was rightly pointed out by an ESLint no-template-curly-in-string error in Users.js.
Change substitution syntax in queryTemplate from ${query} to $QUERY. The former misleading resembled ES6 string-template notations, but that's not really what was happening here -- as was rightly pointed out by an ESLint no-template-curly-in-string error in Users.js.
