@cccsaurora/howler-ui 3.1.1-dev.1747.1 → 3.1.1-dev.1758.1
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.
- package/components/app/providers/ParameterProvider.d.ts +8 -0
- package/components/app/providers/ParameterProvider.js +173 -56
- package/components/app/providers/ParameterProvider.test.js +402 -1
- package/components/app/providers/RecordSearchProvider.js +32 -7
- package/components/app/providers/RecordSearchProvider.test.js +310 -3
- package/components/elements/display/ChipPopper.d.ts +1 -0
- package/components/elements/display/ChipPopper.js +6 -4
- package/components/elements/display/ChipPopper.test.js +9 -0
- package/components/routes/hits/search/ViewLink.js +8 -4
- package/components/routes/hits/search/ViewLink.test.js +83 -0
- package/components/routes/hits/search/shared/HitFilter.js +5 -1
- package/components/routes/hits/search/shared/HitFilter.test.js +40 -3
- package/components/routes/hits/search/shared/HitSort.js +4 -2
- package/components/routes/hits/search/shared/HitSort.test.js +24 -2
- package/components/routes/hits/search/shared/SearchSpan.js +5 -3
- package/components/routes/hits/search/shared/SearchSpan.test.js +15 -1
- package/locales/en/translation.json +3 -0
- package/locales/fr/translation.json +3 -0
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import { cloneDeep } from 'lodash-es';
|
|
|
6
6
|
import { setupContextSelectorMock, setupLocalStorageMock } from '@cccsaurora/howler-ui/tests/mocks';
|
|
7
7
|
import { useContextSelector } from 'use-context-selector';
|
|
8
8
|
import { DEFAULT_QUERY, MY_LOCAL_STORAGE_PREFIX, StorageKey } from '@cccsaurora/howler-ui/utils/constants';
|
|
9
|
-
import { ParameterContext } from './ParameterProvider';
|
|
9
|
+
import ParameterProvider, { ParameterContext } from './ParameterProvider';
|
|
10
10
|
import { RecordContext } from './RecordProvider';
|
|
11
11
|
import RecordSearchProvider, { RecordSearchContext } from './RecordSearchProvider';
|
|
12
12
|
import { ViewContext } from './ViewProvider';
|
|
@@ -17,14 +17,18 @@ import { useLocation, useParams, useSearchParams } from 'react-router';
|
|
|
17
17
|
const mockSetParams = vi.fn();
|
|
18
18
|
const mockParams = vi.mocked(useParams);
|
|
19
19
|
const mockLocation = vi.mocked(useLocation());
|
|
20
|
+
let mockSearchParams = new URLSearchParams();
|
|
20
21
|
const mockViewContext = {
|
|
21
22
|
getCurrentViews: ({ views } = {}) => Promise.resolve([{ view_id: views?.[0] || 'test_view_id', query: 'howler.id:*' }])
|
|
22
23
|
};
|
|
24
|
+
const originalMockViewContext = cloneDeep(mockViewContext);
|
|
23
25
|
let mockParameterContext = {
|
|
24
26
|
filters: [],
|
|
25
27
|
span: 'date.range.1.week',
|
|
26
28
|
sort: 'event.created desc',
|
|
27
29
|
query: 'howler.analytic:*',
|
|
30
|
+
disabledFilterIndexes: [],
|
|
31
|
+
disabledViewIndexes: [],
|
|
28
32
|
setQuery: query => (mockParameterContext.query = query),
|
|
29
33
|
offset: 0,
|
|
30
34
|
setOffset: offset => {
|
|
@@ -47,16 +51,20 @@ const mockHitContext = {
|
|
|
47
51
|
const Wrapper = ({ children }) => {
|
|
48
52
|
return (_jsx(ViewContext.Provider, { value: mockViewContext, children: _jsx(ParameterContext.Provider, { value: mockParameterContext, children: _jsx(RecordContext.Provider, { value: mockHitContext, children: _jsx(RecordSearchProvider, { children: children }) }) }) }));
|
|
49
53
|
};
|
|
54
|
+
const ParameterProviderWrapper = ({ children }) => {
|
|
55
|
+
return (_jsx(ViewContext.Provider, { value: mockViewContext, children: _jsx(ParameterProvider, { children: _jsx(RecordContext.Provider, { value: mockHitContext, children: _jsx(RecordSearchProvider, { children: children }) }) }) }));
|
|
56
|
+
};
|
|
50
57
|
beforeEach(() => {
|
|
58
|
+
Object.assign(mockViewContext, originalMockViewContext, { defaultView: undefined });
|
|
51
59
|
mockParameterContext = cloneDeep(originalMockParameterContext);
|
|
52
60
|
vi.mocked(originalMockParameterContext.addView).mockClear();
|
|
53
61
|
mockLocalStorage.clear();
|
|
54
|
-
mockSetParams.
|
|
62
|
+
mockSetParams.mockReset();
|
|
55
63
|
mockLocation.pathname = '/hits';
|
|
56
64
|
mockLocation.search = '';
|
|
57
65
|
mockParams.mockReturnValue({ id: undefined });
|
|
58
66
|
vi.mocked(hpost).mockClear();
|
|
59
|
-
|
|
67
|
+
mockSearchParams = new URLSearchParams();
|
|
60
68
|
vi.mocked(useSearchParams).mockReturnValue([mockSearchParams, mockSetParams]);
|
|
61
69
|
});
|
|
62
70
|
const expectSearchRequest = request => {
|
|
@@ -66,6 +74,17 @@ const expectSearchRequest = request => {
|
|
|
66
74
|
.map(([, body]) => body);
|
|
67
75
|
expect(requests).toEqual(expect.arrayContaining([expect.objectContaining(request)]));
|
|
68
76
|
};
|
|
77
|
+
const makeMockSetParamsUpdateUrl = () => {
|
|
78
|
+
mockSetParams.mockImplementation(nextParams => {
|
|
79
|
+
const replacement = typeof nextParams === 'function' ? nextParams(mockSearchParams) : nextParams;
|
|
80
|
+
const updatedParams = new URLSearchParams(replacement);
|
|
81
|
+
for (const key of [...mockSearchParams.keys()]) {
|
|
82
|
+
mockSearchParams.delete(key);
|
|
83
|
+
}
|
|
84
|
+
updatedParams.forEach((value, key) => mockSearchParams.append(key, value));
|
|
85
|
+
mockLocation.search = `?${mockSearchParams.toString()}`;
|
|
86
|
+
});
|
|
87
|
+
};
|
|
69
88
|
describe('RecordSearchContext', () => {
|
|
70
89
|
it('should initialize with default values', async () => {
|
|
71
90
|
const hook = renderHook(() => useContextSelector(RecordSearchContext, ctx => ({
|
|
@@ -138,6 +157,187 @@ describe('RecordSearchContext', () => {
|
|
|
138
157
|
expect(filters).toContain('-howler.assessment:*');
|
|
139
158
|
expect(filters).not.toContain('howler.assessment:*');
|
|
140
159
|
});
|
|
160
|
+
it('should omit disabled filters from the effective search request without changing enabled negative filters', async () => {
|
|
161
|
+
mockParameterContext.filters = ['howler.status:open', '-howler.assessment:*'];
|
|
162
|
+
mockParameterContext.disabledFilterIndexes = [0];
|
|
163
|
+
const hook = renderHook(() => useContextSelector(RecordSearchContext, ctx => ctx.search), { wrapper: Wrapper });
|
|
164
|
+
act(() => {
|
|
165
|
+
hook.result.current('test query');
|
|
166
|
+
});
|
|
167
|
+
await waitFor(() => {
|
|
168
|
+
expectSearchRequest({
|
|
169
|
+
query: 'test query',
|
|
170
|
+
filters: expect.arrayContaining(['-howler.assessment:*'])
|
|
171
|
+
});
|
|
172
|
+
expectSearchRequest({ filters: expect.not.arrayContaining(['howler.status:open']) });
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
it('applies copied-link disabled markers to the effective search on load', async () => {
|
|
176
|
+
const filters = [
|
|
177
|
+
'event.provider:"azure"',
|
|
178
|
+
'-howler.outline.indicators:("a" OR "b")',
|
|
179
|
+
'opaque clause [x TO y]',
|
|
180
|
+
'howler.status:open'
|
|
181
|
+
];
|
|
182
|
+
filters.forEach(filter => mockSearchParams.append('filter', filter));
|
|
183
|
+
filters.slice(0, 3).forEach(filter => mockSearchParams.append('disabled_filter', filter));
|
|
184
|
+
mockLocation.search = `?${mockSearchParams.toString()}`;
|
|
185
|
+
const hook = renderHook(() => ({
|
|
186
|
+
filters: useContextSelector(ParameterContext, ctx => ctx.filters),
|
|
187
|
+
disabledFilterIndexes: useContextSelector(ParameterContext, ctx => ctx.disabledFilterIndexes),
|
|
188
|
+
getFilters: useContextSelector(RecordSearchContext, ctx => ctx.getFilters),
|
|
189
|
+
search: useContextSelector(RecordSearchContext, ctx => ctx.search)
|
|
190
|
+
}), { wrapper: ParameterProviderWrapper });
|
|
191
|
+
expect(hook.result.current.filters).toEqual(filters);
|
|
192
|
+
expect(hook.result.current.disabledFilterIndexes).toEqual([0, 1, 2]);
|
|
193
|
+
const effectiveFilters = await hook.result.current.getFilters();
|
|
194
|
+
expect(effectiveFilters).toContain('howler.status:open');
|
|
195
|
+
filters.slice(0, 3).forEach(filter => expect(effectiveFilters).not.toContain(filter));
|
|
196
|
+
await waitFor(() => {
|
|
197
|
+
expectSearchRequest({
|
|
198
|
+
query: DEFAULT_QUERY,
|
|
199
|
+
filters: expect.arrayContaining(['howler.status:open'])
|
|
200
|
+
});
|
|
201
|
+
expectSearchRequest({
|
|
202
|
+
filters: expect.not.arrayContaining(filters.slice(0, 3))
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
it('runs the default search when a copied link loads with only disabled effective filters', async () => {
|
|
207
|
+
const filter = 'howler.status:open';
|
|
208
|
+
mockSearchParams.append('filter', filter);
|
|
209
|
+
mockSearchParams.append('disabled_filter', filter);
|
|
210
|
+
mockLocation.search = `?${mockSearchParams.toString()}`;
|
|
211
|
+
const hook = renderHook(() => ({
|
|
212
|
+
filters: useContextSelector(ParameterContext, ctx => ctx.filters),
|
|
213
|
+
disabledFilterIndexes: useContextSelector(ParameterContext, ctx => ctx.disabledFilterIndexes)
|
|
214
|
+
}), { wrapper: ParameterProviderWrapper });
|
|
215
|
+
expect(hook.result.current.filters).toEqual([filter]);
|
|
216
|
+
expect(hook.result.current.disabledFilterIndexes).toEqual([0]);
|
|
217
|
+
await waitFor(() => {
|
|
218
|
+
expectSearchRequest({
|
|
219
|
+
query: DEFAULT_QUERY,
|
|
220
|
+
filters: expect.not.arrayContaining([filter])
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
it('gives an immutable marker-only URL navigation precedence over a debounced query update', async () => {
|
|
225
|
+
mockSearchParams.append('filter', 'filter:a');
|
|
226
|
+
mockSearchParams.append('filter', 'filter:b');
|
|
227
|
+
mockSearchParams.set('query', 'incoming query');
|
|
228
|
+
mockLocation.search = `?${mockSearchParams.toString()}`;
|
|
229
|
+
const writes = [];
|
|
230
|
+
const snapshots = [];
|
|
231
|
+
vi.mocked(useSearchParams).mockImplementation(() => {
|
|
232
|
+
const snapshot = new URLSearchParams(mockLocation.search);
|
|
233
|
+
snapshots.push(snapshot);
|
|
234
|
+
const setParamsForSnapshot = nextParams => {
|
|
235
|
+
const next = typeof nextParams === 'function' ? nextParams(snapshot) : nextParams;
|
|
236
|
+
writes.push(new URLSearchParams(next).toString());
|
|
237
|
+
};
|
|
238
|
+
return [snapshot, setParamsForSnapshot];
|
|
239
|
+
});
|
|
240
|
+
const hook = renderHook(() => ({
|
|
241
|
+
query: useContextSelector(ParameterContext, ctx => ctx.query),
|
|
242
|
+
filters: useContextSelector(ParameterContext, ctx => ctx.filters),
|
|
243
|
+
disabledFilterIndexes: useContextSelector(ParameterContext, ctx => ctx.disabledFilterIndexes),
|
|
244
|
+
setQuery: useContextSelector(ParameterContext, ctx => ctx.setQuery),
|
|
245
|
+
getFilters: useContextSelector(RecordSearchContext, ctx => ctx.getFilters)
|
|
246
|
+
}), { wrapper: ParameterProviderWrapper });
|
|
247
|
+
act(() => hook.result.current.setQuery('local query'));
|
|
248
|
+
const incomingUrl = new URLSearchParams(mockLocation.search);
|
|
249
|
+
incomingUrl.append('disabled_filter', 'filter:a');
|
|
250
|
+
mockLocation.search = `?${incomingUrl.toString()}`;
|
|
251
|
+
await act(async () => {
|
|
252
|
+
await new Promise(resolve => setTimeout(resolve, 150));
|
|
253
|
+
});
|
|
254
|
+
expect(hook.result.current.query).toBe('incoming query');
|
|
255
|
+
expect(hook.result.current.filters).toEqual(['filter:a', 'filter:b']);
|
|
256
|
+
expect(hook.result.current.disabledFilterIndexes).toEqual([0]);
|
|
257
|
+
const effectiveFilters = await hook.result.current.getFilters();
|
|
258
|
+
expect(effectiveFilters).toContain('filter:b');
|
|
259
|
+
expect(effectiveFilters).not.toContain('filter:a');
|
|
260
|
+
expect(writes).toEqual([]);
|
|
261
|
+
await waitFor(() => {
|
|
262
|
+
expectSearchRequest({
|
|
263
|
+
query: 'incoming query',
|
|
264
|
+
filters: expect.arrayContaining(['filter:b'])
|
|
265
|
+
});
|
|
266
|
+
expectSearchRequest({ filters: expect.not.arrayContaining(['filter:a']) });
|
|
267
|
+
});
|
|
268
|
+
hook.rerender();
|
|
269
|
+
hook.rerender();
|
|
270
|
+
expect(mockLocation.search).toBe(`?${incomingUrl.toString()}`);
|
|
271
|
+
expect(hook.result.current.disabledFilterIndexes).toEqual([0]);
|
|
272
|
+
expect(writes).toEqual([]);
|
|
273
|
+
expect(snapshots.length).toBeGreaterThan(1);
|
|
274
|
+
expect(snapshots[snapshots.length - 1]).not.toBe(snapshots[snapshots.length - 2]);
|
|
275
|
+
});
|
|
276
|
+
it('keeps the surviving disabled filter excluded after an edit creates duplicate definitions', async () => {
|
|
277
|
+
mockSearchParams.append('filter', 'filter:a');
|
|
278
|
+
mockSearchParams.append('filter', 'filter:b');
|
|
279
|
+
mockLocation.search = '?filter=filter%3Aa&filter=filter%3Ab';
|
|
280
|
+
makeMockSetParamsUpdateUrl();
|
|
281
|
+
const hook = renderHook(() => ({
|
|
282
|
+
filters: useContextSelector(ParameterContext, ctx => ctx.filters),
|
|
283
|
+
disabledFilterIndexes: useContextSelector(ParameterContext, ctx => ctx.disabledFilterIndexes),
|
|
284
|
+
disableFilter: useContextSelector(ParameterContext, ctx => ctx.disableFilter),
|
|
285
|
+
setFilter: useContextSelector(ParameterContext, ctx => ctx.setFilter),
|
|
286
|
+
search: useContextSelector(RecordSearchContext, ctx => ctx.search)
|
|
287
|
+
}), { wrapper: ParameterProviderWrapper });
|
|
288
|
+
await act(async () => {
|
|
289
|
+
hook.result.current.disableFilter(0);
|
|
290
|
+
hook.result.current.disableFilter(1);
|
|
291
|
+
hook.result.current.setFilter(0, 'filter:b');
|
|
292
|
+
});
|
|
293
|
+
await act(async () => hook.rerender());
|
|
294
|
+
await waitFor(() => {
|
|
295
|
+
expect(hook.result.current.filters).toEqual(['filter:b']);
|
|
296
|
+
expect(hook.result.current.disabledFilterIndexes).toEqual([0]);
|
|
297
|
+
expect(mockSearchParams.getAll('filter')).toEqual(['filter:b']);
|
|
298
|
+
expect(mockSearchParams.getAll('disabled_filter')).toEqual(['filter:b']);
|
|
299
|
+
});
|
|
300
|
+
vi.mocked(hpost).mockClear();
|
|
301
|
+
act(() => {
|
|
302
|
+
hook.result.current.search();
|
|
303
|
+
});
|
|
304
|
+
await waitFor(() => {
|
|
305
|
+
expectSearchRequest({ filters: expect.not.arrayContaining(['filter:b']) });
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
it('keeps a duplicate filter effective when any collapsed occurrence was enabled', async () => {
|
|
309
|
+
mockSearchParams.append('filter', 'filter:a');
|
|
310
|
+
mockSearchParams.append('filter', 'filter:b');
|
|
311
|
+
mockLocation.search = '?filter=filter%3Aa&filter=filter%3Ab';
|
|
312
|
+
makeMockSetParamsUpdateUrl();
|
|
313
|
+
const hook = renderHook(() => ({
|
|
314
|
+
filters: useContextSelector(ParameterContext, ctx => ctx.filters),
|
|
315
|
+
disabledFilterIndexes: useContextSelector(ParameterContext, ctx => ctx.disabledFilterIndexes),
|
|
316
|
+
disableFilter: useContextSelector(ParameterContext, ctx => ctx.disableFilter),
|
|
317
|
+
setFilter: useContextSelector(ParameterContext, ctx => ctx.setFilter),
|
|
318
|
+
getFilters: useContextSelector(RecordSearchContext, ctx => ctx.getFilters),
|
|
319
|
+
search: useContextSelector(RecordSearchContext, ctx => ctx.search)
|
|
320
|
+
}), { wrapper: ParameterProviderWrapper });
|
|
321
|
+
await act(async () => {
|
|
322
|
+
hook.result.current.disableFilter(0);
|
|
323
|
+
hook.result.current.setFilter(0, 'filter:b');
|
|
324
|
+
});
|
|
325
|
+
await act(async () => hook.rerender());
|
|
326
|
+
await waitFor(() => {
|
|
327
|
+
expect(hook.result.current.filters).toEqual(['filter:b']);
|
|
328
|
+
expect(hook.result.current.disabledFilterIndexes).toEqual([]);
|
|
329
|
+
expect(mockSearchParams.getAll('filter')).toEqual(['filter:b']);
|
|
330
|
+
expect(mockSearchParams.getAll('disabled_filter')).toEqual([]);
|
|
331
|
+
});
|
|
332
|
+
expect(await hook.result.current.getFilters()).toContain('filter:b');
|
|
333
|
+
vi.mocked(hpost).mockClear();
|
|
334
|
+
act(() => {
|
|
335
|
+
hook.result.current.search();
|
|
336
|
+
});
|
|
337
|
+
await waitFor(() => {
|
|
338
|
+
expectSearchRequest({ filters: expect.arrayContaining(['filter:b']) });
|
|
339
|
+
});
|
|
340
|
+
});
|
|
141
341
|
it('should perform a search and update response', async () => {
|
|
142
342
|
const hook = renderHook(() => useContextSelector(RecordSearchContext, ctx => ({
|
|
143
343
|
search: ctx.search,
|
|
@@ -361,6 +561,42 @@ describe('RecordSearchContext', () => {
|
|
|
361
561
|
expect(hpost).toHaveBeenCalled();
|
|
362
562
|
}, { timeout: 2000 });
|
|
363
563
|
});
|
|
564
|
+
it('should refresh results when disabling the last effective filter', async () => {
|
|
565
|
+
mockParameterContext.query = DEFAULT_QUERY;
|
|
566
|
+
mockParameterContext.views = [];
|
|
567
|
+
mockParameterContext.filters = ['howler.status:open'];
|
|
568
|
+
const hook = renderHook(() => useContextSelector(RecordSearchContext, ctx => ctx.response), { wrapper: Wrapper });
|
|
569
|
+
await waitFor(() => {
|
|
570
|
+
expectSearchRequest({ filters: expect.arrayContaining(['howler.status:open']) });
|
|
571
|
+
});
|
|
572
|
+
vi.mocked(hpost).mockClear();
|
|
573
|
+
mockParameterContext.disabledFilterIndexes = [0];
|
|
574
|
+
hook.rerender();
|
|
575
|
+
await waitFor(() => {
|
|
576
|
+
expectSearchRequest({
|
|
577
|
+
query: DEFAULT_QUERY,
|
|
578
|
+
filters: expect.not.arrayContaining(['howler.status:open'])
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
vi.mocked(hpost).mockClear();
|
|
582
|
+
mockParameterContext.disabledFilterIndexes = [];
|
|
583
|
+
hook.rerender();
|
|
584
|
+
await waitFor(() => {
|
|
585
|
+
expectSearchRequest({
|
|
586
|
+
query: DEFAULT_QUERY,
|
|
587
|
+
filters: expect.arrayContaining(['howler.status:open'])
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
it('does not search when only a disabled positive wildcard placeholder remains', async () => {
|
|
592
|
+
mockParameterContext.query = DEFAULT_QUERY;
|
|
593
|
+
mockParameterContext.views = [];
|
|
594
|
+
mockParameterContext.filters = ['howler.assessment:*'];
|
|
595
|
+
mockParameterContext.disabledFilterIndexes = [0];
|
|
596
|
+
renderHook(() => useContextSelector(RecordSearchContext, ctx => ctx.response), { wrapper: Wrapper });
|
|
597
|
+
await new Promise(resolve => setTimeout(resolve, 600));
|
|
598
|
+
expect(hpost).not.toHaveBeenCalled();
|
|
599
|
+
});
|
|
364
600
|
it('should not trigger search when query is DEFAULT_QUERY', async () => {
|
|
365
601
|
mockParameterContext.query = DEFAULT_QUERY;
|
|
366
602
|
renderHook(() => useContextSelector(RecordSearchContext, ctx => ctx.response), { wrapper: Wrapper });
|
|
@@ -413,6 +649,77 @@ describe('RecordSearchContext', () => {
|
|
|
413
649
|
});
|
|
414
650
|
});
|
|
415
651
|
describe('multiple views support', () => {
|
|
652
|
+
describe('disabled views', () => {
|
|
653
|
+
beforeEach(() => {
|
|
654
|
+
mockViewContext.getCurrentViews = vi.fn(async ({ views = [], ignoreParams = false } = {}) => {
|
|
655
|
+
const ids = ignoreParams ? views : [...new Set([...views, ...mockSearchParams.getAll('view')])];
|
|
656
|
+
return ids.map(id => ({ view_id: id, query: `howler.analytic:${id}` }));
|
|
657
|
+
});
|
|
658
|
+
});
|
|
659
|
+
it('restores disabled views from copied links without reintroducing them from URL params', async () => {
|
|
660
|
+
mockSearchParams.append('view', 'disabled_view');
|
|
661
|
+
mockSearchParams.append('view', 'enabled_view');
|
|
662
|
+
mockSearchParams.append('disabled_view', 'disabled_view');
|
|
663
|
+
mockSearchParams.append('filter', '-howler.assessment:*');
|
|
664
|
+
mockSearchParams.set('disabled_index', 'hit');
|
|
665
|
+
mockLocation.search = `?${mockSearchParams.toString()}`;
|
|
666
|
+
const hook = renderHook(() => ({
|
|
667
|
+
views: useContextSelector(ParameterContext, ctx => ctx.views),
|
|
668
|
+
disabledViewIndexes: useContextSelector(ParameterContext, ctx => ctx.disabledViewIndexes)
|
|
669
|
+
}), { wrapper: ParameterProviderWrapper });
|
|
670
|
+
expect(hook.result.current.views).toEqual(['disabled_view', 'enabled_view']);
|
|
671
|
+
expect(hook.result.current.disabledViewIndexes).toEqual([0]);
|
|
672
|
+
await waitFor(() => {
|
|
673
|
+
expectSearchRequest({
|
|
674
|
+
query: DEFAULT_QUERY,
|
|
675
|
+
filters: ['-howler.assessment:*', 'event.created:[now-1M TO now]', 'howler.analytic:enabled_view']
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
expect(mockViewContext.getCurrentViews).toHaveBeenCalledWith({ views: ['enabled_view'], ignoreParams: true });
|
|
679
|
+
});
|
|
680
|
+
it('searches with only disabled views and does not inject or resolve a default view', async () => {
|
|
681
|
+
mockViewContext.defaultView = 'default_view';
|
|
682
|
+
mockSearchParams.append('view', 'disabled_view');
|
|
683
|
+
mockSearchParams.append('disabled_view', 'disabled_view');
|
|
684
|
+
mockLocation.search = `?${mockSearchParams.toString()}`;
|
|
685
|
+
makeMockSetParamsUpdateUrl();
|
|
686
|
+
renderHook(() => useContextSelector(RecordSearchContext, ctx => ctx.response), {
|
|
687
|
+
wrapper: ParameterProviderWrapper
|
|
688
|
+
});
|
|
689
|
+
await waitFor(() => {
|
|
690
|
+
expectSearchRequest({ query: DEFAULT_QUERY, filters: ['event.created:[now-1M TO now]'] });
|
|
691
|
+
});
|
|
692
|
+
expect(mockViewContext.getCurrentViews).not.toHaveBeenCalled();
|
|
693
|
+
expect(mockSearchParams.getAll('view')).toEqual(['disabled_view']);
|
|
694
|
+
expect(mockSearchParams.getAll('disabled_view')).toEqual(['disabled_view']);
|
|
695
|
+
});
|
|
696
|
+
it('refreshes the effective search when the last view is disabled and re-enabled', async () => {
|
|
697
|
+
mockSearchParams.append('view', 'first_view');
|
|
698
|
+
mockLocation.search = `?${mockSearchParams.toString()}`;
|
|
699
|
+
makeMockSetParamsUpdateUrl();
|
|
700
|
+
const hook = renderHook(() => ({
|
|
701
|
+
enableView: useContextSelector(ParameterContext, ctx => ctx.enableView),
|
|
702
|
+
disableView: useContextSelector(ParameterContext, ctx => ctx.disableView)
|
|
703
|
+
}), { wrapper: ParameterProviderWrapper });
|
|
704
|
+
await waitFor(() => {
|
|
705
|
+
expectSearchRequest({ filters: expect.arrayContaining(['howler.analytic:first_view']) });
|
|
706
|
+
});
|
|
707
|
+
vi.mocked(hpost).mockClear();
|
|
708
|
+
await act(async () => hook.result.current.disableView(0));
|
|
709
|
+
hook.rerender();
|
|
710
|
+
await waitFor(() => {
|
|
711
|
+
expectSearchRequest({ filters: ['event.created:[now-1M TO now]'] });
|
|
712
|
+
});
|
|
713
|
+
vi.mocked(hpost).mockClear();
|
|
714
|
+
await act(async () => hook.result.current.enableView(0));
|
|
715
|
+
hook.rerender();
|
|
716
|
+
await waitFor(() => {
|
|
717
|
+
expectSearchRequest({ filters: expect.arrayContaining(['howler.analytic:first_view']) });
|
|
718
|
+
});
|
|
719
|
+
expect(mockSearchParams.getAll('view')).toEqual(['first_view']);
|
|
720
|
+
expect(mockSearchParams.getAll('disabled_view')).toEqual([]);
|
|
721
|
+
});
|
|
722
|
+
});
|
|
416
723
|
describe('AND logic for multiple view queries', () => {
|
|
417
724
|
it('should combine two view queries with AND logic', async () => {
|
|
418
725
|
mockParameterContext.views = ['view_1', 'view_2'];
|
|
@@ -14,6 +14,7 @@ interface ChipPopperProps {
|
|
|
14
14
|
placement?: 'bottom-start' | 'bottom-end' | 'bottom';
|
|
15
15
|
onToggle?: (show: boolean) => void;
|
|
16
16
|
onDelete?: (event?: any) => void;
|
|
17
|
+
dimmed?: boolean;
|
|
17
18
|
toggleOnDelete?: boolean;
|
|
18
19
|
disablePortal?: boolean;
|
|
19
20
|
closeOnClick?: boolean;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Chip, ClickAwayListener, Collapse, Paper, Popper } from '@mui/material';
|
|
3
3
|
import { memo, useState } from 'react';
|
|
4
|
-
const ChipPopper = ({ icon, deleteIcon, label, children, minWidth, placement = 'bottom-start', onToggle, onDelete, toggleOnDelete = false, closeOnClick = false, disablePortal = true, slotProps = {} }) => {
|
|
4
|
+
const ChipPopper = ({ icon, deleteIcon, label, children, minWidth, placement = 'bottom-start', onToggle, onDelete, dimmed = false, toggleOnDelete = false, closeOnClick = false, disablePortal = true, slotProps = {} }) => {
|
|
5
5
|
const [show, setShow] = useState(false);
|
|
6
6
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
7
|
+
const { sx: chipSx, ...chipProps } = slotProps.chip ?? {};
|
|
7
8
|
const handleToggle = (newShow) => {
|
|
8
9
|
setShow(newShow);
|
|
9
10
|
onToggle?.(newShow);
|
|
@@ -16,11 +17,12 @@ const ChipPopper = ({ icon, deleteIcon, label, children, minWidth, placement = '
|
|
|
16
17
|
theme => ({
|
|
17
18
|
position: 'relative',
|
|
18
19
|
zIndex: 1,
|
|
19
|
-
transition: theme.transitions.create(['border-bottom-left-radius', 'border-bottom-right-radius'])
|
|
20
|
+
transition: theme.transitions.create(['border-bottom-left-radius', 'border-bottom-right-radius', 'opacity'])
|
|
20
21
|
}),
|
|
21
22
|
show && { borderBottomLeftRadius: '0', borderBottomRightRadius: '0' },
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
dimmed && { opacity: 0.5, '&:hover': { opacity: 1 } },
|
|
24
|
+
...(Array.isArray(chipSx) ? chipSx : [chipSx])
|
|
25
|
+
], ...chipProps }), _jsx(Popper, { placement: placement, anchorEl: anchorEl, disablePortal: disablePortal, open: !!anchorEl, sx: {
|
|
24
26
|
minWidth: Math.max(typeof minWidth === 'number' ? minWidth : parseInt(minWidth?.replace('px', '')) || 0, anchorEl?.clientWidth || 0),
|
|
25
27
|
zIndex: 1000
|
|
26
28
|
}, children: _jsx(Collapse, { in: show, unmountOnExit: true, onClick: () => {
|
|
@@ -178,6 +178,15 @@ describe('ChipPopper', () => {
|
|
|
178
178
|
});
|
|
179
179
|
});
|
|
180
180
|
describe('Styling', () => {
|
|
181
|
+
it('dims disabled chips and restores full opacity on hover', () => {
|
|
182
|
+
const { container } = render(_jsx(ChipPopper, { icon: _jsx(Info, {}), label: "Disabled filter", dimmed: true, children: _jsx("div", { children: "Content" }) }));
|
|
183
|
+
const chip = container.querySelector('.MuiChip-root');
|
|
184
|
+
expect(chip).toHaveStyle({ opacity: '0.5' });
|
|
185
|
+
const generatedStyles = Array.from(document.querySelectorAll('style'))
|
|
186
|
+
.map(style => style.textContent ?? '')
|
|
187
|
+
.join(' ');
|
|
188
|
+
expect(generatedStyles).toMatch(/:hover\{opacity:1/);
|
|
189
|
+
});
|
|
181
190
|
it('should apply border radius transition styles to chip', () => {
|
|
182
191
|
const { container } = render(_jsx(ChipPopper, { icon: _jsx(Info, {}), label: "Test", children: _jsx("div", { children: "Content" }) }));
|
|
183
192
|
const chip = container.querySelector('.MuiChip-root');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createElement as _createElement } from "react";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { ArrowDropDown, Delete, Edit, Language, Lock, OpenInNew, Person, Refresh,
|
|
4
|
-
import { Autocomplete, Chip, CircularProgress, IconButton, Stack, TextField, Tooltip, Typography } from '@mui/material';
|
|
3
|
+
import { ArrowDropDown, Delete, Edit, Language, Lock, OpenInNew, Person, Refresh, SelectAll, Warning } from '@mui/icons-material';
|
|
4
|
+
import { Autocomplete, Checkbox, Chip, CircularProgress, FormControlLabel, IconButton, Stack, TextField, Tooltip, Typography } from '@mui/material';
|
|
5
5
|
import { ParameterContext } from '@cccsaurora/howler-ui/components/app/providers/ParameterProvider';
|
|
6
6
|
import { RecordSearchContext } from '@cccsaurora/howler-ui/components/app/providers/RecordSearchProvider';
|
|
7
7
|
import { ViewContext } from '@cccsaurora/howler-ui/components/app/providers/ViewProvider';
|
|
@@ -18,6 +18,10 @@ const ViewLink = ({ id, viewId }) => {
|
|
|
18
18
|
const sort = useContextSelector(ParameterContext, ctx => ctx.sort);
|
|
19
19
|
const span = useContextSelector(ParameterContext, ctx => ctx.span);
|
|
20
20
|
const currentViews = useContextSelector(ParameterContext, ctx => ctx.views);
|
|
21
|
+
const disabledViewIndexes = useContextSelector(ParameterContext, ctx => ctx.disabledViewIndexes);
|
|
22
|
+
const enableView = useContextSelector(ParameterContext, ctx => ctx.enableView);
|
|
23
|
+
const disableView = useContextSelector(ParameterContext, ctx => ctx.disableView);
|
|
24
|
+
const disabled = disabledViewIndexes?.includes(id) ?? false;
|
|
21
25
|
const removeView = useContextSelector(ParameterContext, ctx => ctx.removeView);
|
|
22
26
|
const setParamView = useContextSelector(ParameterContext, ctx => ctx.setView);
|
|
23
27
|
const search = useContextSelector(RecordSearchContext, ctx => ctx.search);
|
|
@@ -57,10 +61,10 @@ const ViewLink = ({ id, viewId }) => {
|
|
|
57
61
|
if (!view) {
|
|
58
62
|
return (_jsx(Chip, { size: "small", role: "alert", color: "error", "aria-live": "assertive", "aria-atomic": "true", label: t('view.notfound'), onDelete: () => removeView(viewId) }));
|
|
59
63
|
}
|
|
60
|
-
return (_jsx(ChipPopper, { slotProps: { chip: { size: 'small' } }, icon: _jsx(Tooltip, { title: t(`route.views.manager.${view.type}`), children: {
|
|
64
|
+
return (_jsx(ChipPopper, { dimmed: disabled, slotProps: { chip: { size: 'small' } }, icon: _jsx(Tooltip, { title: t(`route.views.manager.${view.type}`), children: {
|
|
61
65
|
readonly: _jsx(Lock, { fontSize: "small", "aria-label": t(`route.views.manager.${view.type}`) }),
|
|
62
66
|
global: _jsx(Language, { fontSize: "small", "aria-label": t(`route.views.manager.${view.type}`) }),
|
|
63
67
|
personal: _jsx(Person, { fontSize: "small", "aria-label": t(`route.views.manager.${view.type}`) })
|
|
64
|
-
}[view.type] ?? _jsx("span", {}) }), label: _jsxs(Stack, { direction: "row", spacing: 0.5, alignItems: "center", children: [_jsx(Tooltip, { title: view.query, children: _jsx(Typography, { role: "link", sx: { color: 'text.primary' }, variant: "body2", component: Link, to: `/views/${view.view_id}/edit`, "aria-label": `${t(view.title)} - ${view.query ?? t('unknown')}`, children: t(view.title) }) }), view.settings?.display === 'grid' && displayType !== 'grid' && (_jsx(Tooltip, { title: t('view.display.grid.inactive_warning'), children: _jsx(Warning, { fontSize: "small", color: "warning" }) }))] }), onDelete: () => removeView(viewId), children: _jsxs(Stack, { direction: "row", spacing: 0.5, alignItems: "center", children: [_jsx(Tooltip, { title:
|
|
68
|
+
}[view.type] ?? _jsx("span", {}) }), label: _jsxs(Stack, { direction: "row", spacing: 0.5, alignItems: "center", children: [_jsx(Tooltip, { title: view.query, children: _jsx(Typography, { role: "link", sx: { color: 'text.primary' }, variant: "body2", component: Link, to: `/views/${view.view_id}/edit`, "aria-label": `${t(view.title)} - ${view.query ?? t('unknown')}`, children: t(view.title) }) }), view.settings?.display === 'grid' && displayType !== 'grid' && (_jsx(Tooltip, { title: t('view.display.grid.inactive_warning'), children: _jsx(Warning, { fontSize: "small", color: "warning" }) }))] }), onDelete: () => removeView(viewId), children: _jsxs(Stack, { spacing: 1, children: [_jsx(FormControlLabel, { label: t('hit.search.view.disable'), control: _jsx(Checkbox, { size: "small", checked: disabled, onChange: (_event, checked) => (checked ? disableView : enableView)(id) }) }), _jsxs(Stack, { direction: "row", spacing: 0.5, alignItems: "center", children: [_jsx(Tooltip, { title: t('route.views.edit'), children: _jsx(IconButton, { "aria-label": t('route.views.edit'), size: "small", component: Link, disabled: span?.endsWith('custom'), to: viewUrl, role: "link", children: _jsx(Edit, { fontSize: "small" }) }) }), _jsx(Tooltip, { title: t('view.refresh'), children: _jsx(IconButton, { size: "small", onClick: () => search(query), "aria-label": t('view.refresh'), children: _jsx(Refresh, { fontSize: "small" }) }) }), _jsx(Tooltip, { title: t('view.open'), children: _jsx(IconButton, { size: "small", component: Link, to: `/search?query=${view.query}`, "aria-label": t('view.open'), role: "link", children: _jsx(OpenInNew, { fontSize: "small" }) }) })] })] }) }));
|
|
65
69
|
};
|
|
66
70
|
export default memo(ViewLink);
|
|
@@ -20,10 +20,13 @@ let mockParameterContext = {
|
|
|
20
20
|
sort: 'event.created desc',
|
|
21
21
|
span: 'date.range.1.month',
|
|
22
22
|
views: ['test-view-id'],
|
|
23
|
+
disabledViewIndexes: [],
|
|
23
24
|
setQuery: vi.fn(),
|
|
24
25
|
setSort: vi.fn(),
|
|
25
26
|
setSpan: vi.fn(),
|
|
26
27
|
removeView: vi.fn(),
|
|
28
|
+
enableView: vi.fn(),
|
|
29
|
+
disableView: vi.fn(),
|
|
27
30
|
setView: vi.fn()
|
|
28
31
|
};
|
|
29
32
|
let mockRecordSearchContext = {
|
|
@@ -50,7 +53,10 @@ describe('ViewLink', () => {
|
|
|
50
53
|
mockParameterContext.sort = 'event.created desc';
|
|
51
54
|
mockParameterContext.span = 'date.range.1.month';
|
|
52
55
|
mockParameterContext.views = ['test-view-id'];
|
|
56
|
+
mockParameterContext.disabledViewIndexes = [];
|
|
53
57
|
mockParameterContext.removeView = vi.fn();
|
|
58
|
+
mockParameterContext.enableView = vi.fn();
|
|
59
|
+
mockParameterContext.disableView = vi.fn();
|
|
54
60
|
mockParameterContext.setView = vi.fn();
|
|
55
61
|
mockRecordSearchContext.search = vi.fn();
|
|
56
62
|
mockViewContext.getCurrentViews = vi.fn().mockResolvedValue([createMockView()]);
|
|
@@ -64,6 +70,7 @@ describe('ViewLink', () => {
|
|
|
64
70
|
mockViewContext.getCurrentViews = vi.fn(() => new Promise(() => { })); // Never resolves
|
|
65
71
|
render(_jsx(ViewLink, { id: 0, viewId: "test-view-id" }), { wrapper: Wrapper });
|
|
66
72
|
expect(screen.getByRole('progressbar')).toBeInTheDocument();
|
|
73
|
+
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
|
|
67
74
|
});
|
|
68
75
|
it('should hide loading spinner after view is fetched', async () => {
|
|
69
76
|
mockViewContext.getCurrentViews = vi.fn().mockResolvedValue([createMockView()]);
|
|
@@ -82,6 +89,7 @@ describe('ViewLink', () => {
|
|
|
82
89
|
await user.click(await screen.findByText(i18n.t('hit.search.view.select')));
|
|
83
90
|
const autocomplete = screen.getByRole('combobox');
|
|
84
91
|
expect(autocomplete).toBeInTheDocument();
|
|
92
|
+
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
|
|
85
93
|
});
|
|
86
94
|
it('should filter out views already in currentViews', async () => {
|
|
87
95
|
mockParameterContext.views = ['test-view-id']; // Already selected
|
|
@@ -126,6 +134,7 @@ describe('ViewLink', () => {
|
|
|
126
134
|
render(_jsx(ViewLink, { id: 0, viewId: "non-existent-view" }), { wrapper: Wrapper });
|
|
127
135
|
expect(await screen.findByRole('alert')).toBeInTheDocument();
|
|
128
136
|
expect(screen.getByText(i18n.t('view.notfound'))).toBeInTheDocument();
|
|
137
|
+
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
|
|
129
138
|
});
|
|
130
139
|
it('should have proper accessibility attributes on error alert', async () => {
|
|
131
140
|
mockViewContext.getCurrentViews = vi.fn().mockResolvedValue([]);
|
|
@@ -199,6 +208,80 @@ describe('ViewLink', () => {
|
|
|
199
208
|
}
|
|
200
209
|
});
|
|
201
210
|
});
|
|
211
|
+
describe('Temporary disabling', () => {
|
|
212
|
+
it('disables and re-enables the selected entry without editing or removing it', async () => {
|
|
213
|
+
mockParameterContext.views = ['another-view-id', 'test-view-id'];
|
|
214
|
+
mockParameterContext.disableView.mockImplementation(index => {
|
|
215
|
+
mockParameterContext = { ...mockParameterContext, disabledViewIndexes: [index] };
|
|
216
|
+
});
|
|
217
|
+
mockParameterContext.enableView.mockImplementation(() => {
|
|
218
|
+
mockParameterContext = { ...mockParameterContext, disabledViewIndexes: [] };
|
|
219
|
+
});
|
|
220
|
+
const { rerender } = render(_jsx(ViewLink, { id: 1, viewId: "test-view-id" }), { wrapper: Wrapper });
|
|
221
|
+
const title = await screen.findByText('Test View');
|
|
222
|
+
await user.click(title.parentElement);
|
|
223
|
+
const checkbox = screen.getByRole('checkbox', { name: i18n.t('hit.search.view.disable') });
|
|
224
|
+
expect(checkbox).not.toBeChecked();
|
|
225
|
+
await user.click(checkbox);
|
|
226
|
+
expect(mockParameterContext.disableView).toHaveBeenCalledExactlyOnceWith(1);
|
|
227
|
+
rerender(_jsx(ViewLink, { id: 1, viewId: "test-view-id" }));
|
|
228
|
+
expect(screen.getByRole('checkbox', { name: i18n.t('hit.search.view.disable') })).toBeChecked();
|
|
229
|
+
expect(title.closest('.MuiChip-root')).toHaveStyle({ opacity: 0.5 });
|
|
230
|
+
await user.click(screen.getByRole('checkbox', { name: i18n.t('hit.search.view.disable') }));
|
|
231
|
+
expect(mockParameterContext.enableView).toHaveBeenCalledExactlyOnceWith(1);
|
|
232
|
+
rerender(_jsx(ViewLink, { id: 1, viewId: "test-view-id" }));
|
|
233
|
+
expect(screen.getByRole('checkbox', { name: i18n.t('hit.search.view.disable') })).not.toBeChecked();
|
|
234
|
+
expect(title.closest('.MuiChip-root')).not.toHaveStyle({ opacity: 0.5 });
|
|
235
|
+
expect(mockParameterContext.views).toEqual(['another-view-id', 'test-view-id']);
|
|
236
|
+
expect(mockParameterContext.setView).not.toHaveBeenCalled();
|
|
237
|
+
expect(mockParameterContext.removeView).not.toHaveBeenCalled();
|
|
238
|
+
expect(mockViewContext.getCurrentViews).toHaveBeenCalledTimes(1);
|
|
239
|
+
});
|
|
240
|
+
it('shows restored disabled state and keeps view actions available', async () => {
|
|
241
|
+
mockParameterContext.disabledViewIndexes = [0];
|
|
242
|
+
render(_jsx(ViewLink, { id: 0, viewId: "test-view-id" }), { wrapper: Wrapper });
|
|
243
|
+
const title = await screen.findByText('Test View');
|
|
244
|
+
expect(title.closest('.MuiChip-root')).toHaveStyle({ opacity: 0.5 });
|
|
245
|
+
await user.click(title.parentElement);
|
|
246
|
+
expect(screen.getByRole('checkbox', { name: i18n.t('hit.search.view.disable') })).toBeChecked();
|
|
247
|
+
expect(screen.getByLabelText(i18n.t('route.views.edit'))).toHaveAttribute('href', '/views/test-view-id/edit');
|
|
248
|
+
expect(screen.getByLabelText(i18n.t('view.open'))).toHaveAttribute('href', '/search?query=howler.status:open');
|
|
249
|
+
await user.click(screen.getByLabelText(i18n.t('view.refresh')));
|
|
250
|
+
expect(mockRecordSearchContext.search).toHaveBeenCalledWith('howler.id:*');
|
|
251
|
+
});
|
|
252
|
+
it('uses the updated entry position when re-enabling after another view is removed', async () => {
|
|
253
|
+
mockParameterContext.views = ['another-view-id', 'test-view-id'];
|
|
254
|
+
mockParameterContext.disabledViewIndexes = [1];
|
|
255
|
+
const { rerender } = render(_jsx(ViewLink, { id: 1, viewId: "test-view-id" }), { wrapper: Wrapper });
|
|
256
|
+
await user.click((await screen.findByText('Test View')).parentElement);
|
|
257
|
+
expect(screen.getByRole('checkbox', { name: i18n.t('hit.search.view.disable') })).toBeChecked();
|
|
258
|
+
mockParameterContext = { ...mockParameterContext, views: ['test-view-id'], disabledViewIndexes: [0] };
|
|
259
|
+
rerender(_jsx(ViewLink, { id: 0, viewId: "test-view-id" }));
|
|
260
|
+
await user.click(screen.getByRole('checkbox', { name: i18n.t('hit.search.view.disable') }));
|
|
261
|
+
expect(mockParameterContext.enableView).toHaveBeenCalledExactlyOnceWith(0);
|
|
262
|
+
expect(mockParameterContext.disableView).not.toHaveBeenCalled();
|
|
263
|
+
});
|
|
264
|
+
it('allows keyboard interaction with the labeled disable checkbox', async () => {
|
|
265
|
+
render(_jsx(ViewLink, { id: 0, viewId: "test-view-id" }), { wrapper: Wrapper });
|
|
266
|
+
await user.click((await screen.findByText('Test View')).parentElement);
|
|
267
|
+
const checkbox = screen.getByRole('checkbox', { name: i18n.t('hit.search.view.disable') });
|
|
268
|
+
checkbox.focus();
|
|
269
|
+
await user.keyboard(' ');
|
|
270
|
+
expect(mockParameterContext.disableView).toHaveBeenCalledExactlyOnceWith(0);
|
|
271
|
+
expect(mockParameterContext.removeView).not.toHaveBeenCalled();
|
|
272
|
+
});
|
|
273
|
+
it('keeps disabled views removable from their chip', async () => {
|
|
274
|
+
mockParameterContext.disabledViewIndexes = [0];
|
|
275
|
+
render(_jsx(ViewLink, { id: 0, viewId: "test-view-id" }), { wrapper: Wrapper });
|
|
276
|
+
const chip = (await screen.findByText('Test View')).closest('.MuiChip-root');
|
|
277
|
+
const deleteIcon = chip.querySelector('.MuiChip-deleteIcon');
|
|
278
|
+
expect(deleteIcon).not.toBeNull();
|
|
279
|
+
await user.click(deleteIcon);
|
|
280
|
+
expect(mockParameterContext.removeView).toHaveBeenCalledExactlyOnceWith('test-view-id');
|
|
281
|
+
expect(mockParameterContext.enableView).not.toHaveBeenCalled();
|
|
282
|
+
expect(mockParameterContext.disableView).not.toHaveBeenCalled();
|
|
283
|
+
});
|
|
284
|
+
});
|
|
202
285
|
describe('Action Buttons', () => {
|
|
203
286
|
beforeEach(async () => {
|
|
204
287
|
mockViewContext.getCurrentViews = vi.fn().mockResolvedValue([createMockView()]);
|
|
@@ -88,6 +88,10 @@ const HitFilter = ({ size, id, value }) => {
|
|
|
88
88
|
const { dispatchApi } = useMyApi();
|
|
89
89
|
const setSavedFilter = useContextSelector(ParameterContext, ctx => ctx.setFilter);
|
|
90
90
|
const removeSavedFilter = useContextSelector(ParameterContext, ctx => ctx.removeFilter);
|
|
91
|
+
const disabledFilterIndexes = useContextSelector(ParameterContext, ctx => ctx.disabledFilterIndexes);
|
|
92
|
+
const enableFilter = useContextSelector(ParameterContext, ctx => ctx.enableFilter);
|
|
93
|
+
const disableFilter = useContextSelector(ParameterContext, ctx => ctx.disableFilter);
|
|
94
|
+
const disabled = disabledFilterIndexes?.includes(id) ?? false;
|
|
91
95
|
const [parsedFilter, setParsedFilter] = useState(() => parseFilter(value));
|
|
92
96
|
const [previousValue, setPreviousValue] = useState(value);
|
|
93
97
|
// Synchronize external replacements without resetting edits when only lookup config changes.
|
|
@@ -157,7 +161,7 @@ const HitFilter = ({ size, id, value }) => {
|
|
|
157
161
|
}, [commitFilter, parsedFilter.raw]);
|
|
158
162
|
const lookupOptions = configuredLookup ?? (customLookups.category === category ? customLookups.options : []);
|
|
159
163
|
const chipLabel = `${parsedFilter.category ? `${parsedFilter.category}:` : ''}${parsedFilter.rawClause}`;
|
|
160
|
-
return (_jsx(Stack, { direction: "row", alignItems: "center", spacing: 0.5, children: _jsx(ChipPopper, { icon: _jsxs(Stack, { direction: "row", spacing: 0.25, alignItems: "center", children: [_jsx(FilterList, { fontSize: "small" }), parsedFilter.negated ? (_jsx(Tooltip, { title: t('hit.search.filter.excluded'), children: _jsx(RemoveCircleOutline, { fontSize: "small", color: "error" }) })) : (_jsx(Tooltip, { title: t('hit.search.filter.included'), children: _jsx(AddCircleOutline, { fontSize: "small", color: "success" }) }))] }), label: _jsx(Typography, { variant: "body2", children: chipLabel }), minWidth: "250px", onDelete: () => removeSavedFilter(value), slotProps: { chip: { size: 'small', color: parsedFilter.wildcard ? 'warning' : 'default' } }, children: _jsxs(Stack, { spacing: 1, sx: { minWidth: '225px' }, children: [_jsx(FormControlLabel, { label: t('hit.search.filter.exclude'), control: _jsx(Checkbox, { size: "small", checked: negated, onChange: toggleNegation }) }), _jsx(Autocomplete, { fullWidth: true, disableClearable: true, disabled: !editable, size: size ?? 'small', value: category ?? ACCEPTED_LOOKUPS[0], options: categoryOptions, filterOptions: (options, state) => categorySearchInput
|
|
164
|
+
return (_jsx(Stack, { direction: "row", alignItems: "center", spacing: 0.5, children: _jsx(ChipPopper, { dimmed: disabled, icon: _jsxs(Stack, { direction: "row", spacing: 0.25, alignItems: "center", children: [_jsx(FilterList, { fontSize: "small" }), parsedFilter.negated ? (_jsx(Tooltip, { title: t('hit.search.filter.excluded'), children: _jsx(RemoveCircleOutline, { fontSize: "small", color: "error" }) })) : (_jsx(Tooltip, { title: t('hit.search.filter.included'), children: _jsx(AddCircleOutline, { fontSize: "small", color: "success" }) }))] }), label: _jsx(Typography, { variant: "body2", children: chipLabel }), minWidth: "250px", onDelete: () => removeSavedFilter(value), slotProps: { chip: { size: 'small', color: parsedFilter.wildcard ? 'warning' : 'default' } }, children: _jsxs(Stack, { spacing: 1, sx: { minWidth: '225px' }, children: [_jsx(FormControlLabel, { label: t('hit.search.filter.disable'), control: _jsx(Checkbox, { size: "small", checked: disabled, onChange: (_event, checked) => (checked ? disableFilter : enableFilter)(id) }) }), _jsx(FormControlLabel, { label: t('hit.search.filter.exclude'), control: _jsx(Checkbox, { size: "small", checked: negated, onChange: toggleNegation }) }), _jsx(Autocomplete, { fullWidth: true, disableClearable: true, disabled: !editable, size: size ?? 'small', value: category ?? ACCEPTED_LOOKUPS[0], options: categoryOptions, filterOptions: (options, state) => categorySearchInput
|
|
161
165
|
? filterFields(options, { ...state, inputValue: categorySearchInput })
|
|
162
166
|
: options.filter(option => DEFAULT_FILTER_FIELDS.includes(option)), renderInput: _params => _jsx(TextField, { ..._params, label: t('hit.search.filter.fields') }), onChange: onCategoryChange, onInputChange: (_event, inputValue, reason) => setCategorySearchInput(reason === 'input' ? inputValue : '') }), _jsx(Autocomplete, { fullWidth: true, freeSolo: true, multiple: true, disabled: !category || !editable, loading: loading, size: size ?? 'small', value: filterValues, options: lookupOptions, renderInput: _params => _jsx(TextField, { ..._params, label: t('hit.search.filter.values') }), getOptionLabel: option => t(option), onChange: onValuesChange })] }) }) }));
|
|
163
167
|
};
|