From d1a86770099b51088220b2d25bc54b7972f48f8f Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Wed, 8 Jan 2025 21:09:40 +0000 Subject: [PATCH] Remove local copy of `makeQueryFunction` And, with it, a dependency on a non-advertised API. Fixes UIHAADM-146. --- CHANGELOG.md | 1 + src/search/queryFunction.js | 3 +- src/util/makeQueryFunction.js | 111 ---------------------------------- 3 files changed, 3 insertions(+), 112 deletions(-) delete mode 100644 src/util/makeQueryFunction.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 1085ea1..dcbcb21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * When downloading Failed Records, provide all records in the result set, not just the currently visible page. Fixes UIHAADM-140. * When running in development (`yarn start`) use the Stripes CLI's `--startProxy` argument. Fixes UIHAADM-144. * Explicitly specify paging size for Harvestables, Jobs and Failed Records. Fixes UIHAADM-145. +* Remove local copy of `makeQueryFunction`, and with it a dependency on a non-advertised API. Fixes UIHAADM-146. ## [2.2.0](https://github.com/folio-org/ui-harvester-admin/tree/v2.2.0) (2024-10-23) diff --git a/src/search/queryFunction.js b/src/search/queryFunction.js index 39f387d..68f97d2 100644 --- a/src/search/queryFunction.js +++ b/src/search/queryFunction.js @@ -1,4 +1,5 @@ -import makeQueryFunction from '../util/makeQueryFunction'; +import { makeQueryFunction } from '@folio/stripes/smart-components'; + const sortMap = { // All the headings are the names of sortable fields diff --git a/src/util/makeQueryFunction.js b/src/util/makeQueryFunction.js deleted file mode 100644 index baa76e3..0000000 --- a/src/util/makeQueryFunction.js +++ /dev/null @@ -1,111 +0,0 @@ -// XXX I don't think we need this copy, which seems more or less identical to what's in stripes-smart-components -// See UIHAADM-35 for the history of how it got here - -// eslint-disable-next-line import/no-extraneous-dependencies -import { compilePathTemplate } from '@folio/stripes-connect/RESTResource/RESTResource'; -import { filters2cql } from '@folio/stripes/components'; -import { escapeCqlValue } from '@folio/stripes/util'; -import { get } from 'lodash'; - -// eslint-disable-next-line import/no-extraneous-dependencies -import { removeNsKeys } from '@folio/stripes-smart-components/lib/SearchAndSort/nsQueryFunctions'; - -// return a function that returns a string, or null, which stripes-connect -// will use to construct a resource query. it will accept four params: -// -// * An object containing the UI URL's query parameters (as accessed by ?{name}). -// * An object containing the UI URL's path components (as accessed by :{name}). -// * An object containing the component's resources' data (as accessed by %{name}). -// * A logger object. -// -// @findAll string: CQL query to retrieve all records when there is a sort-clause but no CQL query -// @queryTemplate string|function: CQL query to interpolate or function which will return CQL as a string -// @sortMap object: map from sort-keys to the CQL fields they match -// @filterConfig array: list of filter objects with keys label, name, cql, values -// @failOnCondition int: -// 0: do not fail even if query and filters and empty -// 1: fail if query is empty, whatever the filter state -// 2: fail if both query and filters and empty. -// For compatibility, false and true may be used for 0 and 1 respectively. -// @nsParams object|string: namespace keys -// @configOrEscape object|boolean: an object containing configuration parameters: -// escape (boolean): whether to escape quote and backslash values in the query (default: true) -// rightTrunc (boolean): whether to append '*' to query terms (default: true) -// For compatibility, a boolean value may be passed, and is used as the `escape` configuration value. -function makeQueryFunction(findAll, queryTemplate, sortMap, filterConfig, failOnCondition, nsParams, configOrEscape = true) { - const config = typeof configOrEscape === 'object' ? - { rightTrunc: true, escape: true, ...configOrEscape } : - { rightTrunc: true, escape: configOrEscape }; - - return (queryParams, pathComponents, resourceValues, logger) => { - const resourceQuery = removeNsKeys(resourceValues.query, nsParams); - const nsQueryParams = removeNsKeys(queryParams, nsParams); - const { qindex, filters, query, sort } = resourceQuery || {}; - - if ((query === undefined || query === '') && - (failOnCondition === 1 || failOnCondition === true)) { - return null; - } - if ((query === undefined || query === '') && - (filters === undefined || filters === '') && - (failOnCondition === 2)) { - return null; - } - - const escapeFx = config.escape ? escapeCqlValue : (s) => (s); - - let cql; - if (query && qindex) { - const t = qindex.split('/', 2); - if (t.length === 1) { - cql = `${qindex}="${escapeFx(query)}${config.rightTrunc ? '*' : ''}"`; - } else { - cql = `${t[0]} =/${t[1]} "${escapeFx(query)}${config.rightTrunc ? '*' : ''}"`; - } - } else if (query) { - const escapedQuery = { ...resourceQuery, ...{ query: escapeFx(get(resourceQuery, 'query', '')) } }; - cql = (typeof queryTemplate === 'function') - ? queryTemplate(nsQueryParams, pathComponents, { query: escapedQuery }) - : compilePathTemplate(queryTemplate, nsQueryParams, pathComponents, { query: escapedQuery }); - - if (cql === null) { - // Some part of the template requires something that we don't have. - return null; - } - } - - - const filterCql = filters2cql(filterConfig, filters); - if (filterCql) { - if (cql) { - cql = `(${cql}) and ${filterCql}`; - } else { - cql = filterCql; - } - } - - if (sort) { - const sortIndexes = sort.split(',').map((sort1) => { - let reverse = false; - if (sort1.startsWith('-')) { - sort1 = sort1.substr(1); // eslint-disable-line no-param-reassign - reverse = true; - } - let sortIndex = sortMap[sort1] || sort1; - if (reverse) { - sortIndex = sortIndex.replace(' ', '/sort.descending ') + '/sort.descending'; - } - return sortIndex; - }); - - if (cql === undefined) cql = findAll; - cql = `(${cql}) sortby ${sortIndexes.join(' ')}`; - } - - logger.log('mquery', `query='${query}' filters='${filters}' sort='${sort}' -> ${cql}`); - - return cql; - }; -} - -export default makeQueryFunction;