@cccsaurora/howler-ui 3.2.0-dev.1769.1 → 3.2.0-dev.1773.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,7 +1,9 @@
1
1
  import type { Dossier } from '@cccsaurora/howler-ui/models/entities/generated/Dossier';
2
+ import type { Pivot } from '@cccsaurora/howler-ui/models/entities/generated/Pivot';
2
3
  import type { FC } from 'react';
3
4
  declare const PivotTooltip: FC<{
4
5
  dossier: Dossier;
6
+ pivot: Pivot;
5
7
  resolvedUrl: string;
6
8
  }>;
7
9
  export default PivotTooltip;
@@ -1,9 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Link, Typography } from '@mui/material';
3
3
  import { useTranslation } from 'react-i18next';
4
- const PivotTooltip = ({ dossier, resolvedUrl }) => {
4
+ const PivotTooltip = ({ dossier, pivot, resolvedUrl }) => {
5
5
  const dossierUrl = `/dossiers/${dossier.dossier_id}/edit?tab=leads&query=${encodeURIComponent(dossier.query ?? '')}`;
6
+ const description = pivot.description?.trim();
6
7
  const { t } = useTranslation();
7
- return (_jsxs(Box, { sx: { maxWidth: 300 }, children: [_jsx(Typography, { variant: "subtitle2", children: dossier.title }), _jsx(Typography, { variant: "body2", color: "text.secondary", children: dossier.owner }), _jsx(Typography, { variant: "body2", sx: { mt: 2 }, children: dossier.leads?.[0]?.content?.slice(0, 120) ?? t('pivot.description.none') }), _jsxs(Box, { sx: { mt: 2, wordBreak: 'break-all' }, children: [_jsx(Typography, { variant: "caption", display: "block", children: t('pivot.url') }), _jsx(Link, { href: resolvedUrl, target: "_blank", rel: "noopener noreferrer", underline: "hover", children: resolvedUrl })] }), _jsx(Box, { sx: { mt: 2 }, children: _jsx(Link, { href: dossierUrl, target: "_blank", rel: "noopener noreferrer", underline: "hover", children: t('pivot.dossier.open') }) })] }));
8
+ return (_jsxs(Box, { sx: { maxWidth: 300 }, children: [_jsx(Typography, { variant: "subtitle2", children: dossier.title }), _jsx(Typography, { variant: "body2", color: "text.secondary", children: dossier.owner }), description && (_jsxs(Box, { sx: { mt: 2 }, children: [_jsx(Typography, { variant: "caption", display: "block", children: t('pivot.description.header') }), _jsx(Typography, { variant: "body2", children: description.slice(0, 120) })] })), _jsxs(Box, { sx: { mt: 2, wordBreak: 'break-all' }, children: [_jsx(Typography, { variant: "caption", display: "block", children: t('pivot.url') }), _jsx(Link, { href: resolvedUrl, target: "_blank", rel: "noopener noreferrer", underline: "hover", children: resolvedUrl })] }), _jsx(Box, { sx: { mt: 2 }, children: _jsx(Link, { href: dossierUrl, target: "_blank", rel: "noopener noreferrer", underline: "hover", children: t('pivot.dossier.open') }) })] }));
8
9
  };
9
10
  export default PivotTooltip;
@@ -0,0 +1,104 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render, screen, within } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { BrowserRouter } from 'react-router';
5
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
6
+ import PivotLink from './pivots/PivotLink';
7
+ const executeFunction = vi.hoisted(() => vi.fn());
8
+ vi.mock('react-pluggable', async (importOriginal) => ({
9
+ ...(await importOriginal()),
10
+ usePluginStore: () => ({ executeFunction })
11
+ }));
12
+ vi.mock('components/elements/display/handlebars/helpers', () => ({
13
+ useHelpers: () => []
14
+ }));
15
+ vi.mock('components/elements/display/HowlerCard', () => ({
16
+ default: ({ children }) => _jsx("div", { children: children })
17
+ }));
18
+ vi.mock('plugins/store', () => ({
19
+ default: { pivotFormats: ['plugin'] }
20
+ }));
21
+ vi.mock('./RelatedIcon', () => ({ default: () => null }));
22
+ vi.mock('react-i18next', () => ({
23
+ useTranslation: () => ({ i18n: { language: 'en' }, t: (key) => key })
24
+ }));
25
+ describe('PivotLink', () => {
26
+ const resolvedUrl = 'https://example.com/alert';
27
+ const dossier = {
28
+ dossier_id: 'test-dossier',
29
+ title: 'Test Dossier',
30
+ owner: 'test-owner',
31
+ query: 'howler.id:test-hit',
32
+ leads: [{ content: 'Test lead description' }]
33
+ };
34
+ const hit = { howler: { id: 'test-hit' } };
35
+ beforeEach(() => {
36
+ executeFunction.mockReset();
37
+ executeFunction.mockReturnValue(_jsx("button", { children: "Plugin pivot" }));
38
+ });
39
+ it.each(['link', 'plugin'])('shows the dossier and pivot descriptions for a %s pivot', async (format) => {
40
+ const user = userEvent.setup();
41
+ const pivot = {
42
+ format,
43
+ value: resolvedUrl,
44
+ description: 'Pivot-specific description',
45
+ label: { en: 'Link pivot', fr: 'Link pivot' },
46
+ mappings: []
47
+ };
48
+ render(_jsx(BrowserRouter, { children: _jsx(PivotLink, { pivot: pivot, hit: hit, dossier: dossier }) }));
49
+ await user.hover(format === 'link'
50
+ ? screen.getByRole('link', { name: 'Link pivot' })
51
+ : screen.getByRole('button', { name: 'Plugin pivot' }));
52
+ const tooltip = within(await screen.findByRole('tooltip'));
53
+ const expectedUrl = format === 'link' ? resolvedUrl : '/dossier/test-dossier';
54
+ expect(tooltip.getByText('Test Dossier')).toBeInTheDocument();
55
+ expect(tooltip.getByText('test-owner')).toBeInTheDocument();
56
+ expect(tooltip.getByText('pivot.description.header')).toBeInTheDocument();
57
+ expect(tooltip.getByText('Pivot-specific description')).toBeInTheDocument();
58
+ expect(tooltip.getByRole('link', { name: expectedUrl })).toHaveAttribute('href', expectedUrl);
59
+ expect(tooltip.getByRole('link', { name: 'pivot.dossier.open' })).toHaveAttribute('href', '/dossiers/test-dossier/edit?tab=leads&query=howler.id%3Atest-hit');
60
+ });
61
+ it('shows the description inline for a menu-item link pivot', () => {
62
+ const pivot = {
63
+ format: 'link',
64
+ value: resolvedUrl,
65
+ description: ' Pivot-specific description ',
66
+ label: { en: 'Link pivot', fr: 'Link pivot' },
67
+ mappings: []
68
+ };
69
+ render(_jsx(BrowserRouter, { children: _jsx(PivotLink, { pivot: pivot, hit: hit, dossier: dossier, variant: "menu-item" }) }));
70
+ const menuItem = within(screen.getByRole('menuitem'));
71
+ expect(menuItem.getByText('Pivot-specific description')).toBeInTheDocument();
72
+ expect(menuItem.getByText('Test Dossier • test-owner')).toBeInTheDocument();
73
+ expect(menuItem.getByText(resolvedUrl)).toBeInTheDocument();
74
+ expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
75
+ });
76
+ it.each([undefined, '', ' '])('omits the menu-item description when it is %j', description => {
77
+ const pivot = {
78
+ format: 'link',
79
+ value: resolvedUrl,
80
+ description,
81
+ label: { en: 'Link pivot', fr: 'Link pivot' },
82
+ mappings: []
83
+ };
84
+ render(_jsx(BrowserRouter, { children: _jsx(PivotLink, { pivot: pivot, hit: hit, dossier: dossier, variant: "menu-item" }) }));
85
+ const menuItem = screen.getByRole('menuitem');
86
+ expect(within(menuItem).getByText('Test Dossier • test-owner')).toBeInTheDocument();
87
+ expect(within(menuItem).getByText(resolvedUrl)).toBeInTheDocument();
88
+ expect(menuItem.querySelectorAll('.MuiTypography-caption')).toHaveLength(2);
89
+ });
90
+ it('omits the description header when the pivot description is blank', async () => {
91
+ const user = userEvent.setup();
92
+ const pivot = {
93
+ format: 'link',
94
+ value: resolvedUrl,
95
+ description: ' ',
96
+ label: { en: 'Link pivot', fr: 'Link pivot' },
97
+ mappings: []
98
+ };
99
+ render(_jsx(BrowserRouter, { children: _jsx(PivotLink, { pivot: pivot, hit: hit, dossier: dossier }) }));
100
+ await user.hover(screen.getByRole('link', { name: 'Link pivot' }));
101
+ const tooltip = within(await screen.findByRole('tooltip'));
102
+ expect(tooltip.queryByText('pivot.description.header')).not.toBeInTheDocument();
103
+ });
104
+ });
@@ -12,13 +12,14 @@ import { usePluginStore } from 'react-pluggable';
12
12
  import RelatedLink from '../RelatedLink';
13
13
  const PivotLink = ({ pivot, hit, compact = false, dossier, variant = 'card', onNavigate }) => {
14
14
  const { i18n } = useTranslation();
15
+ const description = pivot.description?.trim();
15
16
  const helpers = useHelpers({ async: false, components: false });
16
17
  const pluginStore = usePluginStore();
17
18
  const resolvedUrl = useMemo(() => pivot.format === 'link'
18
19
  ? resolvePivotUrl(pivot, hit, helpers) || `/dossier/${dossier.dossier_id}`
19
20
  : `/dossier/${dossier.dossier_id}`, [dossier.dossier_id, helpers, hit, pivot]);
20
21
  if (pivot.format === 'link') {
21
- return (_jsx(RelatedLink, { title: pivot.label?.[i18n.language] ?? pivot.value ?? '', href: resolvedUrl, icon: pivot.icon, target: "_blank", rel: "noopener noreferrer", compact: compact, dense: variant === 'menu-item', secondary: variant === 'menu-item' ? (_jsxs(_Fragment, { children: [_jsx(Typography, { variant: "caption", display: "block", color: "text.secondary", noWrap: true, children: [dossier.title, dossier.owner].filter(Boolean).join(' • ') }), _jsx(Typography, { variant: "caption", display: "block", color: "text.secondary", noWrap: true, sx: { maxWidth: 260 }, children: resolvedUrl })] })) : undefined, tooltip: variant === 'menu-item' ? undefined : _jsx(PivotTooltip, { dossier: dossier, resolvedUrl: resolvedUrl }), menuItem: variant === 'menu-item', onNavigate: onNavigate }));
22
+ return (_jsx(RelatedLink, { title: pivot.label?.[i18n.language] ?? pivot.value ?? '', href: resolvedUrl, icon: pivot.icon, target: "_blank", rel: "noopener noreferrer", compact: compact, dense: variant === 'menu-item', secondary: variant === 'menu-item' ? (_jsxs(_Fragment, { children: [_jsx(Typography, { variant: "caption", display: "block", color: "text.secondary", noWrap: true, children: [dossier.title, dossier.owner].filter(Boolean).join(' • ') }), description && (_jsx(Typography, { variant: "caption", display: "block", color: "text.secondary", noWrap: true, sx: { maxWidth: 260 }, children: description })), _jsx(Typography, { variant: "caption", display: "block", color: "text.secondary", noWrap: true, sx: { maxWidth: 260 }, children: resolvedUrl })] })) : undefined, tooltip: variant === 'menu-item' ? undefined : (_jsx(PivotTooltip, { dossier: dossier, pivot: pivot, resolvedUrl: resolvedUrl })), menuItem: variant === 'menu-item', onNavigate: onNavigate }));
22
23
  }
23
24
  const pluginPivot = howlerPluginStore.pivotFormats.includes(pivot.format ?? '')
24
25
  ? pluginStore.executeFunction(`pivot.${pivot.format}`, { pivot, hit, compact, variant, onNavigate })
@@ -27,7 +28,7 @@ const PivotLink = ({ pivot, hit, compact = false, dossier, variant = 'card', onN
27
28
  if (variant === 'menu-item') {
28
29
  return pluginPivot;
29
30
  }
30
- return (_jsx(Tooltip, { title: _jsx(PivotTooltip, { dossier: dossier, resolvedUrl: resolvedUrl }), children: _jsx(Box, { component: "span", sx: { display: 'inline-flex' }, children: pluginPivot }) }));
31
+ return (_jsx(Tooltip, { title: _jsx(PivotTooltip, { dossier: dossier, pivot: pivot, resolvedUrl: resolvedUrl }), children: _jsx(Box, { component: "span", sx: { display: 'inline-flex' }, children: pluginPivot }) }));
31
32
  }
32
33
  if (variant === 'menu-item') {
33
34
  return (_jsxs(Box, { role: "menuitem", "aria-disabled": "true", tabIndex: -1, sx: { display: 'flex', alignItems: 'center', gap: 1, px: 1, py: 0.5 }, children: [_jsx(ErrorOutline, { color: "error", fontSize: "small" }), _jsx(Typography, { noWrap: true, children: `Missing Pivot Implementation ${pivot.format}` })] }));
@@ -122,7 +122,7 @@ const PivotForm = ({ dossier, setDossier, loading }) => {
122
122
  if (reason === 'input') {
123
123
  fetchGroupSuggestions(value);
124
124
  }
125
- }, renderInput: params => (_jsx(TextField, { ...params, id: "dossier-group", label: t('route.pivots.groups.label'), size: "small", fullWidth: true, error: !!groupError, onFocus: () => fetchGroupSuggestions(pivot?.group ?? '') })) }), _jsx(Typography, { variant: "caption", color: "text.secondary", sx: { mt: `${theme.spacing(0.5)} !important` }, children: groupError ? t(groupError) : t('route.dossiers.pivot.explanation') }), _jsxs(Stack, { direction: "row", spacing: 2, children: [_jsx(TextField, { size: "small", label: t('route.dossiers.manager.pivot.label.en'), disabled: !pivot, value: pivot?.label?.en ?? '', fullWidth: true, onChange: ev => update({ label: { en: ev.target.value } }) }), _jsx(TextField, { size: "small", label: t('route.dossiers.manager.pivot.label.fr'), disabled: !pivot, value: pivot?.label?.fr ?? '', fullWidth: true, onChange: ev => update({ label: { fr: ev.target.value } }) })] }), _jsx(Autocomplete, { disabled: !pivot, options: ['link', ...howlerPluginStore.pivotFormats], renderInput: params => (_jsx(TextField, { ...params, size: "small", label: t('route.dossiers.manager.pivot.format') })), value: pivot?.format ?? null, onChange: (_ev, format) => update({ format: format ?? undefined, value: '', mappings: [] }) }), !!pivot?.format &&
125
+ }, renderInput: params => (_jsx(TextField, { ...params, id: "dossier-group", label: t('route.pivots.groups.label'), size: "small", fullWidth: true, error: !!groupError, onFocus: () => fetchGroupSuggestions(pivot?.group ?? '') })) }), _jsx(Typography, { variant: "caption", color: "text.secondary", sx: { mt: `${theme.spacing(0.5)} !important` }, children: groupError ? t(groupError) : t('route.dossiers.pivot.explanation') }), _jsx(TextField, { size: "small", multiline: true, label: t('tooltip.pivot.description'), disabled: !pivot, value: pivot?.description ?? '', fullWidth: true, onChange: ev => update({ description: ev.target.value }) }), _jsxs(Stack, { direction: "row", spacing: 2, children: [_jsx(TextField, { size: "small", label: t('route.dossiers.manager.pivot.label.en'), disabled: !pivot, value: pivot?.label?.en ?? '', fullWidth: true, onChange: ev => update({ label: { en: ev.target.value } }) }), _jsx(TextField, { size: "small", label: t('route.dossiers.manager.pivot.label.fr'), disabled: !pivot, value: pivot?.label?.fr ?? '', fullWidth: true, onChange: ev => update({ label: { fr: ev.target.value } }) })] }), _jsx(Autocomplete, { disabled: !pivot, options: ['link', ...howlerPluginStore.pivotFormats], renderInput: params => (_jsx(TextField, { ...params, size: "small", label: t('route.dossiers.manager.pivot.format') })), value: pivot?.format ?? null, onChange: (_ev, format) => update({ format: format ?? undefined, value: '', mappings: [] }) }), !!pivot?.format &&
126
126
  (pivot.format === 'link' ? (_jsx(LinkForm, { pivot: pivot, update: update })) : (pluginStore.executeFunction(`pivot.${pivot.format}.form`, { pivot, update })))] })] }) }));
127
127
  };
128
128
  export default PivotForm;
@@ -78,6 +78,13 @@ describe('PivotForm', () => {
78
78
  expect(screen.getByText('route.dossiers.pivot.explanation')).toBeInTheDocument();
79
79
  expect(screen.getByTestId('dossier-state')).not.toHaveTextContent('"group"');
80
80
  });
81
+ it('updates the pivot description when edited', async () => {
82
+ const user = userEvent.setup();
83
+ renderForm();
84
+ const descriptionInput = screen.getByRole('textbox', { name: 'tooltip.pivot.description' });
85
+ await user.type(descriptionInput, 'A useful description');
86
+ expect(screen.getByTestId('dossier-state')).toHaveTextContent('"description":"A useful description"');
87
+ });
81
88
  it('loads at most ten group suggestions after the throttled request', async () => {
82
89
  const user = userEvent.setup();
83
90
  mockGroupsGet.mockResolvedValue(Array.from({ length: 12 }, (_, index) => `network/${index}`));
@@ -624,6 +624,7 @@
624
624
  "personalization.showbreadcrumbs": "Show Breadcrumbs",
625
625
  "personalization.sticky": "Sticky Topbar",
626
626
  "pivot.clue.missing": "No Clue action is configured for this pivot.",
627
+ "pivot.description.header": "Description:",
627
628
  "pivot.description.none": "No description",
628
629
  "pivot.dossier.open": "Open Dossier",
629
630
  "pivot.url": "URL:",
@@ -970,6 +971,7 @@
970
971
  "to": "to",
971
972
  "tooltip.breadcrumbs.max": "Expand Breadcrumbs",
972
973
  "tooltip.breadcrumbs.min": "Collapse Breadcrumbs",
974
+ "tooltip.pivot.description": "Pivot's Description",
973
975
  "tui.query.invalid": "Invalid view",
974
976
  "tui.query.load": "Load a saved view",
975
977
  "tui.query.save.alert": "Load a saved view or save the current query as a view",
@@ -249,9 +249,9 @@
249
249
  "hit.search.filter.button": "Utiliser des filtres de recherche avec des valeurs prédéfinies",
250
250
  "hit.search.filter.disable": "Désactiver temporairement le filtre",
251
251
  "hit.search.filter.enable": "Réactiver le filtre",
252
- "hit.search.filter.fields": "Paramètres",
253
252
  "hit.search.filter.exclude": "Exclure les résultats correspondant à ce filtre",
254
253
  "hit.search.filter.excluded": "Filtre exclu",
254
+ "hit.search.filter.fields": "Paramètres",
255
255
  "hit.search.filter.include": "Inclure ce filtre",
256
256
  "hit.search.filter.included": "Filtre inclus",
257
257
  "hit.search.filter.label": "Filtres de recherche",
@@ -338,11 +338,11 @@
338
338
  "membership.message.error": "Il y a eu une erreur durant la mise a jours des permissions",
339
339
  "membership.message.success": "Permissions misse à jours.",
340
340
  "membership.message.warning": "Aucun utilisateur sélectionné",
341
- "membership.role": "Rôle",
342
341
  "membership.privilege.admins": "Administrateur",
343
342
  "membership.privilege.manage": "Gérer privilèges",
344
343
  "membership.privilege.members": "Membre",
345
344
  "membership.privilege.owner": "Propriétaire",
345
+ "membership.role": "Rôle",
346
346
  "modal.action.description": "Donnez un nom qui permette aux autres utilisateurs d'identifier l'objectif de cette action.",
347
347
  "modal.action.empty": "Le nom de l'action ne peut pas être vide.",
348
348
  "modal.action.label": "Nom de l'action",
@@ -624,6 +624,7 @@
624
624
  "personalization.showbreadcrumbs": "Afficher fils d'ariane",
625
625
  "personalization.sticky": "Barre supérieure collante",
626
626
  "pivot.clue.missing": "Aucune action Clue n'est configurée pour ce pivot.",
627
+ "pivot.description.header": "Description :",
627
628
  "pivot.description.none": "Aucune description",
628
629
  "pivot.dossier.open": "Ouvrir le dossier",
629
630
  "pivot.url": "URL :",
@@ -970,6 +971,7 @@
970
971
  "to": "à",
971
972
  "tooltip.breadcrumbs.max": "Maximiser fils d'ariane",
972
973
  "tooltip.breadcrumbs.min": "Minimiser fils d'ariane",
974
+ "tooltip.pivot.description": "Description du pivot",
973
975
  "tui.query.invalid": "Requête invalide",
974
976
  "tui.query.load": "Charger une vue enregistrée",
975
977
  "tui.query.save.alert": "Charger une vue enregistrée ou enregistrer la requête actuelle en tant que vue",
@@ -11,4 +11,5 @@ export interface Pivot {
11
11
  mappings?: Mapping[];
12
12
  value?: string;
13
13
  group?: string;
14
+ description?: string;
14
15
  }
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.1769.1",
100
+ "version": "3.2.0-dev.1773.1",
101
101
  "exports": {
102
102
  "./i18n": "./i18n.js",
103
103
  "./index.css": "./index.css",