@cccsaurora/howler-ui 2.16.2 → 2.16.4

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.
@@ -22,5 +22,4 @@ export interface HitSearchContextType {
22
22
  }
23
23
  export declare const HitSearchContext: import("use-context-selector").Context<HitSearchContextType>;
24
24
  declare const HitSearchProvider: FC<PropsWithChildren>;
25
- export declare const useHitSearchContextSelector: <Selected>(selector: (value: HitSearchContextType) => Selected) => Selected;
26
25
  export default HitSearchProvider;
@@ -77,7 +77,7 @@ const HitSearchProvider = ({ children }) => {
77
77
  }
78
78
  // Fetch all view queries
79
79
  if (views.length > 0) {
80
- const viewObjects = await getCurrentViews();
80
+ const viewObjects = await getCurrentViews({ views });
81
81
  // Filter out null/undefined views and extract queries
82
82
  viewObjects
83
83
  .filter(view => view?.query)
@@ -157,7 +157,8 @@ const HitSearchProvider = ({ children }) => {
157
157
  trackTotalHits,
158
158
  loadHits,
159
159
  getCurrentViews,
160
- setOffset
160
+ setOffset,
161
+ getFilters
161
162
  ]);
162
163
  // We only run this when ancillary properties (i.e. filters, sorting) change
163
164
  useEffect(() => {
@@ -171,7 +172,7 @@ const HitSearchProvider = ({ children }) => {
171
172
  setResponse(null);
172
173
  }
173
174
  // eslint-disable-next-line react-hooks/exhaustive-deps
174
- }, [offset, pageCount, sort, span, bundleId, location.pathname, startDate, endDate, filters, query]);
175
+ }, [offset, pageCount, sort, span, bundleId, location.pathname, startDate, endDate, filters, query, views]);
175
176
  return (_jsx(HitSearchContext.Provider, { value: {
176
177
  displayType,
177
178
  setDisplayType,
@@ -187,7 +188,4 @@ const HitSearchProvider = ({ children }) => {
187
188
  setFzfSearch
188
189
  }, children: children }));
189
190
  };
190
- export const useHitSearchContextSelector = (selector) => {
191
- return useContextSelector(HitSearchContext, selector);
192
- };
193
191
  export default HitSearchProvider;
@@ -17,7 +17,7 @@ const mockSetParams = vi.fn();
17
17
  const mockParams = vi.mocked(useParams);
18
18
  const mockLocation = vi.mocked(useLocation());
19
19
  const mockViewContext = {
20
- getCurrentViews: ({ viewId } = {}) => Promise.resolve([{ view_id: viewId || 'test_view_id', query: 'howler.id:*' }])
20
+ getCurrentViews: ({ views } = {}) => Promise.resolve([{ view_id: views?.[0] || 'test_view_id', query: 'howler.id:*' }])
21
21
  };
22
22
  let mockParameterContext = {
23
23
  filters: [],
@@ -81,8 +81,8 @@ const ParameterProvider = ({ children }) => {
81
81
  if (value === values[key]) {
82
82
  return;
83
83
  }
84
- if (key === 'selected' && !value) {
85
- pendingChanges.current.selected = getSelectedValue(params, location.pathname, routeParams.id);
84
+ if (key === 'selected') {
85
+ pendingChanges.current.selected = value;
86
86
  }
87
87
  else {
88
88
  pendingChanges.current[key] = value ?? DEFAULT_VALUES[key] ?? null;
@@ -95,7 +95,7 @@ const ParameterProvider = ({ children }) => {
95
95
  _setValues(_current => ({ ..._current, ...pendingChanges.current }));
96
96
  pendingChanges.current = {};
97
97
  });
98
- }, [location.pathname, routeParams.id, values, params]);
98
+ }, [values]);
99
99
  const setOffset = useCallback(_offset => _setValues(_current => ({ ..._current, offset: parseOffset(_offset) })), []);
100
100
  const setCustomSpan = useCallback((startDate, endDate) => {
101
101
  _setValues(_values => ({
@@ -13,7 +13,7 @@ export interface ViewContextType {
13
13
  editView: (id: string, newView: Partial<Omit<View, 'view_id' | 'owner'>>) => Promise<View>;
14
14
  removeView: (id: string) => Promise<void>;
15
15
  getCurrentViews: (config?: {
16
- viewId?: string;
16
+ views?: string[];
17
17
  lazy?: boolean;
18
18
  ignoreParams?: boolean;
19
19
  }) => Promise<View[]>;
@@ -3,7 +3,7 @@ import api from '@cccsaurora/howler-ui/api';
3
3
  import { useAppUser } from '@cccsaurora/howler-ui/commons/components/app/hooks';
4
4
  import useMyApi from '@cccsaurora/howler-ui/components/hooks/useMyApi';
5
5
  import { useMyLocalStorageItem } from '@cccsaurora/howler-ui/components/hooks/useMyLocalStorage';
6
- import { has, omit } from 'lodash-es';
6
+ import { has, omit, uniq } from 'lodash-es';
7
7
  import { useCallback, useEffect, useState } from 'react';
8
8
  import { useSearchParams } from 'react-router-dom';
9
9
  import { createContext, useContextSelector } from 'use-context-selector';
@@ -59,11 +59,8 @@ const ViewProvider = ({ children }) => {
59
59
  }
60
60
  })();
61
61
  }, [defaultView, fetchViews, setDefaultView, views]);
62
- const getCurrentViews = useCallback(async ({ viewId, lazy = false, ignoreParams = false } = {}) => {
63
- const currentViews = ignoreParams ? [] : searchParams.getAll('view');
64
- if (viewId && !currentViews.includes(viewId)) {
65
- currentViews.push(viewId);
66
- }
62
+ const getCurrentViews = useCallback(async ({ views: _views, lazy = false, ignoreParams = false } = {}) => {
63
+ const currentViews = uniq([...(_views ?? []), ...(ignoreParams ? [] : searchParams.getAll('view'))]);
67
64
  if (currentViews.length < 1) {
68
65
  return [];
69
66
  }
@@ -135,7 +135,7 @@ describe('ViewContext', () => {
135
135
  it('should allow the user to fetch their current view based on the view ID', async () => {
136
136
  // lazy load should return nothing
137
137
  await expect(hook.result.current({ lazy: true })).resolves.toEqual([]);
138
- const result = await act(async () => hook.result.current({ viewId: 'searched_view_id' }));
138
+ const result = await act(async () => hook.result.current({ views: ['searched_view_id'] }));
139
139
  expect(result).toEqual([MOCK_RESPONSES['/api/v1/search/view'].items[0]]);
140
140
  });
141
141
  });
@@ -25,7 +25,7 @@ const ViewLink = ({ id, viewId }) => {
25
25
  const [view, setView] = useState(null);
26
26
  useEffect(() => {
27
27
  setLoading(true);
28
- getCurrentViews({ viewId, ignoreParams: true })
28
+ getCurrentViews({ views: [viewId], ignoreParams: true })
29
29
  .then(result => setView(result[0]))
30
30
  .finally(() => setLoading(false));
31
31
  }, [getCurrentViews, viewId]);
@@ -341,7 +341,7 @@ describe('ViewLink', () => {
341
341
  it('should call getCurrentViews when viewId changes', async () => {
342
342
  const { rerender } = render(_jsx(ViewLink, { id: 0, viewId: "test-view-id" }), { wrapper: Wrapper });
343
343
  await screen.findByText('Test View');
344
- expect(mockViewContext.getCurrentViews).toHaveBeenCalledWith({ viewId: 'test-view-id', ignoreParams: true });
344
+ expect(mockViewContext.getCurrentViews).toHaveBeenCalledWith({ views: ['test-view-id'], ignoreParams: true });
345
345
  mockViewContext.getCurrentViews = vi.fn().mockResolvedValue([
346
346
  createMockView({
347
347
  view_id: 'another-view-id',
@@ -350,7 +350,7 @@ describe('ViewLink', () => {
350
350
  ]);
351
351
  rerender(_jsx(ViewLink, { id: 0, viewId: "another-view-id" }));
352
352
  await screen.findByText('Another View');
353
- expect(mockViewContext.getCurrentViews).toHaveBeenCalledWith({ viewId: 'another-view-id', ignoreParams: true });
353
+ expect(mockViewContext.getCurrentViews).toHaveBeenCalledWith({ views: ['another-view-id'], ignoreParams: true });
354
354
  });
355
355
  });
356
356
  describe('Accessibility', () => {
@@ -385,7 +385,7 @@ describe('ViewLink', () => {
385
385
  mockViewContext.getCurrentViews = vi.fn().mockResolvedValue([createMockView()]);
386
386
  render(_jsx(ViewLink, { id: 0, viewId: "test-view-id" }), { wrapper: Wrapper });
387
387
  await screen.findByText('Test View');
388
- expect(mockViewContext.getCurrentViews).toHaveBeenCalledWith({ viewId: 'test-view-id', ignoreParams: true });
388
+ expect(mockViewContext.getCurrentViews).toHaveBeenCalledWith({ views: ['test-view-id'], ignoreParams: true });
389
389
  });
390
390
  it('should use removeView from ParameterContext', async () => {
391
391
  mockViewContext.getCurrentViews = vi.fn().mockResolvedValue([createMockView()]);
@@ -143,7 +143,7 @@ const ViewComposer = () => {
143
143
  return;
144
144
  }
145
145
  (async () => {
146
- const viewToEdit = (await getCurrentViews({ viewId: routeParams.id }))[0];
146
+ const viewToEdit = (await getCurrentViews({ views: [routeParams.id] }))[0];
147
147
  if (!viewToEdit) {
148
148
  setError('route.views.missing');
149
149
  return;
package/package.json CHANGED
@@ -96,7 +96,7 @@
96
96
  "internal-slot": "1.0.7"
97
97
  },
98
98
  "type": "module",
99
- "version": "2.16.2",
99
+ "version": "2.16.4",
100
100
  "exports": {
101
101
  "./i18n": "./i18n.js",
102
102
  "./index.css": "./index.css",