@cccsaurora/howler-ui 2.13.0-dev.107 → 2.13.0-dev.125

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 (41) hide show
  1. package/api/hit/index.d.ts +1 -1
  2. package/api/hit/index.js +6 -2
  3. package/api/search/index.d.ts +1 -0
  4. package/commons/components/utils/hooks/useEnv.d.ts +1 -1
  5. package/components/app/App.js +1 -3
  6. package/components/app/hooks/useMatchers.d.ts +8 -0
  7. package/components/app/hooks/useMatchers.js +46 -0
  8. package/components/app/hooks/useMatchers.test.d.ts +1 -0
  9. package/components/app/hooks/useMatchers.test.js +237 -0
  10. package/components/app/hooks/useTitle.js +5 -4
  11. package/components/app/providers/HitProvider.d.ts +2 -1
  12. package/components/app/providers/HitProvider.js +8 -2
  13. package/components/app/providers/HitSearchProvider.d.ts +2 -1
  14. package/components/app/providers/HitSearchProvider.js +2 -1
  15. package/components/app/providers/SocketProvider.js +1 -1
  16. package/components/elements/display/handlebars/helpers.js +5 -2
  17. package/components/elements/hit/HitCard.js +0 -5
  18. package/components/elements/hit/HitOutline.d.ts +2 -2
  19. package/components/elements/hit/HitOutline.js +11 -21
  20. package/components/elements/hit/HitOverview.js +7 -4
  21. package/components/elements/hit/HitSummary.d.ts +2 -1
  22. package/components/elements/hit/HitSummary.js +7 -6
  23. package/components/elements/hit/related/PivotLink.js +10 -3
  24. package/components/routes/analytics/AnalyticTemplates.js +9 -6
  25. package/components/routes/hits/search/InformationPane.js +25 -40
  26. package/components/routes/hits/search/SearchPane.js +2 -8
  27. package/components/routes/hits/search/grid/AddColumnModal.js +10 -5
  28. package/components/routes/hits/view/HitViewer.js +17 -23
  29. package/components/routes/templates/TemplateViewer.js +27 -36
  30. package/components/routes/templates/Templates.js +4 -11
  31. package/locales/en/translation.json +1 -0
  32. package/locales/fr/translation.json +1 -0
  33. package/models/WithMetadata.d.ts +8 -0
  34. package/models/WithMetadata.js +1 -0
  35. package/package.json +104 -104
  36. package/setupTests.d.ts +1 -0
  37. package/setupTests.js +8 -0
  38. package/components/app/providers/DossierProvider.d.ts +0 -16
  39. package/components/app/providers/DossierProvider.js +0 -82
  40. package/components/app/providers/TemplateProvider.d.ts +0 -14
  41. package/components/app/providers/TemplateProvider.js +0 -103
@@ -0,0 +1,8 @@
1
+ import type { Dossier } from './entities/generated/Dossier';
2
+ import type { Overview } from './entities/generated/Overview';
3
+ import type { Template } from './entities/generated/Template';
4
+ export type WithMetadata<T> = T & {
5
+ __template?: Template;
6
+ __overview?: Overview;
7
+ __dossiers?: Dossier[];
8
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -96,162 +96,162 @@
96
96
  "internal-slot": "1.0.7"
97
97
  },
98
98
  "type": "module",
99
- "version": "2.13.0-dev.107",
99
+ "version": "2.13.0-dev.125",
100
100
  "exports": {
101
101
  "./i18n": "./i18n.js",
102
102
  "./index.css": "./index.css",
103
- "./models/*": "./models/*.js",
104
- "./branding/*": "./branding/*.js",
103
+ "./api/*": "./api/*.js",
104
+ "./api": "./api/index.js",
105
105
  "./commons/*": "./commons/*.js",
106
- "./utils/*": "./utils/*.js",
107
- "./utils/*.json": "./utils/*.json",
108
106
  "./rest/*": "./rest/*.js",
109
107
  "./rest": "./rest/index.js",
108
+ "./locales/*.json": "./locales/*.json",
109
+ "./branding/*": "./branding/*.js",
110
110
  "./components/*": "./components/*.js",
111
+ "./models/*": "./models/*.js",
112
+ "./utils/*": "./utils/*.js",
113
+ "./utils/*.json": "./utils/*.json",
111
114
  "./plugins/*": "./plugins/*.js",
112
- "./api/*": "./api/*.js",
113
- "./api": "./api/index.js",
114
- "./locales/*.json": "./locales/*.json",
115
- "./models/socket/*": "./models/socket/*.js",
116
- "./models/entities/*": "./models/entities/*.js",
117
- "./models/entities/generated/*": "./models/entities/generated/*.js",
115
+ "./api/analytic/*": "./api/analytic/*.js",
116
+ "./api/analytic": "./api/analytic/index.js",
117
+ "./api/configs/*": "./api/configs/*.js",
118
+ "./api/configs": "./api/configs/index.js",
119
+ "./api/dossier/*": "./api/dossier/*.js",
120
+ "./api/dossier": "./api/dossier/index.js",
121
+ "./api/user/*": "./api/user/*.js",
122
+ "./api/user": "./api/user/index.js",
123
+ "./api/notebook/*": "./api/notebook/*.js",
124
+ "./api/notebook": "./api/notebook/index.js",
125
+ "./api/action/*": "./api/action/*.js",
126
+ "./api/action": "./api/action/index.js",
127
+ "./api/auth/*": "./api/auth/*.js",
128
+ "./api/auth": "./api/auth/index.js",
129
+ "./api/search/*": "./api/search/*.js",
130
+ "./api/search": "./api/search/index.js",
131
+ "./api/view/*": "./api/view/*.js",
132
+ "./api/view": "./api/view/index.js",
133
+ "./api/overview/*": "./api/overview/*.js",
134
+ "./api/overview": "./api/overview/index.js",
135
+ "./api/hit/*": "./api/hit/*.js",
136
+ "./api/hit": "./api/hit/index.js",
137
+ "./api/template/*": "./api/template/*.js",
138
+ "./api/template": "./api/template/index.js",
139
+ "./api/analytic/notebooks/*": "./api/analytic/notebooks/*.js",
140
+ "./api/analytic/notebooks": "./api/analytic/notebooks/index.js",
141
+ "./api/analytic/comments/*": "./api/analytic/comments/*.js",
142
+ "./api/analytic/comments": "./api/analytic/comments/index.js",
143
+ "./api/user/avatar/*": "./api/user/avatar/*.js",
144
+ "./api/user/avatar": "./api/user/avatar/index.js",
145
+ "./api/search/fields/*": "./api/search/fields/*.js",
146
+ "./api/search/fields": "./api/search/fields/index.js",
147
+ "./api/search/sigma/*": "./api/search/sigma/*.js",
148
+ "./api/search/histogram/*": "./api/search/histogram/*.js",
149
+ "./api/search/histogram": "./api/search/histogram/index.js",
150
+ "./api/search/grouped/*": "./api/search/grouped/*.js",
151
+ "./api/search/grouped": "./api/search/grouped/index.js",
152
+ "./api/search/count/*": "./api/search/count/*.js",
153
+ "./api/search/count": "./api/search/count/index.js",
154
+ "./api/search/eql/*": "./api/search/eql/*.js",
155
+ "./api/search/facet/*": "./api/search/facet/*.js",
156
+ "./api/search/facet": "./api/search/facet/index.js",
157
+ "./api/hit/comments/*": "./api/hit/comments/*.js",
158
+ "./api/hit/comments": "./api/hit/comments/index.js",
118
159
  "./commons/components/*": "./commons/components/*.js",
119
- "./commons/components/notification/*": "./commons/components/notification/*.js",
120
- "./commons/components/notification": "./commons/components/notification/index.js",
121
- "./commons/components/search/*": "./commons/components/search/*.js",
122
- "./commons/components/display/*": "./commons/components/display/*.js",
123
160
  "./commons/components/breadcrumbs/*": "./commons/components/breadcrumbs/*.js",
124
161
  "./commons/components/app/*": "./commons/components/app/*.js",
125
- "./commons/components/utils/*": "./commons/components/utils/*.js",
162
+ "./commons/components/notification/*": "./commons/components/notification/*.js",
163
+ "./commons/components/notification": "./commons/components/notification/index.js",
126
164
  "./commons/components/topnav/*": "./commons/components/topnav/*.js",
127
165
  "./commons/components/pages/*": "./commons/components/pages/*.js",
166
+ "./commons/components/display/*": "./commons/components/display/*.js",
167
+ "./commons/components/utils/*": "./commons/components/utils/*.js",
128
168
  "./commons/components/leftnav/*": "./commons/components/leftnav/*.js",
129
- "./commons/components/notification/elements/*": "./commons/components/notification/elements/*.js",
130
- "./commons/components/notification/elements/item/*": "./commons/components/notification/elements/item/*.js",
131
- "./commons/components/display/hooks/*": "./commons/components/display/hooks/*.js",
169
+ "./commons/components/search/*": "./commons/components/search/*.js",
132
170
  "./commons/components/app/hooks/*": "./commons/components/app/hooks/*.js",
133
171
  "./commons/components/app/hooks": "./commons/components/app/hooks/index.js",
134
172
  "./commons/components/app/providers/*": "./commons/components/app/providers/*.js",
135
- "./commons/components/utils/hooks/*": "./commons/components/utils/hooks/*.js",
173
+ "./commons/components/notification/elements/*": "./commons/components/notification/elements/*.js",
174
+ "./commons/components/notification/elements/item/*": "./commons/components/notification/elements/item/*.js",
136
175
  "./commons/components/pages/hooks/*": "./commons/components/pages/hooks/*.js",
176
+ "./commons/components/display/hooks/*": "./commons/components/display/hooks/*.js",
177
+ "./commons/components/utils/hooks/*": "./commons/components/utils/hooks/*.js",
178
+ "./locales/en/*.json": "./locales/en/*.json",
179
+ "./locales/fr/*.json": "./locales/fr/*.json",
180
+ "./locales/en/help/*.json": "./locales/en/help/*.json",
181
+ "./locales/fr/help/*.json": "./locales/fr/help/*.json",
182
+ "./components/app/*": "./components/app/*.js",
137
183
  "./components/hooks/*": "./components/hooks/*.js",
138
184
  "./components/elements/*": "./components/elements/*.js",
139
- "./components/app/*": "./components/app/*.js",
140
185
  "./components/routes/*": "./components/routes/*.js",
141
186
  "./components/logins/*": "./components/logins/*.js",
187
+ "./components/app/hooks/*": "./components/app/hooks/*.js",
188
+ "./components/app/drawers/*": "./components/app/drawers/*.js",
189
+ "./components/app/providers/*": "./components/app/providers/*.js",
190
+ "./components/elements/addons/*": "./components/elements/addons/*.js",
142
191
  "./components/elements/display/*": "./components/elements/display/*.js",
143
192
  "./components/elements/view/*": "./components/elements/view/*.js",
144
- "./components/elements/addons/*": "./components/elements/addons/*.js",
145
193
  "./components/elements/hit/*": "./components/elements/hit/*.js",
146
- "./components/elements/display/handlebars/*": "./components/elements/display/handlebars/*.js",
147
- "./components/elements/display/features/*": "./components/elements/display/features/*.js",
148
- "./components/elements/display/json/*": "./components/elements/display/json/*.js",
149
- "./components/elements/display/modals/*": "./components/elements/display/modals/*.js",
150
- "./components/elements/display/icons/*": "./components/elements/display/icons/*.js",
151
- "./components/elements/display/markdownPlugins/*.md": "./components/elements/display/markdownPlugins/*.md.js",
152
- "./components/elements/display/icons/svg/*": "./components/elements/display/icons/svg/*.js",
153
- "./components/elements/addons/search/*": "./components/elements/addons/search/*.js",
194
+ "./components/elements/addons/lists/*": "./components/elements/addons/lists/*.js",
195
+ "./components/elements/addons/lists": "./components/elements/addons/lists/index.js",
154
196
  "./components/elements/addons/buttons/*": "./components/elements/addons/buttons/*.js",
155
197
  "./components/elements/addons/buttons": "./components/elements/addons/buttons/index.js",
156
198
  "./components/elements/addons/layout/*": "./components/elements/addons/layout/*.js",
157
- "./components/elements/addons/lists/*": "./components/elements/addons/lists/*.js",
158
- "./components/elements/addons/lists": "./components/elements/addons/lists/index.js",
199
+ "./components/elements/addons/search/*": "./components/elements/addons/search/*.js",
200
+ "./components/elements/addons/lists/hooks/*": "./components/elements/addons/lists/hooks/*.js",
201
+ "./components/elements/addons/lists/table/*": "./components/elements/addons/lists/table/*.js",
202
+ "./components/elements/addons/lists/table": "./components/elements/addons/lists/table/index.js",
203
+ "./components/elements/addons/layout/vsbox/*": "./components/elements/addons/layout/vsbox/*.js",
159
204
  "./components/elements/addons/search/phrase/*": "./components/elements/addons/search/phrase/*.js",
160
205
  "./components/elements/addons/search/phrase": "./components/elements/addons/search/phrase/index.js",
161
206
  "./components/elements/addons/search/phrase/word/*": "./components/elements/addons/search/phrase/word/*.js",
162
207
  "./components/elements/addons/search/phrase/word/consumers/*": "./components/elements/addons/search/phrase/word/consumers/*.js",
163
- "./components/elements/addons/layout/vsbox/*": "./components/elements/addons/layout/vsbox/*.js",
164
- "./components/elements/addons/lists/hooks/*": "./components/elements/addons/lists/hooks/*.js",
165
- "./components/elements/addons/lists/table/*": "./components/elements/addons/lists/table/*.js",
166
- "./components/elements/addons/lists/table": "./components/elements/addons/lists/table/index.js",
167
- "./components/elements/hit/aggregate/*": "./components/elements/hit/aggregate/*.js",
168
- "./components/elements/hit/actions/*": "./components/elements/hit/actions/*.js",
208
+ "./components/elements/display/features/*": "./components/elements/display/features/*.js",
209
+ "./components/elements/display/markdownPlugins/*.md": "./components/elements/display/markdownPlugins/*.md.js",
210
+ "./components/elements/display/icons/*": "./components/elements/display/icons/*.js",
211
+ "./components/elements/display/handlebars/*": "./components/elements/display/handlebars/*.js",
212
+ "./components/elements/display/modals/*": "./components/elements/display/modals/*.js",
213
+ "./components/elements/display/json/*": "./components/elements/display/json/*.js",
214
+ "./components/elements/display/icons/svg/*": "./components/elements/display/icons/svg/*.js",
169
215
  "./components/elements/hit/related/*": "./components/elements/hit/related/*.js",
216
+ "./components/elements/hit/aggregate/*": "./components/elements/hit/aggregate/*.js",
170
217
  "./components/elements/hit/elements/*": "./components/elements/hit/elements/*.js",
218
+ "./components/elements/hit/actions/*": "./components/elements/hit/actions/*.js",
171
219
  "./components/elements/hit/outlines/*": "./components/elements/hit/outlines/*.js",
172
220
  "./components/elements/hit/outlines/al/*": "./components/elements/hit/outlines/al/*.js",
173
- "./components/app/hooks/*": "./components/app/hooks/*.js",
174
- "./components/app/drawers/*": "./components/app/drawers/*.js",
175
- "./components/app/providers/*": "./components/app/providers/*.js",
176
221
  "./components/routes/home/*": "./components/routes/home/*.js",
177
222
  "./components/routes/home": "./components/routes/home/index.js",
178
- "./components/routes/dossiers/*": "./components/routes/dossiers/*.js",
179
223
  "./components/routes/views/*": "./components/routes/views/*.js",
180
- "./components/routes/action/*": "./components/routes/action/*.js",
181
- "./components/routes/overviews/*": "./components/routes/overviews/*.js",
224
+ "./components/routes/hits/*": "./components/routes/hits/*.js",
225
+ "./components/routes/advanced/*": "./components/routes/advanced/*.js",
182
226
  "./components/routes/admin/*": "./components/routes/admin/*.js",
227
+ "./components/routes/dossiers/*": "./components/routes/dossiers/*.js",
228
+ "./components/routes/templates/*": "./components/routes/templates/*.js",
229
+ "./components/routes/action/*": "./components/routes/action/*.js",
183
230
  "./components/routes/settings/*": "./components/routes/settings/*.js",
231
+ "./components/routes/overviews/*": "./components/routes/overviews/*.js",
184
232
  "./components/routes/help/*": "./components/routes/help/*.js",
185
- "./components/routes/hits/*": "./components/routes/hits/*.js",
186
233
  "./components/routes/analytics/*": "./components/routes/analytics/*.js",
187
- "./components/routes/advanced/*": "./components/routes/advanced/*.js",
188
- "./components/routes/templates/*": "./components/routes/templates/*.js",
189
- "./components/routes/action/view/*": "./components/routes/action/view/*.js",
190
- "./components/routes/action/shared/*": "./components/routes/action/shared/*.js",
191
- "./components/routes/action/edit/*": "./components/routes/action/edit/*.js",
192
- "./components/routes/admin/users/*": "./components/routes/admin/users/*.js",
193
- "./components/routes/help/components/*": "./components/routes/help/components/*.js",
194
- "./components/routes/help/markdown/*.md": "./components/routes/help/markdown/*.md.js",
195
- "./components/routes/help/markdown/en/*.md": "./components/routes/help/markdown/en/*.md.js",
196
- "./components/routes/help/markdown/fr/*.md": "./components/routes/help/markdown/fr/*.md.js",
197
234
  "./components/routes/hits/search/*": "./components/routes/hits/search/*.js",
198
235
  "./components/routes/hits/view/*": "./components/routes/hits/view/*.js",
199
236
  "./components/routes/hits/search/grid/*": "./components/routes/hits/search/grid/*.js",
200
237
  "./components/routes/hits/search/shared/*": "./components/routes/hits/search/shared/*.js",
238
+ "./components/routes/admin/users/*": "./components/routes/admin/users/*.js",
239
+ "./components/routes/action/edit/*": "./components/routes/action/edit/*.js",
240
+ "./components/routes/action/shared/*": "./components/routes/action/shared/*.js",
241
+ "./components/routes/action/view/*": "./components/routes/action/view/*.js",
242
+ "./components/routes/help/markdown/*.md": "./components/routes/help/markdown/*.md.js",
243
+ "./components/routes/help/components/*": "./components/routes/help/components/*.js",
244
+ "./components/routes/help/markdown/en/*.md": "./components/routes/help/markdown/en/*.md.js",
245
+ "./components/routes/help/markdown/fr/*.md": "./components/routes/help/markdown/fr/*.md.js",
201
246
  "./components/routes/analytics/widgets/*": "./components/routes/analytics/widgets/*.js",
202
247
  "./components/logins/hooks/*": "./components/logins/hooks/*.js",
203
248
  "./components/logins/auth/*": "./components/logins/auth/*.js",
249
+ "./models/socket/*": "./models/socket/*.js",
250
+ "./models/entities/*": "./models/entities/*.js",
251
+ "./models/entities/generated/*": "./models/entities/generated/*.js",
204
252
  "./plugins/borealis/*": "./plugins/borealis/*.js",
205
253
  "./plugins/borealis": "./plugins/borealis/index.js",
206
- "./plugins/borealis/components/*": "./plugins/borealis/components/*.js",
207
254
  "./plugins/borealis/locales/*": "./plugins/borealis/locales/*.js",
208
- "./api/search/*": "./api/search/*.js",
209
- "./api/search": "./api/search/index.js",
210
- "./api/analytic/*": "./api/analytic/*.js",
211
- "./api/analytic": "./api/analytic/index.js",
212
- "./api/auth/*": "./api/auth/*.js",
213
- "./api/auth": "./api/auth/index.js",
214
- "./api/template/*": "./api/template/*.js",
215
- "./api/template": "./api/template/index.js",
216
- "./api/view/*": "./api/view/*.js",
217
- "./api/view": "./api/view/index.js",
218
- "./api/action/*": "./api/action/*.js",
219
- "./api/action": "./api/action/index.js",
220
- "./api/user/*": "./api/user/*.js",
221
- "./api/user": "./api/user/index.js",
222
- "./api/overview/*": "./api/overview/*.js",
223
- "./api/overview": "./api/overview/index.js",
224
- "./api/configs/*": "./api/configs/*.js",
225
- "./api/configs": "./api/configs/index.js",
226
- "./api/dossier/*": "./api/dossier/*.js",
227
- "./api/dossier": "./api/dossier/index.js",
228
- "./api/hit/*": "./api/hit/*.js",
229
- "./api/hit": "./api/hit/index.js",
230
- "./api/notebook/*": "./api/notebook/*.js",
231
- "./api/notebook": "./api/notebook/index.js",
232
- "./api/search/grouped/*": "./api/search/grouped/*.js",
233
- "./api/search/grouped": "./api/search/grouped/index.js",
234
- "./api/search/sigma/*": "./api/search/sigma/*.js",
235
- "./api/search/histogram/*": "./api/search/histogram/*.js",
236
- "./api/search/histogram": "./api/search/histogram/index.js",
237
- "./api/search/eql/*": "./api/search/eql/*.js",
238
- "./api/search/facet/*": "./api/search/facet/*.js",
239
- "./api/search/facet": "./api/search/facet/index.js",
240
- "./api/search/fields/*": "./api/search/fields/*.js",
241
- "./api/search/fields": "./api/search/fields/index.js",
242
- "./api/search/count/*": "./api/search/count/*.js",
243
- "./api/search/count": "./api/search/count/index.js",
244
- "./api/analytic/notebooks/*": "./api/analytic/notebooks/*.js",
245
- "./api/analytic/notebooks": "./api/analytic/notebooks/index.js",
246
- "./api/analytic/comments/*": "./api/analytic/comments/*.js",
247
- "./api/analytic/comments": "./api/analytic/comments/index.js",
248
- "./api/user/avatar/*": "./api/user/avatar/*.js",
249
- "./api/user/avatar": "./api/user/avatar/index.js",
250
- "./api/hit/comments/*": "./api/hit/comments/*.js",
251
- "./api/hit/comments": "./api/hit/comments/index.js",
252
- "./locales/en/*.json": "./locales/en/*.json",
253
- "./locales/fr/*.json": "./locales/fr/*.json",
254
- "./locales/en/help/*.json": "./locales/en/help/*.json",
255
- "./locales/fr/help/*.json": "./locales/fr/help/*.json"
255
+ "./plugins/borealis/components/*": "./plugins/borealis/components/*.js"
256
256
  }
257
257
  }
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/vitest';
package/setupTests.js ADDED
@@ -0,0 +1,8 @@
1
+ /// <reference types="vitest" />
2
+ import * as matchers from '@testing-library/jest-dom/matchers';
3
+ import '@testing-library/jest-dom/vitest';
4
+ import { configure } from '@testing-library/react';
5
+ // Extend vitest with the dom matchers from jest-dom.
6
+ expect.extend(matchers);
7
+ // tell React Testing Library to look for id as the testId.
8
+ configure({ testIdAttribute: 'id' });
@@ -1,16 +0,0 @@
1
- import type { Dossier } from '@cccsaurora/howler-ui/models/entities/generated/Dossier';
2
- import { type FC, type PropsWithChildren } from 'react';
3
- export interface DossierContextType {
4
- ready: boolean;
5
- dossiers: Dossier[];
6
- fetchDossiers: (force?: boolean) => Promise<void>;
7
- addDossier: (v: Dossier) => Promise<Dossier>;
8
- editDossier: (dossier: Dossier) => Promise<Dossier>;
9
- removeDossier: (id: string) => Promise<void>;
10
- getCurrentDossiers: () => Dossier[];
11
- getMatchingDossiers: (id: string) => Promise<Dossier[]>;
12
- }
13
- export declare const DossierContext: import("use-context-selector").Context<DossierContextType>;
14
- declare const DossierProvider: FC<PropsWithChildren>;
15
- export declare const useDossierContextSelector: <Selected>(selector: (value: DossierContextType) => Selected) => Selected;
16
- export default DossierProvider;
@@ -1,82 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import api from '@cccsaurora/howler-ui/api';
3
- import { useAppUser } from '@cccsaurora/howler-ui/commons/components/app/hooks';
4
- import useMyApi from '@cccsaurora/howler-ui/components/hooks/useMyApi';
5
- import { useCallback, useEffect, useState } from 'react';
6
- import { createContext, useContextSelector } from 'use-context-selector';
7
- export const DossierContext = createContext(null);
8
- const DossierProvider = ({ children }) => {
9
- const { dispatchApi } = useMyApi();
10
- const appUser = useAppUser();
11
- const [loading, setLoading] = useState(false);
12
- const [ready, setReady] = useState(false);
13
- const [dossiers, setDossiers] = useState([]);
14
- const [idToDossiers, setIdToDossiers] = useState({});
15
- const fetchDossiers = useCallback(async (force = false) => {
16
- if (ready && !force) {
17
- return;
18
- }
19
- if (!appUser.isReady()) {
20
- return;
21
- }
22
- setLoading(true);
23
- try {
24
- setDossiers((await api.dossier.get()));
25
- setReady(true);
26
- }
27
- finally {
28
- setLoading(false);
29
- }
30
- }, [appUser, ready]);
31
- useEffect(() => {
32
- if (!ready && !loading) {
33
- fetchDossiers();
34
- }
35
- }, [fetchDossiers, ready, loading]);
36
- const getCurrentDossiers = useCallback(() => {
37
- return [];
38
- }, []);
39
- const editDossier = useCallback(async (dossier) => {
40
- const result = await api.dossier.put(dossier.dossier_id, dossier);
41
- setDossiers(_dossiers => _dossiers.map(_dossier => (_dossier.dossier_id === dossier.dossier_id ? { ..._dossier, dossier } : _dossier)));
42
- return result;
43
- }, []);
44
- const addDossier = useCallback(async (dossier) => {
45
- const newDossier = await dispatchApi(api.dossier.post(dossier));
46
- setDossiers(_dossiers => [..._dossiers, newDossier]);
47
- return newDossier;
48
- }, [dispatchApi]);
49
- const removeDossier = useCallback(async (id) => {
50
- const result = await api.dossier.del(id);
51
- setDossiers(_dossiers => _dossiers.filter(v => v.dossier_id !== id));
52
- return result;
53
- }, []);
54
- const getMatchingDossiers = useCallback(async (id) => {
55
- if (idToDossiers[id]) {
56
- return idToDossiers[id];
57
- }
58
- const result = await dispatchApi(api.dossier.hit.get(id), { throwError: false });
59
- if (result) {
60
- setIdToDossiers(_dossiers => ({
61
- ..._dossiers,
62
- [id]: result
63
- }));
64
- return result;
65
- }
66
- return [];
67
- }, [dispatchApi, idToDossiers]);
68
- return (_jsx(DossierContext.Provider, { value: {
69
- ready,
70
- dossiers,
71
- fetchDossiers,
72
- addDossier,
73
- editDossier,
74
- removeDossier,
75
- getCurrentDossiers,
76
- getMatchingDossiers
77
- }, children: children }));
78
- };
79
- export const useDossierContextSelector = (selector) => {
80
- return useContextSelector(DossierContext, selector);
81
- };
82
- export default DossierProvider;
@@ -1,14 +0,0 @@
1
- import type { Hit } from '@cccsaurora/howler-ui/models/entities/generated/Hit';
2
- import type { Template } from '@cccsaurora/howler-ui/models/entities/generated/Template';
3
- import type { FC, PropsWithChildren } from 'react';
4
- interface TemplateContextType {
5
- templates: Template[];
6
- getTemplates: (force?: boolean) => Promise<Template[]>;
7
- getMatchingTemplate: (h: Hit) => Template;
8
- refresh: () => void;
9
- loaded: boolean;
10
- }
11
- export declare const TemplateContext: import("use-context-selector").Context<TemplateContextType>;
12
- declare const TemplateProvider: FC<PropsWithChildren>;
13
- export declare const useTemplateContextSelector: <Selected>(selector: (value: TemplateContextType) => Selected) => Selected;
14
- export default TemplateProvider;
@@ -1,103 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import api from '@cccsaurora/howler-ui/api';
3
- import useMyApi from '@cccsaurora/howler-ui/components/hooks/useMyApi';
4
- import { useCallback, useRef, useState } from 'react';
5
- import { createContext, useContextSelector } from 'use-context-selector';
6
- const SIX_TAIL_PHISH_DETAILS = [
7
- 'event.start',
8
- 'event.end',
9
- 'destination.ip',
10
- 'destination.domain',
11
- 'cloud.service.name',
12
- 'error.code',
13
- 'error.message'
14
- ];
15
- /**
16
- * TODO: Ask analysts to move these into the API
17
- */
18
- const BUILTIN_TEMPLATES = [
19
- {
20
- analytic: '6TailPhish',
21
- keys: SIX_TAIL_PHISH_DETAILS,
22
- owner: 'none',
23
- template_id: '6tailphish.builtin',
24
- type: 'readonly'
25
- }
26
- ];
27
- export const TemplateContext = createContext(null);
28
- const TemplateProvider = ({ children }) => {
29
- const request = useRef(null);
30
- const { dispatchApi } = useMyApi();
31
- const [loaded, setLoaded] = useState(false);
32
- const templateRequest = useRef(null);
33
- const [templates, setTemplates] = useState(BUILTIN_TEMPLATES);
34
- const getTemplates = useCallback(async (force = false) => {
35
- if (request.current) {
36
- return request.current;
37
- }
38
- if (loaded && !force) {
39
- return templates;
40
- }
41
- else if (templateRequest.current) {
42
- return templateRequest.current;
43
- }
44
- else {
45
- try {
46
- request.current = dispatchApi(api.template.get());
47
- const result = await request.current;
48
- const fullList = [...BUILTIN_TEMPLATES, ...result];
49
- setTemplates(fullList);
50
- setLoaded(true);
51
- return fullList;
52
- }
53
- catch (e) {
54
- return [];
55
- }
56
- finally {
57
- request.current = null;
58
- }
59
- }
60
- }, [dispatchApi, loaded, templates]);
61
- /**
62
- * Based on a given hit, retrieve the best match for a template
63
- */
64
- const getMatchingTemplate = useCallback((hit) => templates
65
- .filter(_template =>
66
- // The analytic must match, and the detection must either a) not exist or b) match the hit
67
- _template.analytic === hit.howler.analytic &&
68
- (!_template.detection || _template.detection.toLowerCase() === hit.howler.detection?.toLowerCase()))
69
- .sort((a, b) => {
70
- // Sort priority:
71
- // 1. personal > readonly > global
72
- // 2. detection > !detection
73
- if (a.type !== b.type) {
74
- const order = {
75
- personal: 2,
76
- readonly: 1,
77
- global: 0
78
- };
79
- return order[b.type] - order[a.type];
80
- }
81
- else {
82
- if (a.detection && !b.detection) {
83
- return -1;
84
- }
85
- else if (!a.detection && b.detection) {
86
- return 1;
87
- }
88
- else {
89
- return 0;
90
- }
91
- }
92
- })[0], [templates]);
93
- const refresh = useCallback(() => {
94
- setLoaded(false);
95
- getTemplates();
96
- // eslint-disable-next-line react-hooks/exhaustive-deps
97
- }, []);
98
- return (_jsx(TemplateContext.Provider, { value: { templates, getTemplates, getMatchingTemplate, refresh, loaded }, children: children }));
99
- };
100
- export const useTemplateContextSelector = (selector) => {
101
- return useContextSelector(TemplateContext, selector);
102
- };
103
- export default TemplateProvider;