@cccsaurora/howler-ui 3.1.0-dev.1424 → 3.1.0-dev.1437

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 (30) hide show
  1. package/components/app/hooks/useMatchers.d.ts +2 -1
  2. package/components/app/hooks/useMatchers.js +4 -1
  3. package/components/app/hooks/useMatchers.test.js +10 -0
  4. package/components/elements/display/Markdown.js +9 -3
  5. package/components/elements/display/Markdown.test.d.ts +1 -0
  6. package/components/elements/display/Markdown.test.js +25 -0
  7. package/components/elements/display/json/JSONViewer.js +10 -3
  8. package/components/elements/display/json/JSONViewer.test.d.ts +1 -0
  9. package/components/elements/display/json/JSONViewer.test.js +35 -0
  10. package/components/elements/hit/HitBanner.js +15 -66
  11. package/components/elements/hit/HitBanner.test.d.ts +1 -0
  12. package/components/elements/hit/HitBanner.test.js +209 -0
  13. package/components/elements/hit/HitCard.js +1 -1
  14. package/components/elements/hit/HitLabels.js +1 -1
  15. package/components/elements/hit/HitOutline.d.ts +2 -0
  16. package/components/elements/hit/HitOutline.js +73 -28
  17. package/components/elements/hit/HitOutline.test.d.ts +1 -0
  18. package/components/elements/hit/HitOutline.test.js +63 -0
  19. package/components/elements/hit/elements/AnalyticLink.js +4 -3
  20. package/components/elements/hit/elements/AnalyticLink.test.d.ts +1 -0
  21. package/components/elements/hit/elements/AnalyticLink.test.js +26 -0
  22. package/components/routes/help/TemplateDocumentation.js +14 -3
  23. package/components/routes/help/markdown/en/templates.md.js +1 -1
  24. package/locales/en/translation.json +2 -0
  25. package/locales/fr/translation.json +2 -0
  26. package/package.json +109 -111
  27. package/components/elements/hit/outlines/DefaultOutline.d.ts +0 -12
  28. package/components/elements/hit/outlines/DefaultOutline.js +0 -45
  29. package/components/elements/hit/outlines/al/AssemblyLineRules.d.ts +0 -5
  30. package/components/elements/hit/outlines/al/AssemblyLineRules.js +0 -46
@@ -1,9 +1,10 @@
1
1
  import type { Hit } from '@cccsaurora/howler-ui/models/entities/generated/Hit';
2
+ import type { Template } from '@cccsaurora/howler-ui/models/entities/generated/Template';
2
3
  import type { WithMetadata } from '@cccsaurora/howler-ui/models/WithMetadata';
3
4
  declare const useMatchers: (lazy?: boolean) => {
4
5
  getMatchingDossiers: (hit: WithMetadata<Hit>) => Promise<import("../../../models/entities/generated/Dossier").Dossier[]>;
5
6
  getMatchingOverview: (hit: WithMetadata<Hit>) => Promise<import("../../../models/entities/generated/Overview").Overview>;
6
- getMatchingTemplate: (hit: WithMetadata<Hit>) => Promise<import("../../../models/entities/generated/Template").Template>;
7
+ getMatchingTemplate: (hit: WithMetadata<Hit>, providedTemplate?: Template) => Promise<Template>;
7
8
  getMatchingAnalytic: (hit: WithMetadata<Hit>) => Promise<import("../../../models/entities/generated/Analytic").Analytic>;
8
9
  };
9
10
  export default useMatchers;
@@ -5,7 +5,10 @@ import { useContextSelector } from 'use-context-selector';
5
5
  import { RecordContext } from '../providers/RecordProvider';
6
6
  const useMatchers = (lazy = false) => {
7
7
  const getRecord = useContextSelector(RecordContext, ctx => ctx.getRecord);
8
- const getMatchingTemplate = useCallback(async (hit) => {
8
+ const getMatchingTemplate = useCallback(async (hit, providedTemplate) => {
9
+ if (providedTemplate) {
10
+ return providedTemplate;
11
+ }
9
12
  if (!hit) {
10
13
  return null;
11
14
  }
@@ -63,6 +63,16 @@ describe('useMatchers', () => {
63
63
  const template = await result.current.getMatchingTemplate(undefined);
64
64
  expect(template).toBeNull();
65
65
  });
66
+ it('should prefer a provided template over hit metadata', async () => {
67
+ const { has } = await import('lodash-es');
68
+ const providedTemplate = { ...mockTemplate, name: 'provided-template' };
69
+ has.mockReturnValue(true);
70
+ const { result } = renderHook(() => useMatchers());
71
+ const template = await result.current.getMatchingTemplate(mockHitWithMetadata, providedTemplate);
72
+ expect(template).toBe(providedTemplate);
73
+ expect(has).not.toHaveBeenCalled();
74
+ expect(mockGetRecord).not.toHaveBeenCalled();
75
+ });
66
76
  it('should return template from metadata when it exists', async () => {
67
77
  const { has } = await import('lodash-es');
68
78
  has.mockReturnValue(true);
@@ -73,17 +73,23 @@ const Markdown = ({ md, components = {}, disableLinks = false }) => {
73
73
  return _jsx("pre", { className: "mermaid", children: node.children[0].value });
74
74
  }
75
75
  if (match?.[1] === 'json') {
76
+ // Allows passing of settings like so:
77
+ // ```json[hideSearch=true]
78
+ const opts = /.*\[(.+)\].*/.exec(className ?? '')?.[1];
79
+ const options = Object.fromEntries((opts ? opts.split(',') : [])
80
+ .map(entry => entry.split('=', 2))
81
+ .filter(pair => pair.length === 2 && !!pair[0]));
76
82
  try {
77
- return _jsx(JSONViewer, { data: JSON.parse(node.children[0].value) });
83
+ return (_jsx(JSONViewer, { data: JSON.parse(node.children[0].value), hideSearch: options.hideSearch === 'true' }));
78
84
  }
79
85
  catch {
80
86
  return _jsx("code", { style: { color: 'red' }, children: t('markdown.json.invalid') });
81
87
  }
82
88
  }
83
89
  return match ? (_jsx(SyntaxHighlighter
84
- // eslint-disable-next-line react/no-children-prop
90
+ // oxlint-disable-next-line react/no-children-prop typescript/no-base-to-string
85
91
  , {
86
- // eslint-disable-next-line react/no-children-prop
92
+ // oxlint-disable-next-line react/no-children-prop typescript/no-base-to-string
87
93
  children: String(children).replace(/\n$/, ''), style: isDark ? oneDark : oneLight, language: match[1], PreTag: "div", ...props })) : (_jsx("code", { className: className, ...props, children: children }));
88
94
  },
89
95
  blockquote({ children }) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render, screen } from '@testing-library/react';
3
+ import { describe, expect, it, vi } from 'vitest';
4
+ import Markdown from './Markdown';
5
+ vi.mock('commons/components/app/hooks', () => ({
6
+ useAppTheme: () => ({ isDark: false })
7
+ }));
8
+ vi.mock('mermaid', () => ({
9
+ default: {
10
+ initialize: vi.fn(),
11
+ run: vi.fn()
12
+ }
13
+ }));
14
+ vi.mock('./Notebook', () => ({
15
+ Notebook: () => null
16
+ }));
17
+ vi.mock('./json/JSONViewer', () => ({
18
+ default: ({ data, hideSearch }) => (_jsx("output", { id: "json-viewer", children: JSON.stringify({ data, hideSearch }) }))
19
+ }));
20
+ describe('Markdown', () => {
21
+ it('forwards hideSearch from JSON fence options to the viewer', () => {
22
+ render(_jsx(Markdown, { md: '```json[hideSearch=true]\n{"value":"visible"}\n```' }));
23
+ expect(screen.getByTestId('json-viewer')).toHaveTextContent(JSON.stringify({ data: { value: 'visible' }, hideSearch: true }));
24
+ });
25
+ });
@@ -11,7 +11,6 @@ import { StorageKey } from '@cccsaurora/howler-ui/utils/constants';
11
11
  import { validateRegex } from '@cccsaurora/howler-ui/utils/stringUtils';
12
12
  import Throttler from '@cccsaurora/howler-ui/utils/Throttler';
13
13
  import { removeEmpty, searchObject } from '@cccsaurora/howler-ui/utils/utils';
14
- const THROTTLER = new Throttler(150);
15
14
  const JSONViewer = ({ data, collapse = true, hideSearch = false, filter }) => {
16
15
  const { t } = useTranslation();
17
16
  const { isDark } = useAppTheme();
@@ -19,13 +18,21 @@ const JSONViewer = ({ data, collapse = true, hideSearch = false, filter }) => {
19
18
  const [flat] = useMyLocalStorageItem(StorageKey.FLATTEN_JSON);
20
19
  const [query, setQuery] = useState('');
21
20
  const [result, setResult] = useState(null);
21
+ const throttler = useMemo(() => new Throttler(150), []);
22
22
  useEffect(() => {
23
- THROTTLER.debounce(() => {
23
+ let cancelled = false;
24
+ throttler.debounce(() => {
25
+ if (cancelled) {
26
+ return;
27
+ }
24
28
  const filteredData = removeEmpty(data, compact);
25
29
  const searchedData = searchObject(filteredData, filter ?? query, flat);
26
30
  setResult(searchedData);
27
31
  });
28
- }, [compact, data, filter, flat, query]);
32
+ return () => {
33
+ cancelled = true;
34
+ };
35
+ }, [compact, data, filter, flat, query, throttler]);
29
36
  const hasError = useMemo(() => !validateRegex(filter ?? query), [query, filter]);
30
37
  const shouldCollapse = useCallback((field) => {
31
38
  return (field.name !== 'root' && field.type !== 'object') || field.namespace.length > 3;
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { act, render } from '@testing-library/react';
3
+ import { afterEach, describe, expect, it, vi } from 'vitest';
4
+ import JSONViewer from './JSONViewer';
5
+ vi.mock('commons/components/app/hooks', () => ({
6
+ useAppTheme: () => ({ isDark: false })
7
+ }));
8
+ vi.mock('components/elements/addons/search/phrase/Phrase', () => ({
9
+ default: () => _jsx("input", {})
10
+ }));
11
+ vi.mock('components/hooks/useMyLocalStorage', () => ({
12
+ useMyLocalStorageItem: (_key, defaultValue) => [defaultValue]
13
+ }));
14
+ vi.mock('react-i18next', () => ({
15
+ useTranslation: () => ({ t: (key) => key })
16
+ }));
17
+ vi.mock('utils/utils', () => ({
18
+ removeEmpty: vi.fn(),
19
+ searchObject: vi.fn()
20
+ }));
21
+ describe('JSONViewer', () => {
22
+ afterEach(() => {
23
+ vi.useRealTimers();
24
+ });
25
+ it('does not process a debounced result after unmounting', async () => {
26
+ vi.useFakeTimers();
27
+ const { removeEmpty } = await import('utils/utils');
28
+ const { unmount } = render(_jsx(JSONViewer, { data: { value: 'visible' } }));
29
+ unmount();
30
+ act(() => {
31
+ vi.advanceTimersByTime(150);
32
+ });
33
+ expect(removeEmpty).not.toHaveBeenCalled();
34
+ });
35
+ });
@@ -1,10 +1,9 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { OpenInNew } from '@mui/icons-material';
3
- import { Box, Chip, Divider, Grid, Stack, Tooltip, Typography, avatarClasses, chipClasses, iconButtonClasses, useTheme } from '@mui/material';
4
- import { ApiConfigContext } from '@cccsaurora/howler-ui/components/app/providers/ApiConfigProvider';
3
+ import { Box, Chip, Grid, Stack, Tooltip, Typography, chipClasses, useTheme } from '@mui/material';
5
4
  import { uniq } from 'lodash-es';
6
5
  import howlerPluginStore from '@cccsaurora/howler-ui/plugins/store';
7
- import { useCallback, useContext, useMemo } from 'react';
6
+ import { Fragment, useCallback, useMemo } from 'react';
8
7
  import { Trans, useTranslation } from 'react-i18next';
9
8
  import { usePluginStore } from 'react-pluggable';
10
9
  import { ESCALATION_COLORS, PROVIDER_COLORS } from '@cccsaurora/howler-ui/utils/constants';
@@ -19,7 +18,6 @@ import { HitLayout } from './HitLayout';
19
18
  import RelatedRecords from './related/RelatedRecords';
20
19
  const HitBanner = ({ hit, lazy = false, layout = HitLayout.NORMAL, showAssigned = true }) => {
21
20
  const { t } = useTranslation();
22
- const { config } = useContext(ApiConfigContext);
23
21
  const theme = useTheme();
24
22
  const pluginStore = usePluginStore();
25
23
  const compressed = useMemo(() => layout === HitLayout.DENSE, [layout]);
@@ -30,75 +28,26 @@ const HitBanner = ({ hit, lazy = false, layout = HitLayout.NORMAL, showAssigned
30
28
  }
31
29
  return PROVIDER_COLORS[hit?.event.provider] ?? stringToColor(hit?.event.provider);
32
30
  }, [hit?.event.provider]);
33
- const mitreId = useMemo(() => {
34
- if (hit.threat?.framework?.toLowerCase().startsWith('mitre')) {
35
- return;
36
- }
37
- let _id = hit.threat?.tactic?.id;
38
- if (_id && config.lookups.icons.includes(_id)) {
39
- return _id;
40
- }
41
- _id = hit.threat?.technique?.id;
42
- if (_id && config.lookups.icons.includes(_id)) {
43
- return _id;
44
- }
45
- }, [config.lookups.icons, hit.threat?.framework, hit.threat?.tactic?.id, hit.threat?.technique?.id]);
46
- const iconUrl = useMemo(() => {
47
- if (!mitreId) {
48
- return;
49
- }
50
- return `/api/static/mitre/${mitreId}.svg`;
51
- }, [mitreId]);
52
- const leftBox = useMemo(() => (_jsx(HitBannerTooltip, { hit: hit, children: _jsxs(Box, { sx: {
53
- gridColumn: { xs: 'span 3', sm: 'span 1' },
54
- minWidth: '90px',
55
- backgroundColor: providerColor,
56
- color: theme.palette.getContrastText(providerColor),
57
- alignSelf: 'start',
58
- borderRadius: theme.shape.borderRadius,
59
- p: compressed ? 0.5 : 1,
60
- pt: 2,
61
- pl: 1
62
- }, display: "flex", flexDirection: "column", children: [_jsx(Typography, { variant: compressed ? 'caption' : 'body1', style: { wordBreak: 'break-all' }, children: hit.organization?.name ?? _jsx(Trans, { i18nKey: "unknown" }) }), iconUrl && (_jsx(Box, { sx: {
63
- width: '40px',
64
- height: '40px',
65
- mask: `url("${iconUrl}")`,
66
- maskSize: 'cover',
67
- background: theme.palette.getContrastText(providerColor)
68
- } }))] }) })), [compressed, hit, iconUrl, providerColor, theme.palette, theme.shape.borderRadius]);
69
31
  /**
70
32
  * The tooltips are necessary only when in the most compressed format
71
33
  */
72
34
  const Wrapper = useCallback(({ i18nKey, value, field, ...typographyProps }) => {
73
- const _children = (_jsxs(Stack, { direction: "row", spacing: 1, flex: 1, children: [_jsxs(Typography, { variant: textVariant, noWrap: compressed, textOverflow: compressed ? 'ellipsis' : 'wrap', ...typographyProps, sx: [
35
+ const _children = (_jsxs(Stack, { direction: "row", spacing: 1, flex: 1, children: [_jsxs(Typography, { variant: textVariant, noWrap: compressed, fontWeight: "bold", textOverflow: compressed ? 'ellipsis' : 'wrap', ...typographyProps, sx: [
74
36
  { display: 'flex', flexDirection: 'row' },
75
- ...(Array.isArray(typographyProps?.sx) ? typographyProps?.sx : [typographyProps?.sx])
37
+ ...(typographyProps?.sx && Array.isArray(typographyProps.sx) ? typographyProps.sx : [typographyProps?.sx])
76
38
  ], children: [t(i18nKey), ":"] }), (Array.isArray(value) ? value : [value]).map(val => (_jsx(PluginTypography, { component: "span", context: "banner", variant: textVariant, noWrap: compressed, textOverflow: compressed ? 'ellipsis' : 'wrap', ...typographyProps, value: val, field: field, obj: hit }, val)))] }));
77
39
  return compressed ? (_jsx(Tooltip, { title: Array.isArray(value) ? (_jsx("div", { children: value.map(_indicator => (_jsx("p", { style: { margin: 0, padding: 0 }, children: _indicator }, _indicator))) })) : (value), children: _children })) : (_children);
78
40
  }, [compressed, hit, t, textVariant]);
79
- return (_jsxs(Box, { display: "grid", gridTemplateColumns: "minmax(0, auto) minmax(0, 1fr) minmax(0, auto)", alignItems: "stretch", sx: { width: '100%', ml: 0, overflow: 'hidden', textDecoration: 'none', color: 'text.primary' }, component: "a", href: `/hits/${hit?.howler.id}`, onClick: e => e.preventDefault(), children: [leftBox, _jsxs(Stack, { sx: {
80
- height: '100%',
81
- padding: theme.spacing(1),
82
- gridColumn: { xs: 'span 3', sm: 'span 1', md: 'span 1' }
83
- }, spacing: layout !== HitLayout.COMFY ? 1 : 2, divider: _jsx(Divider, { orientation: "horizontal", sx: [
84
- layout !== HitLayout.COMFY && { marginTop: '4px !important' },
85
- { mr: `${theme.spacing(-1)} !important` }
86
- ] }), children: [_jsx(AnalyticLink, { lazy: lazy, hit: hit }), hit.howler?.rationale && (_jsxs(Typography, { flex: 1, variant: textVariant, color: ESCALATION_COLORS[hit.howler.escalation] + '.main', sx: { fontWeight: 'bold' }, children: [t('hit.header.rationale'), ": ", hit.howler.rationale] })), hit.howler?.outline && (_jsxs(_Fragment, { children: [_jsxs(Grid, { container: true, spacing: layout !== HitLayout.COMFY ? 1 : 2, sx: { ml: `${theme.spacing(-1)} !important` }, children: [hit.howler.outline.threat && (_jsx(Grid, { item: true, children: _jsx(Wrapper, { i18nKey: "hit.header.threat", value: hit.howler.outline.threat, field: "howler.outline.threat" }) })), hit.howler.outline.target && (_jsx(Grid, { item: true, children: _jsx(Wrapper, { i18nKey: "hit.header.target", value: hit.howler.outline.target, field: "howler.outline.target" }) }))] }), hit.howler.outline.indicators?.length > 0 && (_jsxs(Stack, { direction: "row", spacing: 1, children: [_jsxs(Typography, { component: "span", variant: textVariant, children: [t('hit.header.indicators'), ":"] }), _jsx(Grid, { container: true, spacing: 0.5, sx: { mt: `${theme.spacing(-0.5)} !important`, ml: `${theme.spacing(0.25)} !important` }, children: uniq(hit.howler.outline.indicators).map((_indicator, index) => {
87
- return (_jsx(Grid, { item: true, children: _jsxs(Stack, { direction: "row", children: [_jsx(PluginTypography, { context: "indicators", variant: textVariant, value: _indicator, children: _indicator }), index < hit.howler.outline.indicators.length - 1 && (_jsx(Typography, { variant: textVariant, children: ',' }))] }) }, _indicator));
88
- }) })] })), hit.howler.outline.summary && (_jsx(Wrapper, { i18nKey: "hit.header.summary", value: hit.howler.outline.summary, paragraph: true, textOverflow: "wrap", sx: [compressed && { marginTop: `0 !important` }], field: "howler.outline.summary" }))] }))] }), _jsxs(Stack, { direction: "column", spacing: layout !== HitLayout.COMFY ? 0.5 : 1, alignSelf: "stretch", sx: [
89
- { minWidth: 0, alignItems: { sm: 'end', md: 'start' }, flex: 1, pl: 1 },
90
- compressed && {
91
- [`& .${avatarClasses.root}`]: {
92
- height: theme.spacing(3),
93
- width: theme.spacing(3)
94
- },
95
- [`& .${iconButtonClasses.root}`]: {
96
- height: theme.spacing(3),
97
- width: theme.spacing(3)
98
- }
99
- }
100
- ], children: [_jsx(HitTimestamp, { hit: hit, layout: layout }), _jsx(Assigned, { hit: hit, layout: layout, showAssigned: showAssigned }), hit.howler.links?.[0]?.href && (_jsx(Chip, { icon: _jsx(OpenInNew, {}), label: hit.howler.links[0].title || t('hit.header.link'), size: layout !== HitLayout.COMFY ? 'small' : 'medium', component: "a", href: hit.howler.links[0].href, target: "_blank", rel: "noopener noreferrer", sx: { [`.${chipClasses.label}`]: { cursor: 'pointer !important' } }, onClick: e => {
101
- e.stopPropagation();
102
- } })), _jsxs(Stack, { direction: "row", spacing: layout !== HitLayout.COMFY ? 0.5 : 1, children: [_jsx(EscalationChip, { hit: hit, layout: layout }), ['in-progress', 'on-hold'].includes(hit.howler.status) && (_jsx(Chip, { sx: { width: 'fit-content', display: 'inline-flex' }, label: hit.howler.status, color: "primary" }))] }), hit.howler.related && _jsx(RelatedRecords, { hit: hit }), howlerPluginStore.plugins.flatMap(plugin => pluginStore.executeFunction(`${plugin}.status`, { hit, layout }))] })] }));
41
+ return (_jsx(Box, { sx: {
42
+ width: '100%',
43
+ ml: 0,
44
+ overflow: 'hidden',
45
+ textDecoration: 'none',
46
+ color: 'text.primary'
47
+ }, component: "a", href: `/hits/${hit?.howler.id}`, onClick: e => e.preventDefault(), children: _jsxs(Stack, { spacing: layout !== HitLayout.COMFY ? 0.25 : 1, children: [_jsxs(Stack, { direction: "row", spacing: 1, flexWrap: "wrap", alignItems: "center", children: [_jsx(HitBannerTooltip, { hit: hit, children: _jsx(Chip, { sx: { backgroundColor: providerColor, color: theme.palette.getContrastText(providerColor) }, label: hit.organization?.name ?? _jsx(Trans, { i18nKey: "unknown" }) }) }), _jsx(AnalyticLink, { lazy: lazy, hit: hit }), _jsx("div", { style: { flex: 1 } }), _jsx(EscalationChip, { hit: hit, layout: layout }), ['in-progress', 'on-hold'].includes(hit.howler.status) && (_jsx(Chip, { sx: { width: 'fit-content', display: 'inline-flex' }, label: hit.howler.status, color: "primary" })), _jsx(HitTimestamp, { hit: hit, layout: layout }), _jsx(Assigned, { hit: hit, layout: layout, showAssigned: showAssigned }), hit.howler.related?.length > 0 && _jsx(RelatedRecords, { hit: hit }), howlerPluginStore.plugins.flatMap(plugin => (_jsx(Fragment, { children: pluginStore.executeFunction(`${plugin}.status`, { hit, layout }) }, plugin)))] }), hit.howler?.rationale && (_jsxs(Typography, { flex: 1, variant: textVariant, color: ESCALATION_COLORS[hit.howler.escalation] + '.main', sx: { fontWeight: 'bold' }, children: [t('hit.header.rationale'), ": ", hit.howler.rationale] })), hit.howler?.outline && (_jsxs(_Fragment, { children: [hit.howler.outline.threat && (_jsx(Wrapper, { i18nKey: "hit.header.threat", value: hit.howler.outline.threat, field: "howler.outline.threat" })), hit.howler.outline.target && (_jsx(Wrapper, { i18nKey: "hit.header.target", value: hit.howler.outline.target, field: "howler.outline.target" })), hit.howler.outline.indicators?.length > 0 && (_jsxs(Stack, { direction: "row", spacing: layout !== HitLayout.COMFY ? 0.25 : 1, children: [_jsxs(Typography, { component: "span", variant: textVariant, fontWeight: "bold", children: [t('hit.header.indicators'), ":"] }), _jsx(Grid, { container: true, spacing: 0.5, sx: { mt: `${theme.spacing(-0.5)} !important`, ml: `${theme.spacing(0.25)} !important` }, children: uniq(hit.howler.outline.indicators).map((_indicator, index) => {
48
+ return (_jsx(Grid, { item: true, children: _jsxs(Stack, { direction: "row", children: [_jsx(PluginTypography, { context: "indicators", variant: textVariant, value: _indicator, children: _indicator }), index < hit.howler.outline.indicators.length - 1 && (_jsx(Typography, { variant: textVariant, children: ',' }))] }) }, _indicator));
49
+ }) })] })), hit.howler.outline.summary && (_jsx(Wrapper, { i18nKey: "hit.header.summary", value: hit.howler.outline.summary, paragraph: true, textOverflow: "wrap", sx: [compressed && { marginTop: `0 !important` }], field: "howler.outline.summary" })), hit.howler.links?.[0]?.href && (_jsx(Chip, { icon: _jsx(OpenInNew, {}), label: hit.howler.links[0].title || t('hit.header.link'), size: layout !== HitLayout.COMFY ? 'small' : 'medium', component: "a", href: hit.howler.links[0].href, target: "_blank", rel: "noopener noreferrer", sx: { [`.${chipClasses.label}`]: { cursor: 'pointer !important' }, alignSelf: 'start' }, onClick: e => {
50
+ e.stopPropagation();
51
+ } }))] }))] }) }));
103
52
  };
104
53
  export default HitBanner;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,209 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createEvent, fireEvent, render, screen } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { ApiConfigContext } from '@cccsaurora/howler-ui/components/app/providers/ApiConfigProvider';
5
+ import { SocketContext } from '@cccsaurora/howler-ui/components/app/providers/SocketProvider';
6
+ import howlerPluginStore from '@cccsaurora/howler-ui/plugins/store';
7
+ import { createMockHit } from '@cccsaurora/howler-ui/tests/utils';
8
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
9
+ import HitBanner from './HitBanner';
10
+ import { HitLayout } from './HitLayout';
11
+ const executeFunctionMock = vi.hoisted(() => vi.fn());
12
+ const stringToColorMock = vi.hoisted(() => vi.fn(() => '#123456'));
13
+ vi.mock('react-pluggable', async () => {
14
+ const actual = await vi.importActual('react-pluggable');
15
+ return {
16
+ ...actual,
17
+ usePluginStore: () => ({ executeFunction: executeFunctionMock })
18
+ };
19
+ });
20
+ vi.mock('react-i18next', () => ({
21
+ useTranslation: () => ({
22
+ t: (key, options) => {
23
+ if (options?.count !== undefined) {
24
+ return `${key}:${options.count}`;
25
+ }
26
+ if (options?.duration) {
27
+ return `${key}:${options.duration}`;
28
+ }
29
+ return key;
30
+ }
31
+ }),
32
+ Trans: ({ i18nKey }) => _jsx("span", { children: i18nKey })
33
+ }));
34
+ vi.mock('commons/components/app/hooks', () => ({
35
+ useAppUser: () => ({ user: { username: 'current-user' } })
36
+ }));
37
+ vi.mock('components/elements/display/HowlerAvatar', () => ({
38
+ default: ({ userId }) => _jsx("div", { id: `avatar-${userId}`, children: userId })
39
+ }));
40
+ vi.mock('utils/utils', async () => {
41
+ const actual = await vi.importActual('utils/utils');
42
+ return {
43
+ ...actual,
44
+ stringToColor: stringToColorMock
45
+ };
46
+ });
47
+ vi.mock('./elements/AnalyticLink', () => ({
48
+ default: () => _jsx("div", { id: "analytic-link", children: "analytic-link" })
49
+ }));
50
+ vi.mock('./related/RelatedRecords', () => ({
51
+ default: () => _jsx("div", { id: "related-records", children: "related-records" })
52
+ }));
53
+ const mockConfig = {
54
+ indexes: {},
55
+ lookups: {},
56
+ configuration: {
57
+ system: {
58
+ retention: {
59
+ limit_amount: 350,
60
+ limit_unit: 'days'
61
+ }
62
+ }
63
+ },
64
+ c12nDef: {},
65
+ mapping: {}
66
+ };
67
+ const createWrapper = (viewers = {}) => {
68
+ const Wrapper = ({ children }) => (_jsx(ApiConfigContext.Provider, { value: { config: mockConfig, setConfig: vi.fn() }, children: _jsx(SocketContext.Provider, { value: {
69
+ viewers,
70
+ addListener: vi.fn(),
71
+ removeListener: vi.fn(),
72
+ emit: vi.fn(),
73
+ status: 1,
74
+ reconnect: vi.fn(),
75
+ open: true,
76
+ fetchViewers: vi.fn()
77
+ }, children: children }) }));
78
+ return Wrapper;
79
+ };
80
+ const createBannerHit = (overrides) => createMockHit({
81
+ organization: { id: 'org-1', name: 'Test Org' },
82
+ event: { provider: 'howler', created: '2024-01-01T00:00:00Z' },
83
+ howler: {
84
+ id: 'hit-123',
85
+ analytic: 'Analytic Name',
86
+ detection: 'Detection Name',
87
+ status: 'open',
88
+ assignment: 'analyst-1',
89
+ escalation: 'hit',
90
+ rationale: 'Escalation rationale',
91
+ related: [],
92
+ outline: {
93
+ threat: 'Threat value',
94
+ target: 'Target value',
95
+ indicators: ['ioc-a', 'ioc-b'],
96
+ summary: 'Summary value'
97
+ },
98
+ links: [{ href: 'https://example.com', title: 'Open source link' }]
99
+ },
100
+ ...overrides
101
+ });
102
+ const renderHitBanner = ({ hit = createBannerHit(), layout = HitLayout.NORMAL, showAssigned = true, viewers = {} } = {}) => render(_jsx(HitBanner, { hit: hit, layout: layout, showAssigned: showAssigned }), {
103
+ wrapper: createWrapper(viewers)
104
+ });
105
+ describe('HitBanner', () => {
106
+ beforeEach(() => {
107
+ howlerPluginStore.plugins.splice(0, howlerPluginStore.plugins.length);
108
+ executeFunctionMock.mockReset();
109
+ stringToColorMock.mockClear();
110
+ });
111
+ afterEach(() => {
112
+ howlerPluginStore.plugins.splice(0, howlerPluginStore.plugins.length);
113
+ });
114
+ it('renders the main banner sections for a fully populated hit', () => {
115
+ renderHitBanner();
116
+ expect(screen.getByText('Test Org')).toBeInTheDocument();
117
+ expect(screen.getByTestId('analytic-link')).toBeInTheDocument();
118
+ expect(screen.getByText('hit.header.rationale: Escalation rationale')).toBeInTheDocument();
119
+ expect(screen.getByText('hit.header.threat:')).toBeInTheDocument();
120
+ expect(screen.getByText('Threat value')).toBeInTheDocument();
121
+ expect(screen.getByText('hit.header.target:')).toBeInTheDocument();
122
+ expect(screen.getByText('Target value')).toBeInTheDocument();
123
+ expect(screen.getByText('hit.header.indicators:')).toBeInTheDocument();
124
+ expect(screen.getByText('ioc-a')).toBeInTheDocument();
125
+ expect(screen.getByText('ioc-b')).toBeInTheDocument();
126
+ expect(screen.getByText('hit.header.summary:')).toBeInTheDocument();
127
+ expect(screen.getByText('Summary value')).toBeInTheDocument();
128
+ expect(screen.getByRole('link', { name: 'Open source link' })).toHaveAttribute('href', 'https://example.com');
129
+ });
130
+ it.each(['in-progress', 'on-hold'])('renders the status chip for %s', status => {
131
+ const hit = createBannerHit({ howler: { ...createBannerHit().howler, status } });
132
+ renderHitBanner({ hit });
133
+ expect(screen.getByText(status)).toBeInTheDocument();
134
+ });
135
+ it('hides and shows the unassigned chip based on showAssigned', () => {
136
+ const hit = createBannerHit({ howler: { ...createBannerHit().howler, assignment: 'unassigned' } });
137
+ renderHitBanner({ hit, showAssigned: false });
138
+ expect(screen.queryByText('app.drawer.hit.assignment.unassigned.name')).not.toBeInTheDocument();
139
+ renderHitBanner({ hit, showAssigned: true });
140
+ expect(screen.getByText('app.drawer.hit.assignment.unassigned.name')).toBeInTheDocument();
141
+ });
142
+ it('renders related records only when related hits are present', () => {
143
+ const withRelated = createBannerHit({ howler: { ...createBannerHit().howler, related: ['hit-2'] } });
144
+ renderHitBanner({ hit: withRelated });
145
+ expect(screen.getByTestId('related-records')).toBeInTheDocument();
146
+ });
147
+ it('uses stringToColor for unknown providers and skips it for known providers', () => {
148
+ const unknownProviderHit = createBannerHit({
149
+ event: { provider: 'custom-provider', created: '2024-01-01T00:00:00Z' }
150
+ });
151
+ renderHitBanner({ hit: unknownProviderHit });
152
+ expect(stringToColorMock).toHaveBeenCalledWith('custom-provider');
153
+ stringToColorMock.mockClear();
154
+ const knownProviderHit = createBannerHit({ event: { provider: 'howler', created: '2024-01-01T00:00:00Z' } });
155
+ renderHitBanner({ hit: knownProviderHit });
156
+ expect(stringToColorMock).not.toHaveBeenCalled();
157
+ });
158
+ it('renders plugin status sections from plugin hooks', () => {
159
+ howlerPluginStore.plugins.push('demo-plugin');
160
+ executeFunctionMock.mockImplementation((name) => {
161
+ if (name === 'demo-plugin.status') {
162
+ return _jsx("span", { id: "plugin-status", children: "plugin-status" });
163
+ }
164
+ return null;
165
+ });
166
+ const hit = createBannerHit();
167
+ renderHitBanner({ hit, layout: HitLayout.COMFY });
168
+ expect(screen.getByTestId('plugin-status')).toBeInTheDocument();
169
+ expect(executeFunctionMock).toHaveBeenCalledWith('demo-plugin.status', { hit, layout: HitLayout.COMFY });
170
+ });
171
+ it('prevents default navigation when the banner root link is clicked', () => {
172
+ const { container } = renderHitBanner();
173
+ const rootLink = container.querySelector('a[href="/hits/hit-123"]');
174
+ expect(rootLink).toBeTruthy();
175
+ const clickEvent = createEvent.click(rootLink, {
176
+ bubbles: true,
177
+ cancelable: true
178
+ });
179
+ fireEvent(rootLink, clickEvent);
180
+ expect(clickEvent.defaultPrevented).toBe(true);
181
+ });
182
+ it('stops propagation when the external link chip is clicked', async () => {
183
+ const user = userEvent.setup();
184
+ const onClick = vi.fn();
185
+ render(_jsx("div", { onClick: onClick, children: _jsx(HitBanner, { hit: createBannerHit(), layout: HitLayout.NORMAL }) }), { wrapper: createWrapper() });
186
+ await user.click(screen.getByRole('link', { name: 'Open source link' }));
187
+ expect(onClick).not.toHaveBeenCalled();
188
+ });
189
+ it('renders fallback link label and omits optional outline/rationale sections when missing', () => {
190
+ const hit = createBannerHit({
191
+ organization: { id: null, name: null },
192
+ event: { provider: null, created: '2024-01-01T00:00:00Z' },
193
+ howler: {
194
+ ...createBannerHit().howler,
195
+ rationale: null,
196
+ outline: {},
197
+ links: [{ href: 'https://example.com' }],
198
+ status: 'open'
199
+ }
200
+ });
201
+ renderHitBanner({ hit, layout: HitLayout.DENSE });
202
+ expect(screen.getByText('unknown')).toBeInTheDocument();
203
+ expect(screen.getByRole('link', { name: 'hit.header.link' })).toHaveAttribute('href', 'https://example.com');
204
+ expect(screen.queryByText('hit.header.rationale:')).not.toBeInTheDocument();
205
+ expect(screen.queryByText('hit.header.threat:')).not.toBeInTheDocument();
206
+ expect(screen.queryByText('hit.header.target:')).not.toBeInTheDocument();
207
+ expect(screen.queryByText('hit.header.summary:')).not.toBeInTheDocument();
208
+ });
209
+ });
@@ -19,6 +19,6 @@ const HitCard = ({ id, layout, readOnly = true, lazy = false, elevation, hit: _h
19
19
  if (!hit) {
20
20
  return _jsx(Skeleton, { variant: "rounded", height: "200px" });
21
21
  }
22
- return (_jsx(HowlerCard, { id: hit?.howler.id, tabIndex: 0, sx: { position: 'relative' }, elevation: elevation, children: _jsxs(CardContent, { children: [_jsx(HitBanner, { hit: hit, layout: layout, lazy: lazy }), _jsx(HitOutline, { hit: hit, layout: layout, lazy: lazy }), _jsx(HitLabels, { hit: hit, readOnly: readOnly })] }) }));
22
+ return (_jsx(HowlerCard, { id: hit?.howler.id, tabIndex: 0, sx: { position: 'relative' }, elevation: elevation, children: _jsxs(CardContent, { sx: { display: 'flex', flexDirection: 'column', alignItems: 'start' }, children: [_jsx(HitBanner, { hit: hit, layout: layout, lazy: lazy }), _jsx(HitOutline, { hit: hit, layout: layout, lazy: lazy }), _jsx(HitLabels, { hit: hit, readOnly: readOnly })] }) }));
23
23
  };
24
24
  export default memo(HitCard);
@@ -89,7 +89,7 @@ const HitLabels = ({ hit, readOnly = false }) => {
89
89
  }));
90
90
  }
91
91
  }, [hit]);
92
- return (_jsxs(Box, { sx: { py: 1 }, children: [_jsxs(Drawer, { open: openDrawer, onClose: () => setOpenDrawer(false), anchor: "right", PaperProps: { sx: { maxWidth: '90%', width: '500px' } }, children: [_jsx(Backdrop, { open: loading, sx: { position: 'absolute', zIndex: theme => theme.zIndex.drawer + 1 }, children: _jsx(CircularProgress, { color: "inherit" }) }), _jsxs(Stack, { direction: "column", spacing: 2, sx: { p: 2 }, children: [_jsx(Typography, { variant: "h4", children: t('hit.label.edit') }), _jsx(Box, { children: labels.map(label => {
92
+ return (_jsxs(Box, { children: [_jsxs(Drawer, { open: openDrawer, onClose: () => setOpenDrawer(false), anchor: "right", PaperProps: { sx: { maxWidth: '90%', width: '500px' } }, children: [_jsx(Backdrop, { open: loading, sx: { position: 'absolute', zIndex: theme => theme.zIndex.drawer + 1 }, children: _jsx(CircularProgress, { color: "inherit" }) }), _jsxs(Stack, { direction: "column", spacing: 2, sx: { p: 2 }, children: [_jsx(Typography, { variant: "h4", children: t('hit.label.edit') }), _jsx(Box, { children: labels.map(label => {
93
93
  const category = label.category.toLowerCase();
94
94
  return (_jsx(Tooltip, { title: t(`hit.label.category.${category}`), children: _jsx(Chip, { icon: LABEL_TYPES[category]?.icon ?? undefined, variant: "filled", size: "small", label: label.label, onDelete: () => deleteLabel(label), sx: [
95
95
  {
@@ -1,4 +1,5 @@
1
1
  import type { Hit } from '@cccsaurora/howler-ui/models/entities/generated/Hit';
2
+ import type { Template } from '@cccsaurora/howler-ui/models/entities/generated/Template';
2
3
  import type { WithMetadata } from '@cccsaurora/howler-ui/models/WithMetadata';
3
4
  import { HitLayout } from './HitLayout';
4
5
  export declare const DEFAULT_FIELDS: string[];
@@ -7,5 +8,6 @@ declare const _default: import("react").NamedExoticComponent<{
7
8
  lazy?: boolean;
8
9
  layout: HitLayout;
9
10
  forceAllFields?: boolean;
11
+ template?: Template;
10
12
  }>;
11
13
  export default _default;