@redocly/theme 0.35.5 → 0.35.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,5 @@ import type { ResolvedNavItem } from '../../types/portal';
2
2
  import type { FilteredCatalog } from '../../types/portal/src/shared/types/catalog';
3
3
  import type { CatalogConfig } from '../../config';
4
4
  export declare function useCatalog(items: ResolvedNavItem[], config: CatalogConfig): FilteredCatalog;
5
- export declare function fillSearchParams(filterProperty: string, filterValues: Set<string>, searchParams: URLSearchParams): URLSearchParams;
6
- export declare function handleFilterInput(filterTerm: string): URLSearchParams;
5
+ export declare function fillSearchParams(filterProperty: string, filterValues: Set<string>, searchParams: URLSearchParams): void;
7
6
  export declare function getFilterValues(filterValues: any): Set<string>;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getFilterValues = exports.handleFilterInput = exports.fillSearchParams = exports.useCatalog = void 0;
26
+ exports.getFilterValues = exports.fillSearchParams = exports.useCatalog = void 0;
27
27
  const React = __importStar(require("react"));
28
28
  const react_router_dom_1 = require("react-router-dom");
29
29
  const telemetry_1 = require("../../mocks/telemetry");
@@ -90,14 +90,15 @@ function useCatalog(items, config) {
90
90
  window.scrollTo(0, 0);
91
91
  }, [filtersWithOptions]);
92
92
  const handleSearchParams = () => {
93
- let newSearchParams = handleFilterInput(filterTerm);
93
+ const newSearchParams = new URLSearchParams(Array.from(searchParams.entries()));
94
+ filterTerm ? searchParams.set('filter', filterTerm) : searchParams.delete('filter');
94
95
  filtersState.forEach((filterValues, filterIdx) => {
95
96
  var _a;
96
97
  const filter = (_a = config.filters) === null || _a === void 0 ? void 0 : _a[filterIdx];
97
98
  if (!filter)
98
99
  return;
99
100
  const values = getFilterValues(filterValues);
100
- newSearchParams = fillSearchParams(filter.property, values, newSearchParams);
101
+ fillSearchParams(filter.property, values, newSearchParams);
101
102
  });
102
103
  const newSearch = newSearchParams.toString();
103
104
  if (newSearch === location.search.substring(1))
@@ -309,22 +310,13 @@ function mapFilterValues(value, mapping) {
309
310
  : mapping[String(value)] || value;
310
311
  }
311
312
  function fillSearchParams(filterProperty, filterValues, searchParams) {
313
+ // Clear old values of the filter before repopulating
314
+ searchParams.delete(filterProperty);
312
315
  filterValues.forEach((value) => {
313
- if (!searchParams.has(filterProperty, value))
314
- searchParams.append(filterProperty, value);
316
+ searchParams.append(filterProperty, value);
315
317
  });
316
- return searchParams;
317
318
  }
318
319
  exports.fillSearchParams = fillSearchParams;
319
- function handleFilterInput(filterTerm) {
320
- const searchParams = new URLSearchParams();
321
- if (filterTerm)
322
- searchParams.set('filter', filterTerm);
323
- else
324
- searchParams.delete('filter');
325
- return searchParams;
326
- }
327
- exports.handleFilterInput = handleFilterInput;
328
320
  function getFilterValues(filterValues) {
329
321
  const values = new Set();
330
322
  if (filterValues instanceof Set)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.35.5",
3
+ "version": "0.35.7",
4
4
  "description": "Shared UI components lib",
5
5
  "keywords": [
6
6
  "theme",
@@ -89,7 +89,7 @@
89
89
  "react-calendar": "4.2.1",
90
90
  "react-date-picker": "10.0.3",
91
91
  "timeago.js": "^4.0.2",
92
- "@redocly/config": "0.1.4"
92
+ "@redocly/config": "0.1.5"
93
93
  },
94
94
  "scripts": {
95
95
  "start": "npm-run-all --parallel storybook storybook:tokens:watch",
@@ -86,13 +86,15 @@ export function useCatalog(items: ResolvedNavItem[], config: CatalogConfig): Fil
86
86
  );
87
87
 
88
88
  const handleSearchParams = () => {
89
- let newSearchParams = handleFilterInput(filterTerm);
89
+ const newSearchParams = new URLSearchParams(Array.from(searchParams.entries()));
90
+
91
+ filterTerm ? searchParams.set('filter', filterTerm) : searchParams.delete('filter');
90
92
 
91
93
  filtersState.forEach((filterValues, filterIdx) => {
92
94
  const filter = config.filters?.[filterIdx];
93
95
  if (!filter) return;
94
96
  const values = getFilterValues(filterValues);
95
- newSearchParams = fillSearchParams(filter.property, values, newSearchParams);
97
+ fillSearchParams(filter.property, values, newSearchParams);
96
98
  });
97
99
 
98
100
  const newSearch = newSearchParams.toString();
@@ -371,20 +373,11 @@ export function fillSearchParams(
371
373
  filterValues: Set<string>,
372
374
  searchParams: URLSearchParams,
373
375
  ) {
376
+ // Clear old values of the filter before repopulating
377
+ searchParams.delete(filterProperty);
374
378
  filterValues.forEach((value) => {
375
- if (!searchParams.has(filterProperty, value)) searchParams.append(filterProperty, value);
379
+ searchParams.append(filterProperty, value);
376
380
  });
377
-
378
- return searchParams;
379
- }
380
-
381
- export function handleFilterInput(filterTerm: string) {
382
- const searchParams = new URLSearchParams();
383
-
384
- if (filterTerm) searchParams.set('filter', filterTerm);
385
- else searchParams.delete('filter');
386
-
387
- return searchParams;
388
381
  }
389
382
 
390
383
  export function getFilterValues(filterValues: any) {
@@ -79,7 +79,7 @@ export function useCatalog(_items: ResolvedNavItem[], _config: CatalogConfig): F
79
79
  }
80
80
 
81
81
  export const useTranslate = (): { translate: TFunction } => ({
82
- translate: (value?: string, options?: { defaultValue: string } | string) =>
82
+ translate: (value?: string, options?: { defaultValue?: string } | string) =>
83
83
  (typeof options === 'string' ? options : options?.defaultValue) || value || '',
84
84
  });
85
85