@eeacms/volto-cca-policy 0.3.65 → 0.3.66

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.
package/CHANGELOG.md CHANGED
@@ -4,17 +4,29 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- ### [0.3.65](https://github.com/eea/volto-cca-policy/compare/1.0.0-alpha.0...0.3.65) - 16 July 2025
7
+ ### [0.3.66](https://github.com/eea/volto-cca-policy/compare/1.0.0-alpha.0...0.3.66) - 17 July 2025
8
8
 
9
9
  #### :rocket: Dependency updates
10
10
 
11
11
  - Release @eeacms/volto-searchlib@2.1.0 [EEA Jenkins - [`e5fc813`](https://github.com/eea/volto-cca-policy/commit/e5fc813f97922df335be28673d6303cb81b3c888)]
12
12
 
13
+ #### :bug: Bug Fixes
14
+
15
+ - fix: issues reported by sonarqube [kreafox - [`ccf5bcd`](https://github.com/eea/volto-cca-policy/commit/ccf5bcde698444d9bed9b138edb54841f78e27af)]
16
+ - fix: resolve sonarqube code quality issues - refs #289841 [kreafox - [`f9e2bd0`](https://github.com/eea/volto-cca-policy/commit/f9e2bd07bc4db00cc452dd4a2837b28dae7c3d64)]
17
+ - fix: resolve sonarqube code quality issues (WIP) - refs #289841 [kreafox - [`8253492`](https://github.com/eea/volto-cca-policy/commit/82534921494f8b0c5ba6c12cf6af834e4cc3f7e5)]
18
+
13
19
  #### :nail_care: Enhancements
14
20
 
15
21
  - change(header): add sitemap link - refs #288920 [kreafox - [`0b51b76`](https://github.com/eea/volto-cca-policy/commit/0b51b7649a13f250390cc78e88f6946d370c4c59)]
16
22
 
17
- ### [1.0.0-alpha.0](https://github.com/eea/volto-cca-policy/compare/0.3.64...1.0.0-alpha.0) - 15 July 2025
23
+ #### :hammer_and_wrench: Others
24
+
25
+ - test: fix security hotspots on sonarqube - refs #289841 [kreafox - [`ed2ae6f`](https://github.com/eea/volto-cca-policy/commit/ed2ae6f3d41062740df5dd31c749b25316321776)]
26
+ - test: fix security hotspots on sonarqube - refs #289841 [kreafox - [`2e86b28`](https://github.com/eea/volto-cca-policy/commit/2e86b285de2d43919248d53988a1f97eb44793d8)]
27
+ - test: add tests to increase code coverage [kreafox - [`29ee566`](https://github.com/eea/volto-cca-policy/commit/29ee56661f1e349177f91237b6e548e1036d8b57)]
28
+ - test: add tests to increase code coverage [kreafox - [`75e95bf`](https://github.com/eea/volto-cca-policy/commit/75e95bf109369b637eecfbd649cb07280c27c9fe)]
29
+ ### [1.0.0-alpha.0](https://github.com/eea/volto-cca-policy/compare/0.3.65...1.0.0-alpha.0) - 15 July 2025
18
30
 
19
31
  #### :bug: Bug Fixes
20
32
 
@@ -28,13 +40,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
28
40
 
29
41
  #### :nail_care: Enhancements
30
42
 
31
- - change: add archived info message on DefaultView - refs #289794 [kreafox - [`7005f0d`](https://github.com/eea/volto-cca-policy/commit/7005f0dcc653f2fd85713b12cb9fa75be97943c7)]
32
43
  - change: add volto grid teaser block customization [kreafox - [`1523323`](https://github.com/eea/volto-cca-policy/commit/15233230a01fbc7b9ef9c6df7aeb069876811530)]
33
44
  - change: update Header component [kreafox - [`8025ab9`](https://github.com/eea/volto-cca-policy/commit/8025ab9b2b5a19045dfe313cc3d4e7928a989771)]
34
45
 
35
46
  #### :house: Internal changes
36
47
 
37
- - chore: i18n [kreafox - [`5ffe66e`](https://github.com/eea/volto-cca-policy/commit/5ffe66e22b34f9451b01db1f4578037e03e1415f)]
38
48
  - chore: code cleanup [kreafox - [`842419b`](https://github.com/eea/volto-cca-policy/commit/842419b1bce3dc624755c81c9dea672198cab9e2)]
39
49
  - style: update teaser block styling [kreafox - [`1e0cad8`](https://github.com/eea/volto-cca-policy/commit/1e0cad8e1ed3ae827ee868dce8ad50b292a937ba)]
40
50
  - chore: update Makefile, run yarn i18n [kreafox - [`61e6962`](https://github.com/eea/volto-cca-policy/commit/61e6962901068ae6512265417a730bd9befd65fe)]
@@ -53,13 +63,30 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
53
63
 
54
64
  - Bump version [Tiberiu Ichim - [`f8e327e`](https://github.com/eea/volto-cca-policy/commit/f8e327e750771576e4f44fa4c27035b6e3b9c9e7)]
55
65
  - Fix eslint [Tiberiu Ichim - [`b6cfdd8`](https://github.com/eea/volto-cca-policy/commit/b6cfdd81c09e523d75ffbf2059008c77240311e2)]
56
- - test: improve security hotspots on sonarqube - refs #289841 [kreafox - [`2259d69`](https://github.com/eea/volto-cca-policy/commit/2259d696fe8c3ef2e1b3d49959d314556ceae501)]
57
66
  - update Jenkinsfile [kreafox - [`c8683c2`](https://github.com/eea/volto-cca-policy/commit/c8683c28ff5272c76ea055ba4e2870d9d8236082)]
58
67
  - test: update snaphots [kreafox - [`de0506a`](https://github.com/eea/volto-cca-policy/commit/de0506a81fd5e224bb1d4dd27109ae4d07fe919c)]
59
68
  - test: update snaphots [kreafox - [`1fee9fe`](https://github.com/eea/volto-cca-policy/commit/1fee9fec29b08aa06d40c88722fb2a032ce63019)]
60
69
  - test: Update to volto 17 PR30 [valentinab25 - [`ed03286`](https://github.com/eea/volto-cca-policy/commit/ed032865efa051d6353844737616019b202ea562)]
61
70
  - test: update snapshots [ana-oprea - [`94608ad`](https://github.com/eea/volto-cca-policy/commit/94608adc1b3b3655c7ecd5c39dde1f0fcd4b41e9)]
62
71
  - test: Update to volto 17 PR30 [valentinab25 - [`2e81033`](https://github.com/eea/volto-cca-policy/commit/2e810334e08366ca77ba62383c064770dde643a1)]
72
+ ### [0.3.65](https://github.com/eea/volto-cca-policy/compare/0.3.64...0.3.65) - 16 July 2025
73
+
74
+ #### :rocket: Dependency updates
75
+
76
+ - Release @eeacms/volto-searchlib@2.1.0 [EEA Jenkins - [`e5fc813`](https://github.com/eea/volto-cca-policy/commit/e5fc813f97922df335be28673d6303cb81b3c888)]
77
+
78
+ #### :nail_care: Enhancements
79
+
80
+ - change(header): add sitemap link - refs #288920 [kreafox - [`0b51b76`](https://github.com/eea/volto-cca-policy/commit/0b51b7649a13f250390cc78e88f6946d370c4c59)]
81
+ - change: add archived info message on DefaultView - refs #289794 [kreafox - [`7005f0d`](https://github.com/eea/volto-cca-policy/commit/7005f0dcc653f2fd85713b12cb9fa75be97943c7)]
82
+
83
+ #### :house: Internal changes
84
+
85
+ - chore: i18n [kreafox - [`5ffe66e`](https://github.com/eea/volto-cca-policy/commit/5ffe66e22b34f9451b01db1f4578037e03e1415f)]
86
+
87
+ #### :hammer_and_wrench: Others
88
+
89
+ - test: improve security hotspots on sonarqube - refs #289841 [kreafox - [`2259d69`](https://github.com/eea/volto-cca-policy/commit/2259d696fe8c3ef2e1b3d49959d314556ceae501)]
63
90
  ### [0.3.64](https://github.com/eea/volto-cca-policy/compare/0.3.63...0.3.64) - 11 July 2025
64
91
 
65
92
  #### :rocket: New Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-cca-policy",
3
- "version": "0.3.65",
3
+ "version": "0.3.66",
4
4
  "description": "@eeacms/volto-cca-policy: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -26,7 +26,10 @@ import cx from 'classnames';
26
26
  import eeaFlag from '@eeacms/volto-eea-design-system/../theme/themes/eea/assets/images/Header/eea.png';
27
27
 
28
28
  function removeTrailingSlash(path) {
29
- return path.replace(/\/+$/, '');
29
+ while (path.endsWith('/')) {
30
+ path = path.slice(0, -1);
31
+ }
32
+ return path;
30
33
  }
31
34
 
32
35
  /**
@@ -20,8 +20,8 @@ export default function LanguageSwitch({ history }) {
20
20
  );
21
21
  const [, setSelectedLanguage] = useAtom(selectedLanguageAtom);
22
22
  const width = useSelector((state) => state.screen?.width);
23
-
24
23
  const currentLang = useSelector((state) => state.intl.locale);
24
+
25
25
  const [language, setLanguage] = React.useState(
26
26
  currentLang || eea.defaultLanguage,
27
27
  );
@@ -45,7 +45,43 @@ export default function LanguageSwitch({ history }) {
45
45
  });
46
46
  };
47
47
 
48
- // .filter((item) => eea.non_eu_langs.indexOf(item.code) !== -1)
48
+ const renderLanguageItems = (languages) =>
49
+ languages.map((item, index) => {
50
+ const translated = (translations || []).some(
51
+ (obj) => obj.language === item.code,
52
+ );
53
+ const active = item.code === currentLang;
54
+ const disabled = !translated && !active;
55
+
56
+ return (
57
+ <Dropdown.Item
58
+ className={cx({
59
+ disabled: disabled,
60
+ active: active,
61
+ })}
62
+ as="li"
63
+ key={index}
64
+ text={
65
+ <span>
66
+ <span className="country-code">{item.code.toUpperCase()}</span>{' '}
67
+ {item.name}
68
+ </span>
69
+ }
70
+ onClick={(e) =>
71
+ disabled || active ? e.preventDefault() : handlePageRedirect(item)
72
+ }
73
+ />
74
+ );
75
+ });
76
+
77
+ const euLanguages = eea.languages.filter(
78
+ (item) => eea.non_eu_langs.indexOf(item.code) === -1,
79
+ );
80
+
81
+ const nonEuLanguages = eea.languages.filter(
82
+ (item) => eea.non_eu_langs.indexOf(item.code) !== -1,
83
+ );
84
+
49
85
  return (
50
86
  <Header.TopDropdownMenu
51
87
  id="language-switcher"
@@ -56,7 +92,7 @@ export default function LanguageSwitch({ history }) {
56
92
  }
57
93
  text={`${language.toUpperCase()}`}
58
94
  mobileText={`${language.toUpperCase()}`}
59
- icon={<Image src={globeIcon} alt="language dropdown globe icon"></Image>}
95
+ icon={<Image src={globeIcon} alt="language dropdown globe icon" />}
60
96
  viewportWidth={width}
61
97
  >
62
98
  <ul
@@ -64,39 +100,8 @@ export default function LanguageSwitch({ history }) {
64
100
  role="listbox"
65
101
  aria-label="language switcher"
66
102
  >
67
- {eea.languages
68
- .filter((item) => eea.non_eu_langs.indexOf(item.code) === -1)
69
- .map((item, index) => {
70
- const translated = (translations || []).some(
71
- (obj) => obj.language === item.code,
72
- );
73
- const active = item.code === currentLang;
74
- const disabled = !translated && !active;
103
+ {renderLanguageItems(euLanguages)}
75
104
 
76
- return (
77
- <Dropdown.Item
78
- className={cx({
79
- disabled: disabled,
80
- active: active,
81
- })}
82
- as="li"
83
- key={index}
84
- text={
85
- <span>
86
- <span className="country-code">
87
- {item.code.toUpperCase()}
88
- </span>{' '}
89
- {item.name}
90
- </span>
91
- }
92
- onClick={(e) =>
93
- disabled || active
94
- ? e.preventDefault()
95
- : handlePageRedirect(item)
96
- }
97
- ></Dropdown.Item>
98
- );
99
- })}
100
105
  <strong className="noneu-langs-label">
101
106
  <FormattedMessage
102
107
  id="Non-EU Languages"
@@ -104,39 +109,7 @@ export default function LanguageSwitch({ history }) {
104
109
  />
105
110
  </strong>
106
111
 
107
- {eea.languages
108
- .filter((item) => eea.non_eu_langs.indexOf(item.code) !== -1)
109
- .map((item, index) => {
110
- const translated = (translations || []).some(
111
- (obj) => obj.language === item.code,
112
- );
113
- const active = item.code === currentLang;
114
- const disabled = !translated && !active;
115
-
116
- return (
117
- <Dropdown.Item
118
- className={cx({
119
- disabled: disabled,
120
- active: active,
121
- })}
122
- as="li"
123
- key={index}
124
- text={
125
- <span>
126
- <span className="country-code">
127
- {item.code.toUpperCase()}
128
- </span>{' '}
129
- {item.name}
130
- </span>
131
- }
132
- onClick={(e) =>
133
- disabled || active
134
- ? e.preventDefault()
135
- : handlePageRedirect(item)
136
- }
137
- ></Dropdown.Item>
138
- );
139
- })}
112
+ {renderLanguageItems(nonEuLanguages)}
140
113
  </ul>
141
114
  </Header.TopDropdownMenu>
142
115
  );
@@ -89,10 +89,10 @@ const ImageGallery = (props) => {
89
89
  <Slider {...carouselSettings} ref={sliderRef}>
90
90
  {items.map((item, i) => {
91
91
  return image.rights ? (
92
- <div>
92
+ <div key={i}>
93
93
  <div className="image-slide">
94
94
  <div className="image-rights">@ {image.rights}</div>
95
- <Image key={i} src={item.url} alt={item?.title} />
95
+ <Image src={item.url} alt={item?.title} />
96
96
  </div>
97
97
  </div>
98
98
  ) : (
@@ -0,0 +1,38 @@
1
+ import '@testing-library/jest-dom';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import ImageGallery from './ImageGallery';
4
+
5
+ jest.mock('react-slick', () => (props) => <div>React Slick Gallery</div>);
6
+
7
+ const mockItems = [
8
+ {
9
+ url: 'https://example.com/image1.jpg',
10
+ title: 'Image One',
11
+ description: 'First image description',
12
+ rights: 'Author One',
13
+ },
14
+ {
15
+ url: 'https://example.com/image2.jpg',
16
+ title: 'Image Two',
17
+ description: 'Second image description',
18
+ rights: 'Author Two',
19
+ },
20
+ ];
21
+
22
+ describe('ImageGallery', () => {
23
+ it('renders preview image and opens modal on click', () => {
24
+ render(<ImageGallery items={mockItems} />);
25
+
26
+ const previewImage = screen.getByRole('img', { name: /Image One/i });
27
+ expect(previewImage).toBeInTheDocument();
28
+
29
+ expect(
30
+ screen.queryByText('First image description'),
31
+ ).not.toBeInTheDocument();
32
+
33
+ fireEvent.click(previewImage);
34
+
35
+ expect(screen.getByText('Image One')).toBeInTheDocument();
36
+ expect(screen.getByText('First image description')).toBeInTheDocument();
37
+ });
38
+ });
@@ -0,0 +1,24 @@
1
+ import { render } from '@testing-library/react';
2
+ import PortalMessage from './PortalMessage';
3
+ import { IntlProvider } from 'react-intl';
4
+ import '@testing-library/jest-dom';
5
+
6
+ const renderWithIntl = (ui) =>
7
+ render(<IntlProvider locale="en">{ui}</IntlProvider>);
8
+
9
+ describe('PortalMessage', () => {
10
+ it('renders the message component when content is archived', () => {
11
+ const content = { review_state: 'archived' };
12
+ const { container } = renderWithIntl(<PortalMessage content={content} />);
13
+
14
+ const messageEl = container.querySelector('.ui.message');
15
+ expect(messageEl).toBeInTheDocument();
16
+ });
17
+
18
+ it('renders nothing when content is not archived', () => {
19
+ const content = { review_state: 'published' };
20
+ const { container } = renderWithIntl(<PortalMessage content={content} />);
21
+
22
+ expect(container).toBeEmptyDOMElement();
23
+ });
24
+ });
@@ -72,6 +72,24 @@ const messages = defineMessages({
72
72
  * ```
73
73
  *
74
74
  */
75
+ function parseDataURL(dataUrl) {
76
+ if (!dataUrl.startsWith('data:')) return null;
77
+
78
+ const commaIndex = dataUrl.indexOf(',');
79
+ if (commaIndex === -1) return null;
80
+
81
+ const meta = dataUrl.slice(5, commaIndex);
82
+ const data = dataUrl.slice(commaIndex + 1);
83
+
84
+ const [contentType, encoding] = meta.split(';');
85
+
86
+ return {
87
+ 'content-type': contentType || '',
88
+ encoding: encoding || '',
89
+ data: data || '',
90
+ };
91
+ }
92
+
75
93
  const FileWidget = (props) => {
76
94
  const { id, value, onChange, isDisabled } = props;
77
95
  const [fileType, setFileType] = React.useState(false);
@@ -99,27 +117,31 @@ const FileWidget = (props) => {
99
117
  const file = files[0];
100
118
  if (!validateFileUploadSize(file, intl.formatMessage)) return;
101
119
  readAsDataURL(file).then((data) => {
102
- const fields = data.match(/^data:(.*);(.*),(.*)$/);
103
- onChange(id, {
104
- data: fields[3],
105
- encoding: fields[2],
106
- 'content-type': fields[1],
107
- filename: file.name,
108
- });
120
+ const fields = parseDataURL(data);
121
+ if (fields) {
122
+ onChange(id, {
123
+ data: fields.data,
124
+ encoding: fields.encoding,
125
+ 'content-type': fields['content-type'],
126
+ filename: file.name,
127
+ });
128
+ }
109
129
  });
110
130
 
111
- let reader = new FileReader();
131
+ const reader = new FileReader();
112
132
  reader.onload = function () {
113
- const fields = reader.result.match(/^data:(.*);(.*),(.*)$/);
114
- if (imageMimetypes.includes(fields[1])) {
133
+ const parsed = parseDataURL(reader.result);
134
+ if (parsed && imageMimetypes.includes(parsed['content-type'])) {
115
135
  setFileType(true);
116
- let imagePreview = document.getElementById(`field-${id}-image`);
117
- imagePreview.src = reader.result;
136
+ const imagePreview = document.getElementById(`field-${id}-image`);
137
+ if (imagePreview) {
138
+ imagePreview.src = reader.result;
139
+ }
118
140
  } else {
119
141
  setFileType(false);
120
142
  }
121
143
  };
122
- reader.readAsDataURL(files[0]);
144
+ reader.readAsDataURL(file);
123
145
  };
124
146
 
125
147
  return (
package/src/index.js CHANGED
@@ -522,7 +522,7 @@ const applyConfig = (config) => {
522
522
  },
523
523
  {
524
524
  match: {
525
- path: /(.*)\/add$/,
525
+ path: /^.*\/add$/,
526
526
  },
527
527
  component: RedirectToLogin,
528
528
  },
@@ -532,13 +532,13 @@ const applyConfig = (config) => {
532
532
  ...config.settings.apiExpanders,
533
533
  {
534
534
  match: {
535
- path: /(.*)\/policy-context\/country-profiles\/(.*)/,
535
+ path: /\/policy-context\/country-profiles\/.+/,
536
536
  },
537
537
  GET_CONTENT: ['siblings'],
538
538
  },
539
539
  {
540
540
  match: {
541
- path: /(.*)\/countries-regions\/countries\/(.*)/,
541
+ path: /\/countries-regions\/countries\/.+/,
542
542
  },
543
543
  GET_CONTENT: ['siblings'],
544
544
  },
package/src/utils.js CHANGED
@@ -101,6 +101,15 @@ export const formatTextToHTML = (text) => {
101
101
  : `<p>${formattedText}</p>`;
102
102
  };
103
103
 
104
+ const trimTrailingChars = (str) => {
105
+ const charsToTrim = ['-', '–', ';', ',', ':', ' '];
106
+ let end = str.length;
107
+ while (end > 0 && charsToTrim.includes(str[end - 1])) {
108
+ end--;
109
+ }
110
+ return str.substring(0, end);
111
+ };
112
+
104
113
  export const extractPlanNameAndURL = (text) => {
105
114
  if (!text) return { name: '', url: '' };
106
115
 
@@ -114,12 +123,8 @@ export const extractPlanNameAndURL = (text) => {
114
123
 
115
124
  if (url) {
116
125
  // Remove URL and any punctuation before it
117
- name = name
118
- .replace(`(${url})`, '')
119
- .replace(url, '')
120
- .replace(/[-–;,:\s]+$/, '')
121
- .replace(/[-–;,:\s]+$/, '')
122
- .trim();
126
+ name = name.replace(`(${url})`, '').replace(url, '');
127
+ name = trimTrailingChars(name).trim();
123
128
  }
124
129
 
125
130
  return {