From ef26138c9fcb5c7a59b5f5bed6046cd9b09a7edc Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Tue, 26 Nov 2024 14:03:51 +0400 Subject: [PATCH] UISACQCOMP-230 Fix version history label resolving (#835) * UISACQCOMP-230 Fix version history label resolving * Properly replace all template values --- .../components/VersionKeyValue/VersionKeyValue.js | 3 ++- lib/VersionHistory/getFieldLabels.js | 2 +- lib/hooks/useCategories/useCategories.js | 13 +++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/VersionHistory/components/VersionKeyValue/VersionKeyValue.js b/lib/VersionHistory/components/VersionKeyValue/VersionKeyValue.js index fa340550..fe4a9937 100644 --- a/lib/VersionHistory/components/VersionKeyValue/VersionKeyValue.js +++ b/lib/VersionHistory/components/VersionKeyValue/VersionKeyValue.js @@ -1,3 +1,4 @@ +import escapeRegExp from 'lodash/escapeRegExp'; import PropTypes from 'prop-types'; import { useContext, @@ -21,7 +22,7 @@ export const VersionKeyValue = ({ const versionContext = useContext(VersionViewContext); const isUpdated = useMemo(() => ( multiple - ? versionContext?.paths?.find((field) => new RegExp(`^${name}\\[\\d\\]$`).test(field)) + ? versionContext?.paths?.find((field) => new RegExp(`^${escapeRegExp(name)}\\[\\d\\]$`).test(field)) : versionContext?.paths?.includes(name) ), [multiple, name, versionContext?.paths]); diff --git a/lib/VersionHistory/getFieldLabels.js b/lib/VersionHistory/getFieldLabels.js index ecf68752..34e304bd 100644 --- a/lib/VersionHistory/getFieldLabels.js +++ b/lib/VersionHistory/getFieldLabels.js @@ -8,7 +8,7 @@ export const getFieldLabels = (intl, paths, labelsMap = {}, hiddenFields = []) = return paths.reduce((acc, path) => { const fieldLabel = labelsMapEntries.find(([fieldPath]) => { - const regex = new RegExp(`^${escapeRegExp(fieldPath).replace('\\\\d', '\\d')}$`); + const regex = new RegExp(`^${escapeRegExp(fieldPath).replaceAll('\\\\d', '\\d')}$`); return regex.test(path); })?.[1] || path; diff --git a/lib/hooks/useCategories/useCategories.js b/lib/hooks/useCategories/useCategories.js index 81c93c84..3c445efc 100644 --- a/lib/hooks/useCategories/useCategories.js +++ b/lib/hooks/useCategories/useCategories.js @@ -6,6 +6,7 @@ import { } from '@folio/stripes/core'; import { + ALL_RECORDS_CQL, CATEGORIES_API, LIMIT_MAX, } from '../../constants'; @@ -19,18 +20,18 @@ export const useCategories = (options = {}) => { const searchParams = { limit: LIMIT_MAX, - query: 'cql.allRecords=1', + query: ALL_RECORDS_CQL, }; const { data, isFetching, isLoading, - } = useQuery( - [namespace], - () => ky.get(CATEGORIES_API, { searchParams }).json(), - options, - ); + } = useQuery({ + queryKey: [namespace], + queryFn: ({ signal }) => ky.get(CATEGORIES_API, { searchParams, signal }).json(), + ...options, + }); const [translatedCategories] = useTranslatedCategories(data?.categories);