@cccsaurora/howler-ui 2.19.0-cases.1110 → 2.19.0-cases.1122

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.
Files changed (36) hide show
  1. package/api/v2/fuzzy.d.ts +17 -0
  2. package/api/v2/fuzzy.js +11 -0
  3. package/api/v2/index.d.ts +2 -1
  4. package/api/v2/index.js +2 -1
  5. package/components/app/App.js +9 -4
  6. package/components/app/providers/ParameterProvider.d.ts +16 -1
  7. package/components/app/providers/ParameterProvider.js +23 -22
  8. package/components/app/providers/ParameterProvider.test.js +12 -0
  9. package/components/elements/addons/search/SearchTotal.js +1 -1
  10. package/components/elements/addons/search/SearchTotal.test.js +2 -2
  11. package/components/elements/search/FuzzySearchBar.d.ts +7 -0
  12. package/components/elements/search/FuzzySearchBar.js +33 -0
  13. package/components/elements/search/FuzzySearchBar.test.js +87 -0
  14. package/components/routes/cases/detail/{CaseAssets.d.ts → CaseObservables.d.ts} +2 -2
  15. package/components/routes/cases/detail/{CaseAssets.js → CaseObservables.js} +18 -18
  16. package/components/routes/cases/detail/{CaseAssets.test.js → CaseObservables.test.js} +34 -34
  17. package/components/routes/cases/detail/CaseSearch.d.ts +3 -0
  18. package/components/routes/cases/detail/CaseSearch.js +78 -0
  19. package/components/routes/cases/detail/CaseSidebar.js +2 -2
  20. package/components/routes/cases/detail/CaseSidebar.test.js +3 -3
  21. package/components/routes/cases/detail/observables/Observable.d.ts +14 -0
  22. package/components/routes/cases/detail/{assets/Asset.js → observables/Observable.js} +3 -3
  23. package/components/routes/cases/detail/observables/Observable.test.d.ts +1 -0
  24. package/components/routes/cases/detail/{assets/Asset.test.js → observables/Observable.test.js} +13 -13
  25. package/components/routes/cases/detail/sidebar/CaseFolder.test.js +1 -0
  26. package/components/routes/cases/detail/sidebar/CaseFolderContextMenu.test.js +3 -2
  27. package/components/routes/hits/search/shared/IndexPicker.d.ts +7 -1
  28. package/components/routes/hits/search/shared/IndexPicker.js +4 -3
  29. package/locales/en/translation.json +27 -18
  30. package/locales/fr/translation.json +27 -18
  31. package/models/entities/generated/Case.d.ts +1 -0
  32. package/package.json +3 -2
  33. package/tests/utils.js +1 -0
  34. package/components/routes/cases/detail/assets/Asset.d.ts +0 -14
  35. /package/components/{routes/cases/detail/CaseAssets.test.d.ts → elements/search/FuzzySearchBar.test.d.ts} +0 -0
  36. /package/components/routes/cases/detail/{assets/Asset.test.d.ts → CaseObservables.test.d.ts} +0 -0
@@ -0,0 +1,17 @@
1
+ import type { HowlerSearchResponse } from '@cccsaurora/howler-ui/api/search';
2
+ import type { Case } from '@cccsaurora/howler-ui/models/entities/generated/Case';
3
+ import type { Event } from '@cccsaurora/howler-ui/models/entities/generated/Event';
4
+ import type { Hit } from '@cccsaurora/howler-ui/models/entities/generated/Hit';
5
+ export type FuzzySearchRequest = {
6
+ query: string;
7
+ indexes?: string[];
8
+ filters?: string[];
9
+ offset?: number;
10
+ rows?: number;
11
+ track_total_hits?: boolean;
12
+ };
13
+ export type FuzzySearchItem<T = Hit | Event | Case> = T & {
14
+ _score: number;
15
+ };
16
+ export declare const uri: () => string;
17
+ export declare const post: (request: FuzzySearchRequest) => Promise<HowlerSearchResponse<FuzzySearchItem>>;
@@ -0,0 +1,11 @@
1
+ import { hpost, joinAllUri } from '@cccsaurora/howler-ui/api';
2
+ import { uri as parentUri } from '@cccsaurora/howler-ui/api/v2';
3
+ export const uri = () => {
4
+ return joinAllUri(parentUri(), 'fuzzy');
5
+ };
6
+ export const post = (request) => {
7
+ if (!request.query || !request.query.trim()) {
8
+ throw new Error('Search query is required.');
9
+ }
10
+ return hpost(joinAllUri(uri(), 'search'), request);
11
+ };
package/api/v2/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as case_ from '@cccsaurora/howler-ui/api/v2/case';
2
+ import * as fuzzy from '@cccsaurora/howler-ui/api/v2/fuzzy';
2
3
  import * as search from '@cccsaurora/howler-ui/api/v2/search';
3
4
  export declare const uri: () => string;
4
- export { case_ as case, search };
5
+ export { case_ as case, fuzzy, search };
package/api/v2/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as case_ from '@cccsaurora/howler-ui/api/v2/case';
2
+ import * as fuzzy from '@cccsaurora/howler-ui/api/v2/fuzzy';
2
3
  import * as search from '@cccsaurora/howler-ui/api/v2/search';
3
4
  export const uri = () => {
4
5
  return '/api/v2';
5
6
  };
6
- export { case_ as case, search };
7
+ export { case_ as case, fuzzy, search };
@@ -28,9 +28,10 @@ import AnalyticDetails from '@cccsaurora/howler-ui/components/routes/analytics/A
28
28
  import AnalyticSearch from '@cccsaurora/howler-ui/components/routes/analytics/AnalyticSearch';
29
29
  import CaseViewer from '@cccsaurora/howler-ui/components/routes/cases/CaseViewer';
30
30
  import Cases from '@cccsaurora/howler-ui/components/routes/cases/Cases';
31
- import CaseAssets from '@cccsaurora/howler-ui/components/routes/cases/detail/CaseAssets';
32
31
  import CaseDashboard from '@cccsaurora/howler-ui/components/routes/cases/detail/CaseDashboard';
32
+ import CaseObservables from '@cccsaurora/howler-ui/components/routes/cases/detail/CaseObservables';
33
33
  import CaseRules from '@cccsaurora/howler-ui/components/routes/cases/detail/CaseRules';
34
+ import CaseSearch from '@cccsaurora/howler-ui/components/routes/cases/detail/CaseSearch';
34
35
  import CaseTimeline from '@cccsaurora/howler-ui/components/routes/cases/detail/CaseTimeline';
35
36
  import ItemPage from '@cccsaurora/howler-ui/components/routes/cases/detail/ItemPage';
36
37
  import DossierEditor from '@cccsaurora/howler-ui/components/routes/dossiers/DossierEditor';
@@ -207,15 +208,15 @@ const createRouter = () => createBrowserRouter([
207
208
  },
208
209
  {
209
210
  path: 'cases/:id',
210
- element: (_jsx(ParameterProvider, { children: _jsx(CaseViewer, {}) })),
211
+ element: (_jsx(ParameterProvider, { defaults: { query: '', indexes: ['hit', 'event', 'case'] }, children: _jsx(CaseViewer, {}) })),
211
212
  children: [
212
213
  {
213
214
  index: true,
214
215
  element: _jsx(CaseDashboard, {})
215
216
  },
216
217
  {
217
- path: 'assets',
218
- element: _jsx(CaseAssets, {})
218
+ path: 'observables',
219
+ element: _jsx(CaseObservables, {})
219
220
  },
220
221
  {
221
222
  path: 'timeline',
@@ -225,6 +226,10 @@ const createRouter = () => createBrowserRouter([
225
226
  path: 'rules',
226
227
  element: _jsx(CaseRules, {})
227
228
  },
229
+ {
230
+ path: 'search',
231
+ element: _jsx(CaseSearch, {})
232
+ },
228
233
  {
229
234
  path: '*',
230
235
  element: _jsx(ItemPage, {})
@@ -32,10 +32,25 @@ export interface ParameterContextType {
32
32
  setView: (index: number, view: string) => void;
33
33
  resetViews: () => void;
34
34
  }
35
+ interface SearchValues {
36
+ selected: string;
37
+ query: string;
38
+ sort: string;
39
+ span: string;
40
+ indexes: SearchIndex[];
41
+ filters: string[];
42
+ views: string[];
43
+ startDate: string;
44
+ endDate: string;
45
+ offset: number;
46
+ trackTotalHits: boolean;
47
+ }
35
48
  export declare const ParameterContext: import("use-context-selector").Context<ParameterContextType>;
36
49
  /**
37
50
  * Context responsible for tracking updates to query operations in hit and view search.
38
51
  */
39
- declare const ParameterProvider: FC<PropsWithChildren>;
52
+ declare const ParameterProvider: FC<PropsWithChildren<{
53
+ defaults?: Partial<SearchValues>;
54
+ }>>;
40
55
  export declare const useParameterContextSelector: <Selected>(selector: (value: ParameterContextType) => Selected) => Selected;
41
56
  export default ParameterProvider;
@@ -24,7 +24,7 @@ const PARAM_MAPPINGS = [
24
24
  const ARRAY_PARAMS = [
25
25
  { urlKey: 'filter', stateKey: 'filters' },
26
26
  { urlKey: 'view', stateKey: 'views' },
27
- { urlKey: 'index', stateKey: 'indexes', default: DEFAULT_VALUES.indexes }
27
+ { urlKey: 'index', stateKey: 'indexes' }
28
28
  ];
29
29
  const ARRAY_URL_KEYS = new Set(ARRAY_PARAMS.map(p => p.urlKey));
30
30
  const WRITE_THROTTLER = new Throttler(100);
@@ -85,7 +85,7 @@ const useListHandlers = (key, _setValues) => {
85
85
  /**
86
86
  * Synchronizes SearchValues state with the URL search string, and vice-versa.
87
87
  */
88
- const useUrlSync = (values, _setValues, params, setParams, pathname, search, routeId) => {
88
+ const useUrlSync = (values, defaults, _setValues, params, setParams, pathname, search, routeId) => {
89
89
  const getUrlFromState = useCallback(() => {
90
90
  const changes = {};
91
91
  // Scalar params: write if changed from URL, remove if back to default
@@ -94,20 +94,21 @@ const useUrlSync = (values, _setValues, params, setParams, pathname, search, rou
94
94
  const urlValue = params.get(urlKey);
95
95
  if (stateValue === urlValue)
96
96
  return;
97
- if (params.has(urlKey) && stateValue === DEFAULT_VALUES[stateKey]) {
97
+ if (params.has(urlKey) && stateValue === defaults[stateKey]) {
98
98
  changes[urlKey] = null; // remove
99
99
  }
100
- else if (stateValue !== DEFAULT_VALUES[stateKey]) {
100
+ else if (stateValue !== defaults[stateKey]) {
101
101
  changes[urlKey] = stateValue; // write
102
102
  }
103
103
  });
104
104
  // Array params: skip when state equals default and URL is already empty
105
- ARRAY_PARAMS.forEach(({ urlKey, stateKey, default: def }) => {
105
+ ARRAY_PARAMS.forEach(({ urlKey, stateKey }) => {
106
106
  const stateArr = values[stateKey];
107
107
  const urlArr = params.getAll(urlKey);
108
+ const defaultValue = stateKey === 'indexes' ? defaults.indexes : undefined;
108
109
  if (isEqual(stateArr, urlArr))
109
110
  return;
110
- const isDefault = def ? isEqual(stateArr, def) : stateArr.length === 0;
111
+ const isDefault = defaultValue ? isEqual(stateArr, defaultValue) : stateArr.length === 0;
111
112
  if (!isDefault) {
112
113
  changes[urlKey] = stateArr.length === 0 ? null : stateArr;
113
114
  }
@@ -128,20 +129,21 @@ const useUrlSync = (values, _setValues, params, setParams, pathname, search, rou
128
129
  }
129
130
  // Drop scalar entries that already match the URL
130
131
  return omitBy(changes, (val, key) => !ARRAY_URL_KEYS.has(key) && val == params.get(key));
131
- }, [values, params, pathname]);
132
+ }, [values, defaults, params, pathname]);
132
133
  const getStateFromUrl = useCallback(() => {
133
134
  const changes = {};
134
135
  // Scalar params: fall back to default when absent from URL
135
136
  PARAM_MAPPINGS.forEach(([urlKey, stateKey]) => {
136
- const urlValue = params.has(urlKey) ? params.get(urlKey) : (DEFAULT_VALUES[stateKey] ?? undefined);
137
+ const urlValue = params.has(urlKey) ? params.get(urlKey) : (defaults[stateKey] ?? undefined);
137
138
  if (urlValue !== values[stateKey]) {
138
139
  changes[stateKey] = urlValue;
139
140
  }
140
141
  });
141
142
  // Array params: fall back to their declared default when absent from URL
142
- ARRAY_PARAMS.forEach(({ urlKey, stateKey, default: def }) => {
143
+ ARRAY_PARAMS.forEach(({ urlKey, stateKey }) => {
143
144
  const raw = params.getAll(urlKey);
144
- const resolved = (isEmpty(raw) && def ? def : uniq(raw));
145
+ const defaultValue = stateKey === 'indexes' ? defaults.indexes : undefined;
146
+ const resolved = (isEmpty(raw) && defaultValue ? defaultValue : uniq(raw));
145
147
  if (!isEqual(resolved, values[stateKey])) {
146
148
  changes[stateKey] = resolved;
147
149
  }
@@ -155,7 +157,7 @@ const useUrlSync = (values, _setValues, params, setParams, pathname, search, rou
155
157
  if (urlOffset !== values.offset)
156
158
  changes.offset = urlOffset;
157
159
  return omitBy(omitBy(changes, isUndefined), (val, key) => val == values[key]);
158
- }, [values, params, pathname, routeId]);
160
+ }, [values, defaults, params, pathname, routeId]);
159
161
  // State → URL
160
162
  useEffect(() => {
161
163
  const changes = getUrlFromState();
@@ -191,19 +193,18 @@ const useUrlSync = (values, _setValues, params, setParams, pathname, search, rou
191
193
  /**
192
194
  * Context responsible for tracking updates to query operations in hit and view search.
193
195
  */
194
- const ParameterProvider = ({ children }) => {
196
+ const ParameterProvider = ({ children, defaults: _defaults = {} }) => {
195
197
  const location = useLocation();
196
198
  const routeParams = useParams();
197
199
  const [params, setParams] = useSearchParams();
200
+ const defaults = useMemo(() => ({ ...DEFAULT_VALUES, ..._defaults }), [_defaults]);
198
201
  const pendingChanges = useRef({});
199
202
  const [values, _setValues] = useState({
200
203
  selected: getSelectedValue(params, location.pathname, routeParams.id),
201
- query: params.get('query') ?? DEFAULT_VALUES.query,
202
- sort: params.get('sort') ?? DEFAULT_VALUES.sort,
203
- span: params.get('span') ?? DEFAULT_VALUES.span,
204
- indexes: params.has('index')
205
- ? uniq(params.getAll('index')).filter(identity)
206
- : DEFAULT_VALUES.indexes,
204
+ query: params.get('query') ?? defaults.query,
205
+ sort: params.get('sort') ?? defaults.sort,
206
+ span: params.get('span') ?? defaults.span,
207
+ indexes: params.has('index') ? uniq(params.getAll('index')).filter(identity) : defaults.indexes,
207
208
  filters: params.getAll('filter'),
208
209
  views: params.getAll('view'),
209
210
  startDate: params.get('start_date'),
@@ -212,7 +213,7 @@ const ParameterProvider = ({ children }) => {
212
213
  trackTotalHits: (params.get('track_total_hits') ?? 'false') !== 'false'
213
214
  });
214
215
  // TODO: SELECTING A BUNDLE STILL CAUSES A FREAKOUT
215
- useUrlSync(values, _setValues, params, setParams, location.pathname, location.search, routeParams.id);
216
+ useUrlSync(values, defaults, _setValues, params, setParams, location.pathname, location.search, routeParams.id);
216
217
  const set = useCallback((key) => (value) => {
217
218
  if (value === values[key])
218
219
  return;
@@ -220,7 +221,7 @@ const ParameterProvider = ({ children }) => {
220
221
  pendingChanges.current.selected = value;
221
222
  }
222
223
  else {
223
- pendingChanges.current[key] = value ?? DEFAULT_VALUES[key] ?? null;
224
+ pendingChanges.current[key] = value ?? defaults[key] ?? null;
224
225
  }
225
226
  if (key === 'span' && typeof value === 'string' && !value.endsWith('custom')) {
226
227
  pendingChanges.current.startDate = null;
@@ -230,7 +231,7 @@ const ParameterProvider = ({ children }) => {
230
231
  _setValues(c => ({ ...c, ...pendingChanges.current }));
231
232
  pendingChanges.current = {};
232
233
  });
233
- }, [values]);
234
+ }, [values, defaults]);
234
235
  const setOffset = useCallback((_offset) => _setValues(c => ({ ...c, offset: parseOffset(_offset) })), []);
235
236
  const setCustomSpan = useCallback((startDate, endDate) => _setValues(c => ({ ...c, startDate, endDate })), []);
236
237
  const filters = useListHandlers('filters', _setValues);
@@ -252,7 +253,7 @@ const ParameterProvider = ({ children }) => {
252
253
  removeIndex: indexes.remove,
253
254
  setIndex: indexes.setAt,
254
255
  setIndexes: indexes.setAll,
255
- resetIndexes: useCallback(() => indexes.reset(DEFAULT_VALUES.indexes), [indexes]),
256
+ resetIndexes: useCallback(() => indexes.reset(defaults.indexes), [indexes, defaults]),
256
257
  addView: views.add,
257
258
  removeView: views.remove,
258
259
  setView: views.setAt,
@@ -579,6 +579,18 @@ describe('ParameterContext', () => {
579
579
  const hook = renderHook(() => useContextSelector(ParameterContext, ctx => ctx.selected), { wrapper: Wrapper });
580
580
  expect(hook.result.current).toBe('different_hit_id');
581
581
  });
582
+ it('should not sync query when default query differs from global default', async () => {
583
+ const CustomDefaultWrapper = ({ children }) => {
584
+ return _jsx(ParameterProvider, { defaults: { query: '' }, children: children });
585
+ };
586
+ const hook = renderHook(() => useContextSelector(ParameterContext, ctx => ctx.query), {
587
+ wrapper: CustomDefaultWrapper
588
+ });
589
+ expect(hook.result.current).toBe('');
590
+ await waitFor(() => {
591
+ expect(mockSetParams).not.toHaveBeenCalled();
592
+ });
593
+ });
582
594
  });
583
595
  describe('useParameterContextSelector', () => {
584
596
  it('should allow selecting specific values from context', async () => {
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Typography } from '@mui/material';
3
3
  import { Trans } from 'react-i18next';
4
4
  const SearchTotal = ({ total, offset, pageLength, ...typographyProps }) => {
5
- return (_jsx(Typography, { ...typographyProps, children: total <= 1 ? (_jsx(Trans, { i18nKey: "search.result.showing.single", values: {
5
+ return (_jsx(Typography, { ...typographyProps, children: total < 1 ? (_jsx(Trans, { i18nKey: "search.result.showing.single", values: {
6
6
  total: total
7
7
  } })) : (_jsx(Trans, { i18nKey: "search.result.showing", values: {
8
8
  total: total,
@@ -15,9 +15,9 @@ describe('SearchTotal', () => {
15
15
  render(_jsx(SearchTotal, { total: 0, offset: 0, pageLength: 0 }), { wrapper: Wrapper });
16
16
  expect(screen.getByText('No results')).toBeInTheDocument();
17
17
  });
18
- it('renders "No results" text when total is 1', () => {
18
+ it('renders "Showing 1 to 1 of 1 results" text when total is 1', () => {
19
19
  render(_jsx(SearchTotal, { total: 1, offset: 0, pageLength: 1 }), { wrapper: Wrapper });
20
- expect(screen.getByText('No results')).toBeInTheDocument();
20
+ expect(screen.getByText('Showing 1 to 1 of 1 results')).toBeInTheDocument();
21
21
  });
22
22
  it('renders range text when total is greater than 1', () => {
23
23
  render(_jsx(SearchTotal, { total: 50, offset: 0, pageLength: 25 }), { wrapper: Wrapper });
@@ -0,0 +1,7 @@
1
+ import type { FC } from 'react';
2
+ export type FuzzySearchBarProps = {
3
+ onSearch: (query: string, indexes: string[]) => void;
4
+ loading?: boolean;
5
+ };
6
+ declare const FuzzySearchBar: FC<FuzzySearchBarProps>;
7
+ export default FuzzySearchBar;
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Search } from '@mui/icons-material';
3
+ import { CircularProgress, IconButton, InputAdornment, Stack, TextField } from '@mui/material';
4
+ import { ParameterContext } from '@cccsaurora/howler-ui/components/app/providers/ParameterProvider';
5
+ import IndexPicker from '@cccsaurora/howler-ui/components/routes/hits/search/shared/IndexPicker';
6
+ import { useCallback, useState } from 'react';
7
+ import { useTranslation } from 'react-i18next';
8
+ import { useContextSelector } from 'use-context-selector';
9
+ const FuzzySearchBar = ({ onSearch, loading = false }) => {
10
+ const { t } = useTranslation();
11
+ const indexes = useContextSelector(ParameterContext, ctx => ctx.indexes);
12
+ const defaultQuery = useContextSelector(ParameterContext, ctx => ctx.query);
13
+ const [query, _setQuery] = useState(defaultQuery ?? '');
14
+ const setQuery = useContextSelector(ParameterContext, ctx => ctx.setQuery);
15
+ const handleQueryChange = useCallback((e) => {
16
+ _setQuery(e.target.value);
17
+ }, [_setQuery]);
18
+ const handleSearch = useCallback(() => {
19
+ if (query.trim()) {
20
+ setQuery(query.trim());
21
+ onSearch(query.trim(), indexes);
22
+ }
23
+ }, [query, setQuery, onSearch, indexes]);
24
+ const handleKeyDown = useCallback((e) => {
25
+ if (e.key === 'Enter') {
26
+ handleSearch();
27
+ }
28
+ }, [handleSearch]);
29
+ return (_jsxs(Stack, { spacing: 1, children: [_jsx(TextField, { id: "fuzzy-search-input", size: "small", fullWidth: true, variant: "outlined", placeholder: t('search.fuzzy.placeholder'), value: query, onChange: handleQueryChange, onKeyDown: handleKeyDown, InputProps: {
30
+ endAdornment: (_jsx(InputAdornment, { position: "end", children: loading ? (_jsx(CircularProgress, { size: 24 })) : (_jsx(IconButton, { id: "fuzzy-search-button", onClick: handleSearch, edge: "end", disabled: !query.trim(), children: _jsx(Search, {}) })) }))
31
+ } }), _jsx(Stack, { direction: "row", children: _jsx(IndexPicker, { additionalOptions: [{ label: 'hit.search.index.case', value: 'case' }] }) })] }));
32
+ };
33
+ export default FuzzySearchBar;
@@ -0,0 +1,87 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent, {} from '@testing-library/user-event';
4
+ import { setupContextSelectorMock } from '@cccsaurora/howler-ui/tests/mocks';
5
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
6
+ setupContextSelectorMock();
7
+ const mockIndexPickerProps = vi.hoisted(() => ({
8
+ last: null
9
+ }));
10
+ vi.mock('react-i18next', () => ({
11
+ useTranslation: () => ({
12
+ t: (key) => key
13
+ })
14
+ }));
15
+ vi.mock('components/routes/hits/search/shared/IndexPicker', () => ({
16
+ default: (props) => {
17
+ mockIndexPickerProps.last = props;
18
+ return _jsx("div", { id: "index-picker" });
19
+ }
20
+ }));
21
+ import { ParameterContext } from '@cccsaurora/howler-ui/components/app/providers/ParameterProvider';
22
+ import FuzzySearchBar from './FuzzySearchBar';
23
+ const mockOnSearch = vi.fn();
24
+ const mockSetQuery = vi.fn();
25
+ const parameterContextValue = {
26
+ indexes: ['hit', 'case'],
27
+ query: '',
28
+ setQuery: mockSetQuery
29
+ };
30
+ const Wrapper = ({ children }) => {
31
+ return _jsx(ParameterContext.Provider, { value: parameterContextValue, children: children });
32
+ };
33
+ describe('FuzzySearchBar', () => {
34
+ let user;
35
+ beforeEach(() => {
36
+ user = userEvent.setup();
37
+ vi.clearAllMocks();
38
+ parameterContextValue.indexes = ['hit', 'case'];
39
+ parameterContextValue.query = '';
40
+ mockIndexPickerProps.last = null;
41
+ });
42
+ it('renders search input and index picker', () => {
43
+ render(_jsx(FuzzySearchBar, { onSearch: mockOnSearch }), { wrapper: Wrapper });
44
+ expect(screen.getByTestId('fuzzy-search-input')).toBeInTheDocument();
45
+ expect(screen.getByTestId('index-picker')).toBeInTheDocument();
46
+ });
47
+ it('disables search button when query is empty', () => {
48
+ render(_jsx(FuzzySearchBar, { onSearch: mockOnSearch }), { wrapper: Wrapper });
49
+ expect(screen.getByTestId('fuzzy-search-button')).toBeDisabled();
50
+ });
51
+ it('calls setQuery and onSearch with trimmed query and selected indexes on click', async () => {
52
+ render(_jsx(FuzzySearchBar, { onSearch: mockOnSearch }), { wrapper: Wrapper });
53
+ await user.type(screen.getByRole('textbox'), ' malware triage ');
54
+ await user.click(screen.getByTestId('fuzzy-search-button'));
55
+ expect(mockSetQuery).toHaveBeenCalledWith('malware triage');
56
+ expect(mockOnSearch).toHaveBeenCalledWith('malware triage', ['hit', 'case']);
57
+ });
58
+ it('triggers search on Enter key', async () => {
59
+ render(_jsx(FuzzySearchBar, { onSearch: mockOnSearch }), { wrapper: Wrapper });
60
+ await user.type(screen.getByRole('textbox'), 'suspicious ip{enter}');
61
+ expect(mockSetQuery).toHaveBeenCalledWith('suspicious ip');
62
+ expect(mockOnSearch).toHaveBeenCalledWith('suspicious ip', ['hit', 'case']);
63
+ });
64
+ it('does not call search for whitespace-only input', async () => {
65
+ render(_jsx(FuzzySearchBar, { onSearch: mockOnSearch }), { wrapper: Wrapper });
66
+ await user.type(screen.getByRole('textbox'), ' ');
67
+ expect(screen.getByTestId('fuzzy-search-button')).toBeDisabled();
68
+ expect(mockSetQuery).not.toHaveBeenCalled();
69
+ expect(mockOnSearch).not.toHaveBeenCalled();
70
+ });
71
+ it('shows loading spinner and hides search button when loading', () => {
72
+ render(_jsx(FuzzySearchBar, { onSearch: mockOnSearch, loading: true }), { wrapper: Wrapper });
73
+ expect(screen.getByRole('progressbar')).toBeInTheDocument();
74
+ expect(screen.queryByTestId('fuzzy-search-button')).not.toBeInTheDocument();
75
+ });
76
+ it('passes expected options to IndexPicker', () => {
77
+ render(_jsx(FuzzySearchBar, { onSearch: mockOnSearch }), { wrapper: Wrapper });
78
+ expect(mockIndexPickerProps.last).toEqual({
79
+ additionalOptions: [{ label: 'hit.search.index.case', value: 'case' }]
80
+ });
81
+ });
82
+ it('initializes input with default query from context', () => {
83
+ parameterContextValue.query = 'existing search';
84
+ render(_jsx(FuzzySearchBar, { onSearch: mockOnSearch }), { wrapper: Wrapper });
85
+ expect(screen.getByRole('textbox')).toHaveValue('existing search');
86
+ });
87
+ });
@@ -1,9 +1,9 @@
1
1
  import type { Case } from '@cccsaurora/howler-ui/models/entities/generated/Case';
2
2
  import type { Event } from '@cccsaurora/howler-ui/models/entities/generated/Event';
3
3
  import type { Hit } from '@cccsaurora/howler-ui/models/entities/generated/Hit';
4
- import { type AssetEntry } from './assets/Asset';
4
+ import { type ObservableEntry } from './observables/Observable';
5
5
  /** Deduplicate and merge seenIn lists into a map keyed by `type:value` */
6
- export declare const buildAssetEntries: (records: Partial<Hit | Event>[]) => AssetEntry[];
6
+ export declare const buildObservableEntries: (records: Partial<Hit | Event>[]) => ObservableEntry[];
7
7
  declare const _default: import("react").NamedExoticComponent<{
8
8
  case?: Case;
9
9
  caseId?: string;
@@ -6,16 +6,16 @@ import { memo, useEffect, useMemo, useState } from 'react';
6
6
  import { useTranslation } from 'react-i18next';
7
7
  import { useOutletContext } from 'react-router-dom';
8
8
  import useCase from '../hooks/useCase';
9
- import Asset, {} from './assets/Asset';
10
- /** All Related fields that carry asset values */
11
- const ASSET_FIELDS = ['hash', 'hosts', 'ip', 'user', 'ids', 'id', 'uri', 'signature'];
9
+ import Observable, {} from './observables/Observable';
10
+ /** All Related fields that carry observable values */
11
+ const OBSERVABLE_FIELDS = ['hash', 'hosts', 'ip', 'user', 'ids', 'id', 'uri', 'signature'];
12
12
  /** Extract (type, value, seenInId) triples from a record's related field */
13
- const extractAssets = (related, recordId) => {
13
+ const extractObservables = (related, recordId) => {
14
14
  if (!related) {
15
15
  return [];
16
16
  }
17
17
  const results = [];
18
- for (const field of ASSET_FIELDS) {
18
+ for (const field of OBSERVABLE_FIELDS) {
19
19
  const raw = related[field];
20
20
  if (!raw) {
21
21
  continue;
@@ -30,7 +30,7 @@ const extractAssets = (related, recordId) => {
30
30
  return results;
31
31
  };
32
32
  /** Deduplicate and merge seenIn lists into a map keyed by `type:value` */
33
- export const buildAssetEntries = (records) => {
33
+ export const buildObservableEntries = (records) => {
34
34
  const map = new Map();
35
35
  for (const record of records) {
36
36
  const related = record.related ?? record.related;
@@ -38,7 +38,7 @@ export const buildAssetEntries = (records) => {
38
38
  if (!recordId) {
39
39
  continue;
40
40
  }
41
- for (const { type, value, id } of extractAssets(related, recordId)) {
41
+ for (const { type, value, id } of extractObservables(related, recordId)) {
42
42
  const key = `${type}:${value}`;
43
43
  if (!map.has(key)) {
44
44
  map.set(key, { type, value, seenIn: [] });
@@ -51,8 +51,8 @@ export const buildAssetEntries = (records) => {
51
51
  }
52
52
  return Array.from(map.values());
53
53
  };
54
- const RELATED_FIELDS = ASSET_FIELDS.map(f => `related.${f}`).join(',');
55
- const CaseAssets = ({ case: providedCase, caseId }) => {
54
+ const RELATED_FIELDS = OBSERVABLE_FIELDS.map(f => `related.${f}`).join(',');
55
+ const CaseObservables = ({ case: providedCase, caseId }) => {
56
56
  const { t } = useTranslation();
57
57
  const { dispatchApi } = useMyApi();
58
58
  const routeCase = useOutletContext();
@@ -73,17 +73,17 @@ const CaseAssets = ({ case: providedCase, caseId }) => {
73
73
  fl: `howler.id,${RELATED_FIELDS}`
74
74
  })).then(response => setRecords(response.items));
75
75
  }, [dispatchApi, ids]);
76
- const allAssets = useMemo(() => (records ? buildAssetEntries(records) : []), [records]);
77
- const assetTypes = useMemo(() => (allAssets ? [...new Set(allAssets.map(a => a.type))].sort() : []), [allAssets]);
78
- const filteredAssets = useMemo(() => {
79
- if (allAssets.length < 1) {
76
+ const allObservables = useMemo(() => (records ? buildObservableEntries(records) : []), [records]);
77
+ const observableTypes = useMemo(() => (allObservables ? [...new Set(allObservables.map(a => a.type))].sort() : []), [allObservables]);
78
+ const filteredObservables = useMemo(() => {
79
+ if (allObservables.length < 1) {
80
80
  return [];
81
81
  }
82
82
  if (activeFilters.size === 0) {
83
- return allAssets;
83
+ return allObservables;
84
84
  }
85
- return allAssets.filter(a => activeFilters.has(a.type));
86
- }, [allAssets, activeFilters]);
85
+ return allObservables.filter(a => activeFilters.has(a.type));
86
+ }, [allObservables, activeFilters]);
87
87
  const toggleFilter = (type) => {
88
88
  setActiveFilters(prev => {
89
89
  const next = new Set(prev);
@@ -99,6 +99,6 @@ const CaseAssets = ({ case: providedCase, caseId }) => {
99
99
  if (!_case) {
100
100
  return null;
101
101
  }
102
- return (_jsxs(Grid, { container: true, spacing: 2, px: 2, children: [_jsx(Grid, { item: true, xs: 12, children: _jsxs(Stack, { direction: "row", alignItems: "center", spacing: 1, flexWrap: "wrap", children: [_jsx(Typography, { variant: "subtitle2", color: "text.secondary", children: t('page.cases.assets.filter_by_type') }), records === null ? (_jsx(Skeleton, { width: 240, height: 32 })) : (assetTypes.map(type => (_jsx(Chip, { label: t(`page.cases.assets.type.${type}`), size: "small", onClick: () => toggleFilter(type), color: activeFilters.has(type) ? 'primary' : 'default', variant: activeFilters.has(type) ? 'filled' : 'outlined' }, type))))] }) }), records === null ? (Array.from({ length: 6 }, (_, i) => (_jsx(Grid, { item: true, xs: 12, sm: 6, md: 4, xl: 3, children: _jsx(Skeleton, { height: 100 }) }, `skeleton-${i}`)))) : filteredAssets.length === 0 ? (_jsx(Grid, { item: true, xs: 12, children: _jsx(Typography, { color: "text.secondary", children: t('page.cases.assets.empty') }) })) : (filteredAssets.map(asset => (_jsx(Grid, { item: true, xs: 12, md: 6, xl: 4, children: _jsx(Asset, { asset: asset, case: _case }) }, `${asset.type}:${asset.value}`))))] }));
102
+ return (_jsxs(Grid, { container: true, spacing: 2, px: 2, children: [_jsx(Grid, { item: true, xs: 12, children: _jsxs(Stack, { direction: "row", alignItems: "center", spacing: 1, flexWrap: "wrap", children: [_jsx(Typography, { variant: "subtitle2", color: "text.secondary", children: t('page.cases.observables.filter_by_type') }), records === null ? (_jsx(Skeleton, { width: 240, height: 32 })) : (observableTypes.map(type => (_jsx(Chip, { label: t(`page.cases.observables.type.${type}`), size: "small", onClick: () => toggleFilter(type), color: activeFilters.has(type) ? 'primary' : 'default', variant: activeFilters.has(type) ? 'filled' : 'outlined' }, type))))] }) }), records === null ? (Array.from({ length: 6 }, (_, i) => (_jsx(Grid, { item: true, xs: 12, sm: 6, md: 4, xl: 3, children: _jsx(Skeleton, { height: 100 }) }, `skeleton-${i}`)))) : filteredObservables.length === 0 ? (_jsx(Grid, { item: true, xs: 12, children: _jsx(Typography, { color: "text.secondary", children: t('page.cases.observables.empty') }) })) : (filteredObservables.map(observable => (_jsx(Grid, { item: true, xs: 12, md: 6, xl: 4, children: _jsx(Observable, { asset: observable, case: _case }) }, `${observable.type}:${observable.value}`))))] }));
103
103
  };
104
- export default memo(CaseAssets);
104
+ export default memo(CaseObservables);