Skip to content

Commit 7b38ff3

Browse files
authored
Refactoring of handling mandatory notes above the table (#728)
* First draft of refactor of mandatory notes above the table * Add space in text * Moved div out of Conent top to get rid of gap Moved check for no notes from alert to surrending div to avoid space if no notes * Use common style for heading underline * Use aria-live * Code cleanup Use already existing text from textfiles * Remove commeted out code * Spelling mistake * moved function out of component function , so it could be accesed from test file Added test * Don't use loadash
1 parent 1a3c19d commit 7b38ff3

File tree

9 files changed

+286
-90
lines changed

9 files changed

+286
-90
lines changed

packages/pxweb2-ui/src/lib/components/Alert/Alert.module.scss

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
&:hover {
2626
box-shadow: inset 0px 0px 0px 2px var(--px-color-border-info);
2727
h2 {
28-
text-decoration: underline;
29-
text-decoration-thickness: 7%;
30-
text-underline-offset: 9%;
31-
text-decoration-skip-ink: true;
28+
@extend .heading-underline;
3229
}
3330
}
3431
&:hover .alert-arrow-wrapper {
@@ -49,10 +46,7 @@
4946
&:hover {
5047
box-shadow: inset 0px 0px 0px 2px var(--px-color-border-success);
5148
h2 {
52-
text-decoration: underline;
53-
text-decoration-thickness: 7%;
54-
text-underline-offset: 9%;
55-
text-decoration-skip-ink: true;
49+
@extend .heading-underline;
5650
}
5751
}
5852
&:hover .alert-arrow-wrapper {
@@ -72,10 +66,7 @@
7266
&:hover {
7367
box-shadow: inset 0px 0px 0px 2px var(--px-color-border-warning);
7468
h2 {
75-
text-decoration: underline;
76-
text-decoration-thickness: 7%;
77-
text-underline-offset: 9%;
78-
text-decoration-skip-ink: true;
69+
@extend .heading-underline;
7970
}
8071
}
8172
&:hover .alert-arrow-wrapper {
@@ -95,10 +86,7 @@
9586
&:hover {
9687
box-shadow: inset 0px 0px 0px 2px var(--px-color-border-error);
9788
h2 {
98-
text-decoration: underline;
99-
text-decoration-thickness: 7%;
100-
text-underline-offset: 9%;
101-
text-decoration-skip-ink: true;
89+
@extend .heading-underline;
10290
}
10391
}
10492
&:hover .alert-arrow-wrapper {
@@ -212,6 +200,17 @@
212200
gap: 6px;
213201
}
214202

203+
.alert-arrow {
204+
display: flex;
205+
align-items: center;
206+
justify-content: center;
207+
width: 32px;
208+
height: 32px;
209+
border: none;
210+
background-color: transparent;
211+
cursor: pointer;
212+
}
213+
215214
.alert-section-right-continue {
216215
display: flex;
217216
margin-left: auto;

packages/pxweb2-ui/src/lib/components/Alert/Alert.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ export interface AlertProps {
2020
readonly onClick?: () => void;
2121
readonly className?: string;
2222
readonly children?: string | React.ReactNode;
23+
readonly clickButtonAriaLabel?: string;
24+
readonly alertAriaLabel?: string;
25+
readonly ariaLive?: 'off' | 'polite' | 'assertive';
26+
readonly ariaHasPopup?:
27+
| 'false'
28+
| 'true'
29+
| 'menu'
30+
| 'listbox'
31+
| 'tree'
32+
| 'grid'
33+
| 'dialog';
34+
readonly role?: React.AriaRole;
2335
ref?: React.Ref<HTMLDivElement>;
2436
id?: string;
2537
}
@@ -34,6 +46,11 @@ export function Alert({
3446
onClick,
3547
className = '',
3648
children,
49+
clickButtonAriaLabel,
50+
alertAriaLabel,
51+
ariaHasPopup = 'false',
52+
ariaLive = 'off',
53+
role,
3754
ref,
3855
id,
3956
}: Readonly<AlertProps>) {
@@ -138,6 +155,7 @@ export function Alert({
138155
return (
139156
<div
140157
id={id}
158+
aria-label={alertAriaLabel}
141159
tabIndex={clickable ? 0 : undefined}
142160
className={
143161
cl(classes[`alert-${size}`], classes[variant], {
@@ -147,6 +165,8 @@ export function Alert({
147165
onClick={clickable ? onClick : undefined}
148166
onKeyDown={clickable ? handleKeyDown : undefined}
149167
style={{ cursor: clickable ? 'pointer' : 'default' }}
168+
aria-haspopup={ariaHasPopup}
169+
role={role}
150170
ref={ref}
151171
>
152172
<div className={classes[`alert-section-left-${size}`]}>
@@ -200,9 +220,15 @@ export function Alert({
200220
</div>
201221
)}
202222
{clickable && (
203-
<div className={cl(classes['alert-arrow-wrapper'])}>
204-
{' '}
205-
<Icon iconName={iconRight} className=""></Icon>
223+
<div aria-live={ariaLive}>
224+
<button
225+
className={cl(classes['alert-arrow'])}
226+
aria-label={clickButtonAriaLabel}
227+
type="button"
228+
tabIndex={-1}
229+
>
230+
<Icon iconName={iconRight} />
231+
</button>
206232
</div>
207233
)}
208234
</div>

packages/pxweb2/public/locales/en/translation.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,13 @@
218218
"mandatory_heading": "Important about the table",
219219
"mandatory_variable_heading": "Important about",
220220
"non_mandatory_heading": "For the entire table",
221-
"show_all_footnotes": "Show all notes for table"
221+
"show_all_footnotes": "Show all notes for table",
222+
"important_about_selection_heading_1": "There are ",
223+
"important_about_selection_heading_2": " important notes for your selection",
224+
"important_about_selection_body": "Click on this message to read the notes.",
225+
"important_about_selection_heading_one_note_1": "There is ",
226+
"important_about_selection_heading_one_note_2": " important note for your selection",
227+
"important_about_selection_body_one_note": "Click on this message to read the note."
222228
},
223229
"definitions": {
224230
"title": "Definitions",
@@ -247,10 +253,6 @@
247253
"description": "Description text...",
248254
"missing_heading": "No contact information",
249255
"missing_text": "The table has no contact information."
250-
},
251-
"notes": {
252-
"important_about_table": "Important about the table",
253-
"important_about_variable": "Important about "
254256
}
255257
},
256258
"related": {

packages/pxweb2/public/locales/no/translation.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,13 @@
218218
"mandatory_heading": "Viktig om tabellen",
219219
"mandatory_variable_heading": "Viktig om",
220220
"non_mandatory_heading": "Gjelder hele tabellen",
221-
"show_all_footnotes": "Vis alle noter for tabellen"
221+
"show_all_footnotes": "Vis alle noter for tabellen",
222+
"important_about_selection_heading_1": "Det er ",
223+
"important_about_selection_heading_2": " viktige merknader for valgt filtrering ",
224+
"important_about_selection_body": "Trykk på denne meldingen for å lese merknadene. ",
225+
"important_about_selection_heading_one_note_1": "Det er ",
226+
"important_about_selection_heading_one_note_2": " viktig merknad for valgt filtrering ",
227+
"important_about_selection_body_one_note": "Trykk på denne meldingen for å lese merknaden. "
222228
},
223229
"definitions": {
224230
"title": "Definisjoner",
@@ -247,10 +253,6 @@
247253
"description": "Beskrivelsestekst...",
248254
"missing_heading": "Ingen kontaktinformasjon",
249255
"missing_text": "Tabellen har ikke kontaktinformasjon."
250-
},
251-
"notes": {
252-
"important_about_table": "Viktig om tabellen",
253-
"important_about_variable": "Viktig om "
254256
}
255257
},
256258
"related": {

packages/pxweb2/public/locales/sv/translation.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,13 @@
218218
"mandatory_heading": "Viktigt om tabellen",
219219
"mandatory_variable_heading": "Viktigt om",
220220
"non_mandatory_heading": "Gäller hela tabellen",
221-
"show_all_footnotes": "Visa alla fotnoter för tabellen"
221+
"show_all_footnotes": "Visa alla fotnoter för tabellen",
222+
"important_about_selection_heading_1": "Det finns ",
223+
"important_about_selection_heading_2": " viktiga noter för vald filtrering ",
224+
"important_about_selection_body": "Tryck på detta meddelande för att läsa noterna. ",
225+
"important_about_selection_heading_one_note_1": "Det finns ",
226+
"important_about_selection_heading_one_note_2": " viktig not för vald filtrering ",
227+
"important_about_selection_body_one_note": "Tryck på detta meddelande för att läsa noten. "
222228
},
223229
"definitions": {
224230
"title": "Definitioner",
@@ -247,10 +253,6 @@
247253
"description": "Beskrivande text...",
248254
"missing_heading": "Ingen kontaktinformation",
249255
"missing_text": "Tabellen har ingen kontaktinformation."
250-
},
251-
"notes": {
252-
"important_about_table": "Viktigt om tabellen",
253-
"important_about_variable": "Viktigt om "
254256
}
255257
},
256258
"related": {

packages/pxweb2/src/app/components/ContentTop/ContentTop.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@
5656
display: flex;
5757
flex-direction: column;
5858
gap: 20px;
59+
width: 100%;
5960
}

packages/pxweb2/src/app/components/ContentTop/ContentTop.spec.tsx

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import {
1010
import ContentTop from './ContentTop';
1111
import { renderWithProviders } from '../../util/testing-utils';
1212
import { getMandatoryNotesCompressed } from '../../util/notes/notesUtil';
13-
//import { describe, it, expect } from 'vitest';
1413

1514
import { Config } from '../../util/config/configType';
15+
import { describe, it, expect } from 'vitest';
16+
import React from 'react';
17+
import * as ContentTopModule from './ContentTop';
18+
import { useTranslation } from 'react-i18next';
1619

1720
// Declare the global variable for this file
1821
declare global {
@@ -204,3 +207,107 @@ describe('Selection', () => {
204207
expect(baseElement).toBeTruthy();
205208
});
206209
});
210+
211+
describe('ContentTop.createNoteMessage', () => {
212+
// Import the function from the component file
213+
const { createNoteMessage } = ContentTopModule;
214+
215+
// Mock translation function
216+
// const t = (key: string) => key;
217+
218+
const baseNoteInfo = {
219+
numberOfTableNotes: 0,
220+
tableNotes: '',
221+
variableNotes: [],
222+
};
223+
const { t } = useTranslation();
224+
it('returns null if there are no notes', () => {
225+
const noteInfo = { ...baseNoteInfo };
226+
const result = createNoteMessage(noteInfo as any, t);
227+
expect(result).toBeNull();
228+
});
229+
230+
it('returns table notes only if variableNotes is empty and numberOfTableNotes > 0', () => {
231+
const noteInfo = {
232+
...baseNoteInfo,
233+
numberOfTableNotes: 2,
234+
tableNotes: 'Table note text',
235+
variableNotes: [],
236+
};
237+
const result = createNoteMessage(noteInfo as any, t);
238+
expect(result).toEqual({
239+
heading:
240+
'presentation_page.main_content.about_table.footnotes.mandatory_heading',
241+
message: 'Table note text',
242+
});
243+
});
244+
245+
it('returns variable note only if numberOfTableNotes is 0 and one variable note', () => {
246+
const noteInfo = {
247+
...baseNoteInfo,
248+
numberOfTableNotes: 0,
249+
variableNotes: [
250+
{
251+
compressednotes: 'Variable note text',
252+
totalNumberOfNotesOnVariable: 1,
253+
},
254+
],
255+
};
256+
const result = createNoteMessage(noteInfo as any, t);
257+
expect(result).toEqual({
258+
heading:
259+
'presentation_page.main_content.about_table.footnotes.important_about_selection_heading_one_note_1' +
260+
1 +
261+
'presentation_page.main_content.about_table.footnotes.important_about_selection_heading_one_note_2',
262+
message: 'Variable note text',
263+
});
264+
});
265+
266+
it('returns combined heading/message for multiple notes', () => {
267+
const noteInfo = {
268+
...baseNoteInfo,
269+
numberOfTableNotes: 1,
270+
variableNotes: [
271+
{
272+
compressednotes: 'Variable note text',
273+
totalNumberOfNotesOnVariable: 2,
274+
},
275+
],
276+
};
277+
const result = createNoteMessage(noteInfo as any, t);
278+
expect(result).toEqual({
279+
heading:
280+
'presentation_page.main_content.about_table.footnotes.important_about_selection_heading_1' +
281+
3 +
282+
'presentation_page.main_content.about_table.footnotes.important_about_selection_heading_2',
283+
message:
284+
'presentation_page.main_content.about_table.footnotes.important_about_selection_body',
285+
});
286+
});
287+
288+
it('returns combined heading/message for multiple variable notes', () => {
289+
const noteInfo = {
290+
...baseNoteInfo,
291+
numberOfTableNotes: 0,
292+
variableNotes: [
293+
{
294+
compressednotes: 'Variable note 1',
295+
totalNumberOfNotesOnVariable: 1,
296+
},
297+
{
298+
compressednotes: 'Variable note 2',
299+
totalNumberOfNotesOnVariable: 2,
300+
},
301+
],
302+
};
303+
const result = createNoteMessage(noteInfo as any, t);
304+
expect(result).toEqual({
305+
heading:
306+
'presentation_page.main_content.about_table.footnotes.important_about_selection_heading_1' +
307+
3 +
308+
'presentation_page.main_content.about_table.footnotes.important_about_selection_heading_2',
309+
message:
310+
'presentation_page.main_content.about_table.footnotes.important_about_selection_body',
311+
});
312+
});
313+
});

0 commit comments

Comments
 (0)