@cccsaurora/howler-ui 3.2.0-dev.1786.1 → 3.2.0-dev.1794.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,93 +1,123 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Editor, useMonaco } from '@monaco-editor/react';
3
3
  import { useTheme } from '@mui/material';
4
- import { useAppTheme, useAppThemeBuilder } from '@tui/core';
5
4
  import { memo, useCallback, useEffect, useMemo } from 'react';
5
+ const toMonacoColor = (color) => {
6
+ const trimmedColor = color.trim();
7
+ const hexMatch = trimmedColor.match(/^#?([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i);
8
+ if (hexMatch) {
9
+ let hex = hexMatch[1] ?? '';
10
+ if (hex.length === 3 || hex.length === 4) {
11
+ hex = hex
12
+ .split('')
13
+ .map(character => character.repeat(2))
14
+ .join('');
15
+ }
16
+ return `#${hex.toUpperCase()}`;
17
+ }
18
+ const rgbMatch = trimmedColor.match(/^rgba?\((.*)\)$/i);
19
+ if (!rgbMatch) {
20
+ return trimmedColor;
21
+ }
22
+ const [channelValues = '', slashAlpha] = (rgbMatch[1] ?? '').split('/');
23
+ const channels = channelValues
24
+ .split(/[\s,]+/)
25
+ .filter(Boolean)
26
+ .map(channel => channel.trim());
27
+ const alpha = slashAlpha?.trim() ?? (channels.length > 3 ? channels.pop() : undefined);
28
+ if (channels.length !== 3 || !channels.every(channel => /^-?(?:\d+\.?\d*|\.\d+)%?$/.test(channel))) {
29
+ return trimmedColor;
30
+ }
31
+ const hexChannels = channels
32
+ .map(channel => {
33
+ const amount = Number.parseFloat(channel);
34
+ const value = channel.endsWith('%') ? (amount * 255) / 100 : amount;
35
+ return Math.round(Math.min(255, Math.max(0, value)))
36
+ .toString(16)
37
+ .padStart(2, '0');
38
+ })
39
+ .join('');
40
+ if (!alpha) {
41
+ return `#${hexChannels.toUpperCase()}`;
42
+ }
43
+ const alphaValue = Number.parseFloat(alpha);
44
+ if (/^-?(?:\d+\.?\d*|\.\d+)%?$/.test(alpha)) {
45
+ const normalizedAlpha = alpha.endsWith('%') ? alphaValue / 100 : alphaValue;
46
+ const alphaHex = Math.round(Math.min(1, Math.max(0, normalizedAlpha)) * 255)
47
+ .toString(16)
48
+ .padStart(2, '0');
49
+ return `#${hexChannels}${alphaHex}`.toUpperCase();
50
+ }
51
+ return trimmedColor;
52
+ };
53
+ const toMonacoTokenColor = (color) => toMonacoColor(color).replace(/^#/, '');
6
54
  const ThemedEditor = ({ beforeMount, options = {}, id, ...otherProps }) => {
7
- const { current: currentTheme, optionsOverride } = useAppTheme();
8
- const themeBuilder = useAppThemeBuilder();
9
- const { lightTheme, darkTheme } = useMemo(() => themeBuilder(currentTheme, optionsOverride), [themeBuilder, currentTheme, optionsOverride]);
10
55
  const theme = useTheme();
11
56
  const monaco = useMonaco();
12
- const _beforeMount = useCallback((_monaco) => {
13
- let lightBackground = lightTheme.palette.background.paper;
14
- // monaco doesn't like colours in the form #fff, with only three digits.
15
- if (lightBackground.startsWith('#') && lightBackground.length < 7) {
16
- lightBackground = lightBackground.replace(/(\w)/g, '$1$1');
17
- }
18
- _monaco.editor.defineTheme('howler', {
19
- base: 'vs',
20
- inherit: true,
21
- rules: [
22
- {
23
- token: 'handlebars',
24
- foreground: lightTheme.palette.warning.dark.toUpperCase().replaceAll('#', '')
25
- },
26
- {
27
- token: 'operator',
28
- foreground: lightTheme.palette.warning.light.toUpperCase().replaceAll('#', '')
29
- },
30
- {
31
- token: 'string.invalid',
32
- foreground: lightTheme.palette.error.main.toUpperCase().replaceAll('#', '')
33
- },
34
- {
35
- token: 'invalid',
36
- foreground: lightTheme.palette.error.main.toUpperCase().replaceAll('#', '')
37
- },
38
- {
39
- token: 'boolean',
40
- foreground: lightTheme.palette.success.main.toUpperCase().replaceAll('#', '')
41
- }
42
- ],
43
- colors: {
44
- 'editor.background': lightBackground
57
+ const monacoTheme = useMemo(() => ({
58
+ base: theme.palette.mode === 'light' ? 'vs' : 'vs-dark',
59
+ inherit: true,
60
+ rules: [
61
+ {
62
+ token: 'handlebars',
63
+ foreground: toMonacoTokenColor(theme.palette.warning.dark)
64
+ },
65
+ {
66
+ token: 'operator',
67
+ foreground: toMonacoTokenColor(theme.palette.warning.light)
68
+ },
69
+ {
70
+ token: 'string.invalid',
71
+ foreground: toMonacoTokenColor(theme.palette.error.main)
72
+ },
73
+ {
74
+ token: 'invalid',
75
+ foreground: toMonacoTokenColor(theme.palette.error.main)
76
+ },
77
+ {
78
+ token: 'boolean',
79
+ foreground: toMonacoTokenColor(theme.palette.success.main)
45
80
  }
46
- });
47
- let darkBackground = darkTheme.palette.background.paper;
48
- // monaco doesn't like colours in the form #fff, with only three digits.
49
- if (darkBackground.startsWith('#') && darkBackground.length < 7) {
50
- darkBackground = darkBackground.replace(/(\w)/g, '$1$1');
81
+ ],
82
+ colors: {
83
+ 'editor.background': toMonacoColor(theme.palette.background.paper),
84
+ 'editor.foreground': toMonacoColor(theme.palette.text.primary),
85
+ 'editorGutter.background': toMonacoColor(theme.palette.background.paper),
86
+ 'editorLineNumber.foreground': toMonacoColor(theme.palette.text.disabled),
87
+ 'editorLineNumber.activeForeground': toMonacoColor(theme.palette.text.secondary),
88
+ 'editorCursor.foreground': toMonacoColor(theme.palette.primary.main),
89
+ 'editor.selectionBackground': toMonacoColor(theme.palette.action.selected),
90
+ 'editor.inactiveSelectionBackground': toMonacoColor(theme.palette.action.hover),
91
+ 'editor.lineHighlightBackground': toMonacoColor(theme.palette.action.hover),
92
+ 'editorWhitespace.foreground': toMonacoColor(theme.palette.divider),
93
+ 'editorIndentGuide.background': toMonacoColor(theme.palette.divider),
94
+ 'editorIndentGuide.activeBackground': toMonacoColor(theme.palette.text.disabled),
95
+ 'editorWidget.background': toMonacoColor(theme.palette.background.paper),
96
+ 'editorWidget.border': toMonacoColor(theme.palette.divider),
97
+ 'editorSuggestWidget.background': toMonacoColor(theme.palette.background.paper),
98
+ 'editorSuggestWidget.border': toMonacoColor(theme.palette.divider),
99
+ 'editorSuggestWidget.selectedBackground': toMonacoColor(theme.palette.action.selected),
100
+ 'editorHoverWidget.background': toMonacoColor(theme.palette.background.paper),
101
+ 'editorHoverWidget.border': toMonacoColor(theme.palette.divider),
102
+ 'editorOverviewRuler.border': toMonacoColor(theme.palette.divider),
103
+ 'scrollbarSlider.background': toMonacoColor(theme.palette.action.hover),
104
+ 'scrollbarSlider.hoverBackground': toMonacoColor(theme.palette.action.selected),
105
+ 'scrollbarSlider.activeBackground': toMonacoColor(theme.palette.action.active)
51
106
  }
52
- _monaco.editor.defineTheme('howler-dark', {
53
- base: 'vs-dark',
54
- inherit: true,
55
- rules: [
56
- {
57
- token: 'handlebars',
58
- foreground: darkTheme.palette.warning.dark.toUpperCase().replaceAll('#', '')
59
- },
60
- {
61
- token: 'operator',
62
- foreground: darkTheme.palette.warning.light.toUpperCase().replaceAll('#', '')
63
- },
64
- {
65
- token: 'string.invalid',
66
- foreground: darkTheme.palette.error.main.toUpperCase().replaceAll('#', '')
67
- },
68
- {
69
- token: 'invalid',
70
- foreground: darkTheme.palette.error.main.toUpperCase().replaceAll('#', '')
71
- },
72
- {
73
- token: 'boolean',
74
- foreground: darkTheme.palette.success.main.toUpperCase().replaceAll('#', '')
75
- }
76
- ],
77
- colors: {
78
- 'editor.background': darkBackground
79
- }
80
- });
107
+ }), [theme]);
108
+ const _beforeMount = useCallback((_monaco) => {
109
+ _monaco.editor.defineTheme('howler', monacoTheme);
81
110
  _monaco.languages.register({ id: 'lucene' });
82
111
  _monaco.languages.register({ id: 'eql' });
83
112
  beforeMount?.(_monaco);
84
- }, [beforeMount, lightTheme, darkTheme]);
113
+ }, [beforeMount, monacoTheme]);
85
114
  useEffect(() => {
86
115
  if (!monaco) {
87
116
  return;
88
117
  }
89
- monaco.editor.setTheme(theme.palette.mode === 'light' ? 'howler' : 'howler-dark');
90
- }, [monaco, theme.palette.background.paper, theme.palette.mode]);
118
+ monaco.editor.defineTheme('howler', monacoTheme);
119
+ monaco.editor.setTheme('howler');
120
+ }, [monaco, monacoTheme]);
91
121
  const _options = useMemo(() => ({
92
122
  automaticLayout: true,
93
123
  minimap: { enabled: false },
@@ -99,6 +129,6 @@ const ThemedEditor = ({ beforeMount, options = {}, id, ...otherProps }) => {
99
129
  },
100
130
  ...options
101
131
  }), [options]);
102
- return (_jsx(Editor, { ...otherProps, wrapperProps: { id }, theme: theme.palette.mode === 'light' ? 'howler' : 'howler-dark', beforeMount: _beforeMount, options: _options }));
132
+ return _jsx(Editor, { ...otherProps, wrapperProps: { id }, theme: "howler", beforeMount: _beforeMount, options: _options });
103
133
  };
104
134
  export default memo(ThemedEditor);
@@ -1,13 +1,28 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  /// <reference types="vitest" />
3
3
  import { render } from '@testing-library/react';
4
- import { describe, expect, it, vi } from 'vitest';
4
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
5
5
  const mockDefineTheme = vi.hoisted(() => vi.fn());
6
6
  const mockRegisterLanguage = vi.hoisted(() => vi.fn());
7
7
  const mockSetTheme = vi.hoisted(() => vi.fn());
8
8
  const capturedProps = vi.hoisted(() => ({ current: null }));
9
- let themeMode = 'light';
9
+ const createPalette = (mode = 'light', paper = mode === 'light' ? '#fff' : '#111', primary = mode === 'light' ? '#0055aa' : '#268bd2', foreground = mode === 'light' ? '#202020' : '#eee8d5', warningDark = '#abc') => ({
10
+ mode,
11
+ background: { paper },
12
+ primary: { main: primary },
13
+ text: { primary: foreground, secondary: '#777777', disabled: '#aaaaaa' },
14
+ divider: '#dddddd',
15
+ action: {
16
+ selected: 'rgba(10, 20, 30, 0.2)',
17
+ hover: 'rgba(10, 20, 30, 0.1)',
18
+ active: 'rgba(10, 20, 30, 0.3)'
19
+ },
20
+ warning: { dark: warningDark, light: '#def' },
21
+ error: { main: '#123456' },
22
+ success: { main: '#654321' }
23
+ });
10
24
  let monacoValue = null;
25
+ let themePalette = createPalette();
11
26
  vi.mock('@monaco-editor/react', () => ({
12
27
  Editor: (props) => {
13
28
  capturedProps.current = props;
@@ -16,51 +31,67 @@ vi.mock('@monaco-editor/react', () => ({
16
31
  useMonaco: () => monacoValue
17
32
  }));
18
33
  vi.mock('@mui/material', () => ({
19
- useTheme: () => ({ palette: { mode: themeMode, background: { paper: themeMode === 'light' ? '#fff' : '#111' } } })
20
- }));
21
- vi.mock('@tui/core', () => ({
22
- useAppTheme: () => ({ current: 'default', optionsOverride: { dense: true } }),
23
- useAppThemeBuilder: () => () => ({
24
- lightTheme: {
25
- palette: {
26
- background: { paper: '#fff' },
27
- warning: { dark: '#abc', light: '#def' },
28
- error: { main: '#123456' },
29
- success: { main: '#654321' }
30
- }
31
- },
32
- darkTheme: {
33
- palette: {
34
- background: { paper: '#111' },
35
- warning: { dark: '#aaa', light: '#bbb' },
36
- error: { main: '#222222' },
37
- success: { main: '#333333' }
38
- }
39
- }
40
- })
34
+ useTheme: () => ({ palette: themePalette })
41
35
  }));
42
36
  import ThemedEditor from './ThemedEditor';
43
37
  describe('ThemedEditor', () => {
38
+ beforeEach(() => {
39
+ themePalette = createPalette();
40
+ monacoValue = null;
41
+ vi.clearAllMocks();
42
+ });
44
43
  it('defines custom monaco themes and merges editor options', () => {
45
- monacoValue = { editor: { setTheme: mockSetTheme } };
44
+ monacoValue = { editor: { defineTheme: mockDefineTheme, setTheme: mockSetTheme } };
46
45
  render(_jsx(ThemedEditor, { id: "the-editor", options: { readOnly: true }, beforeMount: vi.fn(), value: "x" }));
47
46
  const fakeMonaco = {
48
47
  editor: { defineTheme: mockDefineTheme },
49
48
  languages: { register: mockRegisterLanguage }
50
49
  };
51
50
  capturedProps.current.beforeMount(fakeMonaco);
52
- expect(mockDefineTheme).toHaveBeenCalledWith('howler', expect.objectContaining({ colors: { 'editor.background': '#ffffff' } }));
53
- expect(mockDefineTheme).toHaveBeenCalledWith('howler-dark', expect.objectContaining({ colors: { 'editor.background': '#111111' } }));
51
+ expect(mockDefineTheme).toHaveBeenCalledWith('howler', expect.objectContaining({
52
+ base: 'vs',
53
+ colors: expect.objectContaining({ 'editor.background': '#FFFFFF', 'editor.foreground': '#202020' })
54
+ }));
54
55
  expect(mockRegisterLanguage).toHaveBeenCalledWith({ id: 'lucene' });
55
56
  expect(capturedProps.current.wrapperProps).toEqual({ id: 'the-editor' });
56
57
  expect(capturedProps.current.options).toMatchObject({ readOnly: true, automaticLayout: true });
57
58
  expect(mockSetTheme).toHaveBeenCalledWith('howler');
58
59
  });
59
- it('switches to the dark theme when the mui theme changes', () => {
60
- themeMode = 'dark';
61
- monacoValue = { editor: { setTheme: mockSetTheme } };
60
+ it('converts RGB palette colors to Monaco token colors', () => {
61
+ themePalette = createPalette('light', '#fff', '#0055aa', '#202020', 'RGB(126, 95, 0)');
62
+ monacoValue = { editor: { defineTheme: mockDefineTheme, setTheme: mockSetTheme } };
62
63
  render(_jsx(ThemedEditor, { value: "x" }));
63
- expect(capturedProps.current.theme).toBe('howler-dark');
64
- expect(mockSetTheme).toHaveBeenCalledWith('howler-dark');
64
+ capturedProps.current.beforeMount({
65
+ editor: { defineTheme: mockDefineTheme },
66
+ languages: { register: mockRegisterLanguage }
67
+ });
68
+ expect(mockDefineTheme).toHaveBeenCalledWith('howler', expect.objectContaining({
69
+ rules: expect.arrayContaining([expect.objectContaining({ token: 'handlebars', foreground: '7E5F00' })])
70
+ }));
71
+ });
72
+ it('uses and updates colors from the active app theme', () => {
73
+ themePalette = createPalette('dark', '#002B36');
74
+ monacoValue = { editor: { defineTheme: mockDefineTheme, setTheme: mockSetTheme } };
75
+ const { rerender } = render(_jsx(ThemedEditor, { value: "x" }));
76
+ expect(capturedProps.current.theme).toBe('howler');
77
+ expect(mockDefineTheme).toHaveBeenLastCalledWith('howler', expect.objectContaining({
78
+ base: 'vs-dark',
79
+ colors: expect.objectContaining({
80
+ 'editor.background': '#002B36',
81
+ 'editor.foreground': '#EEE8D5',
82
+ 'editor.selectionBackground': '#0A141E33'
83
+ })
84
+ }));
85
+ expect(mockSetTheme).toHaveBeenCalledWith('howler');
86
+ themePalette = createPalette('dark', '#101010', '#cc5500', '#f0f0f0');
87
+ rerender(_jsx(ThemedEditor, { value: "y" }));
88
+ expect(mockDefineTheme).toHaveBeenLastCalledWith('howler', expect.objectContaining({
89
+ base: 'vs-dark',
90
+ colors: expect.objectContaining({
91
+ 'editor.background': '#101010',
92
+ 'editor.foreground': '#F0F0F0',
93
+ 'editorCursor.foreground': '#CC5500'
94
+ })
95
+ }));
65
96
  });
66
97
  });
@@ -15,6 +15,15 @@ import HitTimestamp from './elements/HitTimestamp';
15
15
  import HitBannerTooltip from './HitBannerTooltip';
16
16
  import { HitLayout } from './HitLayout';
17
17
  import RelatedRecords from './related/RelatedRecords';
18
+ const isHttpUrl = (value) => {
19
+ try {
20
+ const { protocol } = new URL(value);
21
+ return protocol === 'http:' || protocol === 'https:';
22
+ }
23
+ catch {
24
+ return false;
25
+ }
26
+ };
18
27
  const Wrapper = ({ compressed, hit, textVariant, i18nKey, value, field, ...typographyProps }) => {
19
28
  const { t } = useTranslation();
20
29
  const children = (_jsxs(Stack, { direction: "row", spacing: 1, flex: 1, sx: { lineHeight: '20px', '& .iconify': { maxHeight: '20px' } }, children: [_jsxs(Typography, { variant: textVariant, noWrap: compressed, fontWeight: "bold", textOverflow: compressed ? 'ellipsis' : 'wrap', ...typographyProps, sx: [
@@ -30,8 +39,20 @@ const HitBanner = ({ hit, lazy = false, layout = HitLayout.NORMAL, showAssigned
30
39
  const compressed = useMemo(() => layout === HitLayout.DENSE, [layout]);
31
40
  const textVariant = useMemo(() => (layout === HitLayout.COMFY ? 'body1' : 'caption'), [layout]);
32
41
  const providerColor = getProviderColor(hit?.event?.provider);
33
- return (_jsx(Box, { sx: { width: '100%', ml: 0, overflow: 'hidden', color: 'text.primary' }, children: _jsxs(Stack, { spacing: layout !== HitLayout.COMFY ? 0.25 : 1, children: [_jsxs(Stack, { direction: "row", spacing: 0.5, 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) > 0 && _jsx(RelatedRecords, { hit: hit }), howlerPluginStore.plugins.flatMap(plugin => (_jsx(Fragment, { children: pluginStore.executeFunction(`${plugin}.status`, { hit, layout }) }, plugin)))] }), hit.howler?.rationale && (_jsx(Wrapper, { fontWeight: "bold", color: getEscalationColor(hit.howler.escalation) + '.main', compressed: compressed, hit: hit, textVariant: textVariant, i18nKey: "hit.header.rationale", value: hit.howler.rationale, field: "howler.rationale" })), hit.howler?.outline && (_jsxs(_Fragment, { children: [hit.howler.outline.threat && (_jsx(Wrapper, { compressed: compressed, hit: hit, textVariant: textVariant, i18nKey: "hit.header.threat", value: hit.howler.outline.threat, field: "howler.outline.threat" })), hit.howler.outline.target && (_jsx(Wrapper, { compressed: compressed, hit: hit, textVariant: textVariant, i18nKey: "hit.header.target", value: hit.howler.outline.target, field: "howler.outline.target" })), (hit.howler.outline.indicators?.length ?? 0) > 0 && (_jsxs(Stack, { direction: "row", spacing: layout !== HitLayout.COMFY ? 0.25 : 1, children: [_jsxs(Typography, { component: "span", variant: textVariant, fontWeight: "bold", pr: 1, children: [t('hit.header.indicators'), ":"] }), _jsx(Grid, { container: true, spacing: 0.5, children: uniq(hit.howler.outline.indicators ?? []).map((_indicator, index) => {
34
- return (_jsx(Grid, { children: _jsxs(Stack, { direction: "row", children: [_jsx(PluginTypography, { context: "indicators", variant: textVariant, value: _indicator, children: _indicator }), index < (hit.howler.outline?.indicators?.length ?? 0) - 1 && (_jsx(Typography, { variant: textVariant, children: ',' }))] }) }, _indicator));
42
+ const indicators = uniq(hit.howler.outline?.indicators ?? []);
43
+ return (_jsx(Box, { sx: { width: '100%', ml: 0, overflow: 'hidden', color: 'text.primary' }, children: _jsxs(Stack, { spacing: layout !== HitLayout.COMFY ? 0.25 : 1, children: [_jsxs(Stack, { direction: "row", spacing: 0.5, 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) > 0 && _jsx(RelatedRecords, { hit: hit }), howlerPluginStore.plugins.flatMap(plugin => (_jsx(Fragment, { children: pluginStore.executeFunction(`${plugin}.status`, { hit, layout }) }, plugin)))] }), hit.howler?.rationale && (_jsx(Wrapper, { fontWeight: "bold", color: getEscalationColor(hit.howler.escalation) + '.main', compressed: compressed, hit: hit, textVariant: textVariant, i18nKey: "hit.header.rationale", value: hit.howler.rationale, field: "howler.rationale" })), hit.howler?.outline && (_jsxs(_Fragment, { children: [hit.howler.outline.threat && (_jsx(Wrapper, { compressed: compressed, hit: hit, textVariant: textVariant, i18nKey: "hit.header.threat", value: hit.howler.outline.threat, field: "howler.outline.threat" })), hit.howler.outline.target && (_jsx(Wrapper, { compressed: compressed, hit: hit, textVariant: textVariant, i18nKey: "hit.header.target", value: hit.howler.outline.target, field: "howler.outline.target" })), indicators.length > 0 && (_jsxs(Stack, { direction: "row", spacing: layout !== HitLayout.COMFY ? 0.25 : 1, sx: { minWidth: 0 }, children: [_jsxs(Typography, { component: "span", variant: textVariant, fontWeight: "bold", pr: 1, children: [t('hit.header.indicators'), ":"] }), _jsx(Grid, { container: true, spacing: 0.5, sx: { flex: 1, minWidth: 0 }, children: indicators.map((indicator, index) => {
44
+ const isUrl = isHttpUrl(indicator);
45
+ const indicatorValue = (_jsx(Box, { tabIndex: isUrl ? 0 : undefined, sx: { minWidth: 0, maxWidth: '100%' }, children: _jsx(PluginTypography, { context: "indicators", variant: textVariant, value: indicator, sx: isUrl
46
+ ? {
47
+ display: '-webkit-box',
48
+ overflow: 'hidden',
49
+ overflowWrap: 'anywhere',
50
+ textOverflow: 'ellipsis',
51
+ WebkitBoxOrient: 'vertical',
52
+ WebkitLineClamp: 2
53
+ }
54
+ : { overflowWrap: 'anywhere' }, children: indicator }) }));
55
+ return (_jsx(Grid, { sx: { flexBasis: '100%', minWidth: 0, maxWidth: '100%' }, children: _jsxs(Stack, { direction: "row", sx: { minWidth: 0 }, children: [isUrl ? _jsx(Tooltip, { title: indicator, children: indicatorValue }) : indicatorValue, index < indicators.length - 1 && _jsx(Typography, { variant: textVariant, children: ',' })] }) }, indicator));
35
56
  }) })] })), hit.howler.outline.summary && (_jsx(Wrapper, { compressed: compressed, hit: hit, textVariant: textVariant, i18nKey: "hit.header.summary", value: hit.howler.outline.summary, 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 => {
36
57
  e.stopPropagation();
37
58
  } }))] }))] }) }));
@@ -130,6 +130,37 @@ describe('HitBanner', () => {
130
130
  expect(screen.getByText('Summary value')).toBeInTheDocument();
131
131
  expect(screen.getByRole('link', { name: 'Open source link' })).toHaveAttribute('href', 'https://example.com');
132
132
  });
133
+ it('truncates HTTP indicator URLs and makes their tooltip keyboard reachable', async () => {
134
+ const user = userEvent.setup();
135
+ const indicator = 'https://example.example.com/v2/r03/__https://example.example.com/sites/security/documents/very-long-document-name?query=very-long-value-example';
136
+ const hit = createBannerHit({
137
+ howler: {
138
+ ...createBannerHit().howler,
139
+ outline: { ...createBannerHit().howler.outline, indicators: [indicator] }
140
+ }
141
+ });
142
+ renderHitBanner({ hit });
143
+ const indicatorText = screen.getByText(indicator);
144
+ expect(indicatorText).toHaveStyle({ WebkitLineClamp: '2', overflow: 'hidden', textOverflow: 'ellipsis' });
145
+ const indicatorWrapper = indicatorText.closest('[tabindex="0"]');
146
+ expect(indicatorWrapper).toBeInTheDocument();
147
+ await user.tab();
148
+ expect(indicatorWrapper).toHaveFocus();
149
+ await user.hover(indicatorText);
150
+ expect(await screen.findByRole('tooltip')).toHaveTextContent(indicator);
151
+ });
152
+ it('wraps non-URL indicators and does not add a tooltip', () => {
153
+ const indicator = 'a-very-long-unbroken-indicator-value';
154
+ const hit = createBannerHit({
155
+ howler: {
156
+ ...createBannerHit().howler,
157
+ outline: { ...createBannerHit().howler.outline, indicators: [indicator] }
158
+ }
159
+ });
160
+ renderHitBanner({ hit });
161
+ expect(screen.getByText(indicator)).toHaveStyle({ overflowWrap: 'anywhere' });
162
+ expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
163
+ });
133
164
  it.each(['in-progress', 'on-hold'])('renders the status chip for %s', status => {
134
165
  const hit = createBannerHit({ howler: { ...createBannerHit().howler, status } });
135
166
  renderHitBanner({ hit });
package/package.json CHANGED
@@ -97,7 +97,7 @@
97
97
  "url": "https://github.com/CybercentreCanada/howler"
98
98
  },
99
99
  "type": "module",
100
- "version": "3.2.0-dev.1786.1",
100
+ "version": "3.2.0-dev.1794.1",
101
101
  "exports": {
102
102
  "./i18n": "./i18n.js",
103
103
  "./index.css": "./index.css",