@eeacms/volto-cca-policy 0.2.41 → 0.2.43

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,15 +4,45 @@ 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.2.41](https://github.com/eea/volto-cca-policy/compare/0.2.40...0.2.41) - 4 June 2024
7
+ ### [0.2.43](https://github.com/eea/volto-cca-policy/compare/0.2.42...0.2.43) - 13 June 2024
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat(event): add i18n messages for documents and improve code readability [kreafox - [`f23168a`](https://github.com/eea/volto-cca-policy/commit/f23168ad982317bdf1523cdd42f39ef84b55da0e)]
8
12
 
9
13
  #### :rocket: Dependency updates
10
14
 
11
- - Release @eeacms/volto-embed@10.0.1 [EEA Jenkins - [`7e807f4`](https://github.com/eea/volto-cca-policy/commit/7e807f45151eb7335a9f690a038bef8a9f1add80)]
15
+ - Release @eeacms/volto-embed@10.0.2 [EEA Jenkins - [`2e0174c`](https://github.com/eea/volto-cca-policy/commit/2e0174c154250e838535e3f9c8b1c8f83fa8ccde)]
16
+
17
+ #### :bug: Bug Fixes
18
+
19
+ - fix(event): use email link interpolation correctly [kreafox - [`0527737`](https://github.com/eea/volto-cca-policy/commit/0527737a47ae1e70a5719b160736be9247d68634)]
20
+
21
+ #### :nail_care: Enhancements
22
+
23
+ - change(event): simplify component structure and organize imports [kreafox - [`30a7766`](https://github.com/eea/volto-cca-policy/commit/30a7766d33a04d26d17b798d0ef776603c7fe29c)]
24
+ - change(event): use renderBlocks instead of custom BannerTitle component [kreafox - [`0dd267a`](https://github.com/eea/volto-cca-policy/commit/0dd267af20184dbd683671ef1e23dd3d15606667)]
12
25
 
13
26
  #### :hammer_and_wrench: Others
14
27
 
15
- - Tweak default expands [Tiberiu Ichim - [`e721114`](https://github.com/eea/volto-cca-policy/commit/e7211143178f25279541cf974ce41e8b4ae2c3b3)]
28
+ - test: fix warning message [kreafox - [`4d31ff2`](https://github.com/eea/volto-cca-policy/commit/4d31ff20dcfce88ad96f608409a5e12b20f13c9e)]
29
+ - test: update snapshot [kreafox - [`c8047ca`](https://github.com/eea/volto-cca-policy/commit/c8047ca5d592fea5db728999f1f7a8f96cad6496)]
30
+ - New version [Tiberiu Ichim - [`8617e34`](https://github.com/eea/volto-cca-policy/commit/8617e343ec075259078b533064bb6de2a3005a48)]
31
+ - https://github.com/elastic/search-ui/issues/1046 [Tiberiu Ichim - [`9eb0d03`](https://github.com/eea/volto-cca-policy/commit/9eb0d03aace62b7692033d9e429c42f10e176354)]
32
+ - Pin @eeacms/volto-embed [kreafox - [`0418854`](https://github.com/eea/volto-cca-policy/commit/04188549444a127e041ef98973900814f86e3859)]
33
+ - Let's try something else [Tiberiu Ichim - [`ab847b7`](https://github.com/eea/volto-cca-policy/commit/ab847b7d35448dadf29892bc10f8024dabf6d664)]
34
+ - Remove dependency for search-ui [Tiberiu Ichim - [`f3bf4a4`](https://github.com/eea/volto-cca-policy/commit/f3bf4a42f1dac44c57b6c1557b583112e328d26d)]
35
+ - Refs #271086 - wip tests [Tripon Eugen - [`e2cfdc7`](https://github.com/eea/volto-cca-policy/commit/e2cfdc78dc82b70d147bc1a7505632b9577719b8)]
36
+ - Refs #271086 - package.json resolutions [Tripon Eugen - [`09cce63`](https://github.com/eea/volto-cca-policy/commit/09cce6376cc489d5466981ce1a8e53bb8a994c1e)]
37
+ - Refs #271086 - add elements filter at cse [Tripon Eugen - [`549030c`](https://github.com/eea/volto-cca-policy/commit/549030cde005331f26a9ccde09394fee3f43f049)]
38
+ ### [0.2.42](https://github.com/eea/volto-cca-policy/compare/0.2.41...0.2.42) - 4 June 2024
39
+
40
+ ### [0.2.41](https://github.com/eea/volto-cca-policy/compare/0.2.40...0.2.41) - 4 June 2024
41
+
42
+ #### :rocket: Dependency updates
43
+
44
+ - Release @eeacms/volto-embed@10.0.1 [EEA Jenkins - [`7e807f4`](https://github.com/eea/volto-cca-policy/commit/7e807f45151eb7335a9f690a038bef8a9f1add80)]
45
+
16
46
  ### [0.2.40](https://github.com/eea/volto-cca-policy/compare/0.2.39...0.2.40) - 31 May 2024
17
47
 
18
48
  #### :bug: Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-cca-policy",
3
- "version": "0.2.41",
3
+ "version": "0.2.43",
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",
@@ -31,13 +31,13 @@
31
31
  "@eeacms/volto-datablocks": "*",
32
32
  "@eeacms/volto-eea-design-system": "*",
33
33
  "@eeacms/volto-eea-website-theme": "^1.33.2",
34
- "@eeacms/volto-embed": "10.0.1",
34
+ "@eeacms/volto-embed": "^9.1.1",
35
35
  "@eeacms/volto-globalsearch": "^1.1.0",
36
36
  "@eeacms/volto-openlayers-map": "*",
37
- "@eeacms/volto-searchlib": "^0.9.3",
37
+ "@eeacms/volto-searchlib": "2.0.2",
38
+ "@elastic/search-ui": "1.21.2",
38
39
  "@eeacms/volto-slate-label": "^0.6.0",
39
40
  "@eeacms/volto-tabs-block": "^7.5.1",
40
- "@elastic/search-ui": "1.21.2",
41
41
  "d3-array": "^2.12.1",
42
42
  "jotai": "^1.6.0",
43
43
  "query-string": "7.1.0",
@@ -4,6 +4,7 @@ export { default as PortalMessage } from './theme/PortalMessage/PortalMessage';
4
4
  export { default as TranslationDisclaimer } from './theme/TranslationDisclaimer/TranslationDisclaimer';
5
5
  export { default as ShareInfoButton } from './theme/ShareInfoButton/ShareInfoButton';
6
6
  export { default as ASTNavigation } from './theme/ASTNavigation/ASTNavigation';
7
+ export { default as RedirectToLogin } from './theme/RedirectToLogin/RedirectToLogin';
7
8
 
8
9
  // Widgets
9
10
  export { default as RASTWidgetView } from './theme/Widgets/RASTWidgetView';
@@ -19,12 +19,14 @@ export default function CaseStudyExplorerView(props) {
19
19
  const [activeFilters, setActiveFilters] = React.useState({
20
20
  sectors: [],
21
21
  impacts: [],
22
+ elements: [],
22
23
  measures: [],
23
24
  });
24
25
 
25
26
  const [activeItems, setActiveItems] = React.useState(cases);
26
27
  const [filters, setFilters] = React.useState({
27
28
  impacts: [],
29
+ elements: [],
28
30
  sectors: [],
29
31
  measures: {},
30
32
  });
@@ -44,12 +46,14 @@ export default function CaseStudyExplorerView(props) {
44
46
  let _filters = filters;
45
47
  _filters.impacts = _filters_data.impacts;
46
48
  _filters.sectors = _filters_data.sectors;
49
+ _filters.elements = _filters_data.elements;
47
50
  setFilters(_filters);
48
51
  }, [
49
52
  filters,
50
53
  cases,
51
54
  activeFilters.impacts,
52
55
  activeFilters.sectors,
56
+ activeFilters.elements,
53
57
  activeFilters.measures,
54
58
  activeItems.length,
55
59
  ]);
@@ -84,6 +84,31 @@ export default function CaseStudyFilters(props) {
84
84
  ),
85
85
  )}
86
86
  </Accordion.Content>
87
+ <Accordion.Title
88
+ active={activeIndex.includes(3)}
89
+ index={3}
90
+ onClick={handleClick}
91
+ >
92
+ <AccordionIcon active={activeIndex.includes(3)} />
93
+ <FormattedMessage
94
+ id="Adaptation elements"
95
+ defaultMessage="Adaptation elements"
96
+ />
97
+ </Accordion.Title>
98
+ <Accordion.Content active={activeIndex.includes(3)}>
99
+ {Object.entries(filters?.elements || {}).map(
100
+ ([value, label], index) => (
101
+ <Checkbox
102
+ label={intl.formatMessage({ id: label })}
103
+ value={value}
104
+ checked={activeFilters.elements.includes(value)}
105
+ name="elements"
106
+ onChange={checkboxChangeHandler}
107
+ key={'element' + index}
108
+ />
109
+ ),
110
+ )}
111
+ </Accordion.Content>
87
112
  <Accordion.Title
88
113
  active={activeIndex.includes(1)}
89
114
  index={1}
@@ -16,6 +16,7 @@ describe('CaseStudyFilters', () => {
16
16
  // impacts: [{ DROUGHT: 'Drought' }],
17
17
  sectors: [],
18
18
  impacts: [],
19
+ elements: [],
19
20
  measures: {
20
21
  // Measure1: [
21
22
  // { key: 'M11', value: 'm11' },
@@ -26,6 +27,7 @@ describe('CaseStudyFilters', () => {
26
27
  activeFilters: {
27
28
  sectors: [],
28
29
  impacts: [],
30
+ elements: [],
29
31
  measures: [],
30
32
  },
31
33
  };
@@ -43,7 +43,6 @@ export default function FeatureDisplay({ feature }) {
43
43
  <span
44
44
  dangerouslySetInnerHTML={{
45
45
  __html: feature.adaptation_options_links.replaceAll('<>', '; '),
46
- // __html: feature.adaptation_options_links,
47
46
  }}
48
47
  ></span>
49
48
  </p>
@@ -35,6 +35,7 @@ export function filterCases(cases, activeFilters) {
35
35
  if (
36
36
  activeFilters.sectors.length === 0 &&
37
37
  activeFilters.measures.length === 0 &&
38
+ activeFilters.elements.length === 0 &&
38
39
  activeFilters.impacts.length === 0
39
40
  )
40
41
  return _case;
@@ -45,6 +46,10 @@ export function filterCases(cases, activeFilters) {
45
46
  if (_case.properties.sectors.includes(',' + filter + ',')) flag = true;
46
47
  });
47
48
 
49
+ activeFilters.elements.forEach((filter) => {
50
+ if (_case.properties.elements.includes(',' + filter + ',')) flag = true;
51
+ });
52
+
48
53
  activeFilters.impacts.forEach((filter) => {
49
54
  if (_case.properties.impacts.includes(',' + filter + ',')) flag = true;
50
55
  });
@@ -60,7 +65,7 @@ export function filterCases(cases, activeFilters) {
60
65
  }
61
66
 
62
67
  export function getFilters(cases) {
63
- let _filters = { sectors: {}, impacts: {}, measures: {} };
68
+ let _filters = { sectors: {}, impacts: {}, elements: {}, measures: {} };
64
69
 
65
70
  for (let key of Object.keys(cases)) {
66
71
  const _case = cases[key];
@@ -81,6 +86,17 @@ export function getFilters(cases) {
81
86
  }
82
87
  }
83
88
 
89
+ let elementKeys = _case.properties?.elements?.split(',');
90
+ let elementNames = _case.properties?.elements_str?.split(',') || [];
91
+ for (let i = 0; i < elementNames.length; i++) {
92
+ if (
93
+ !_filters.elements.hasOwnProperty(elementKeys[i + 1]) &&
94
+ elementKeys[i + 1].length
95
+ ) {
96
+ _filters.elements[elementKeys[i + 1]] = elementNames[i];
97
+ }
98
+ }
99
+
84
100
  // let ktmKeys = _case.properties.ktms.split(',');
85
101
  // let ktmNames = _case.properties.impacts_str.split(',');
86
102
  // for (let i = 0; i < ktmKeys.length; i++) {
@@ -12,17 +12,18 @@ const messages = defineMessages({
12
12
  });
13
13
 
14
14
  const getDropdownOptions = (items) => {
15
- const options = items?.map((item) => {
16
- const source = item?.source?.[0];
17
- return {
18
- key: source?.id,
19
- value: source?.id,
20
- text: item.item_title,
21
- as: Link,
22
- to: flattenToAppURL(source?.['@id']),
23
- };
24
- });
25
- return options;
15
+ return (
16
+ items?.map((item, index) => {
17
+ const source = item?.source?.[0];
18
+ return {
19
+ key: source?.id || index,
20
+ value: source?.id,
21
+ text: item.item_title,
22
+ as: Link,
23
+ to: flattenToAppURL(source?.['@id']),
24
+ };
25
+ }) || []
26
+ );
26
27
  };
27
28
 
28
29
  const DropdownListView = (props) => {
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+
3
+ export default function RedirectToLogin(props) {
4
+ const { token, location, history } = props;
5
+ const { pathname, search } = location;
6
+
7
+ React.useEffect(() => {
8
+ if (!token) {
9
+ const back = encodeURIComponent(`${pathname}${search}`);
10
+ history.push(`/login?return_url=${back}`);
11
+ }
12
+ }, [token, history, pathname, search]);
13
+
14
+ return null;
15
+ }
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import { MemoryRouter } from 'react-router-dom';
3
+ import configureStore from 'redux-mock-store';
4
+ import { Provider } from 'react-intl-redux';
5
+ import RedirectToLogin from './RedirectToLogin';
6
+ import config from '@plone/volto/registry';
7
+ import { render } from '@testing-library/react';
8
+
9
+ config.blocks = {
10
+ blocksConfig: {
11
+ title: {
12
+ view: () => <div>Title Block Component</div>,
13
+ },
14
+ },
15
+ };
16
+
17
+ const mockStore = configureStore();
18
+
19
+ describe('RedirectToLogin', () => {
20
+ it('redirects to login if no token', () => {
21
+ const store = mockStore({
22
+ userSession: { token: '1234' },
23
+ intl: {
24
+ locale: 'en',
25
+ messages: {},
26
+ },
27
+ });
28
+ const history = { push: jest.fn(() => null) };
29
+ const location = {
30
+ pathname: '/en/metadata/add',
31
+ search: '?type=NewsItem',
32
+ };
33
+
34
+ render(
35
+ <Provider store={store}>
36
+ <MemoryRouter>
37
+ <RedirectToLogin history={history} token={null} location={location} />
38
+ </MemoryRouter>
39
+ </Provider>,
40
+ );
41
+
42
+ expect(history.push.mock.calls[0][0]).toBe(
43
+ '/login?return_url=%2Fen%2Fmetadata%2Fadd%3Ftype%3DNewsItem',
44
+ );
45
+ });
46
+
47
+ it('does not redirect to login if token', () => {
48
+ const store = mockStore({
49
+ userSession: { token: '1234' },
50
+ intl: {
51
+ locale: 'en',
52
+ messages: {},
53
+ },
54
+ });
55
+ const history = { push: jest.fn(() => null) };
56
+ const location = {
57
+ pathname: '/en/metadata/add',
58
+ search: '?type=NewsItem',
59
+ };
60
+
61
+ render(
62
+ <Provider store={store}>
63
+ <MemoryRouter>
64
+ <RedirectToLogin
65
+ history={history}
66
+ token={'something'}
67
+ location={location}
68
+ />
69
+ </MemoryRouter>
70
+ </Provider>,
71
+ );
72
+
73
+ expect(history.push.mock.calls).toHaveLength(0);
74
+ });
75
+ });
@@ -1,58 +1,73 @@
1
1
  import React from 'react';
2
+ import { useIntl, defineMessages, FormattedMessage } from 'react-intl';
2
3
  import { Grid, Container, Segment } from 'semantic-ui-react';
3
4
  import {
4
- DocumentsList,
5
5
  HTMLField,
6
- BannerTitle,
7
6
  EventDetails,
7
+ DocumentsList,
8
8
  } from '@eeacms/volto-cca-policy/helpers';
9
9
  import { PortalMessage } from '@eeacms/volto-cca-policy/components';
10
- import { FormattedMessage } from 'react-intl';
10
+ import { filterBlocks } from '@eeacms/volto-cca-policy/utils';
11
+ import RenderBlocks from '@plone/volto/components/theme/View/RenderBlocks';
12
+
13
+ const messages = defineMessages({
14
+ download_agenda: {
15
+ id: 'Download the detailed agenda',
16
+ defaultMessage: 'Download the detailed agenda',
17
+ },
18
+ download_documents: {
19
+ id: 'A background document for the event is available',
20
+ defaultMessage: 'A background document for the event is available',
21
+ },
22
+ });
23
+
24
+ const DocumentSection = ({ title, file }) => (
25
+ <DocumentsList
26
+ content={{
27
+ show_counter: false,
28
+ section_title: title,
29
+ cca_files: [
30
+ {
31
+ url: file?.download,
32
+ title: file?.filename,
33
+ },
34
+ ],
35
+ }}
36
+ />
37
+ );
11
38
 
12
39
  function CcaEventView(props) {
40
+ const intl = useIntl();
13
41
  const { content } = props;
14
- const { event_language } = content;
15
- // cca_files: [content.agenda_file]}
16
- if (content.agenda_file) {
17
- content.agenda_file['url'] = content.agenda_file['download'];
18
- content.agenda_file['title'] = content.agenda_file['filename'];
19
- }
20
- if (content.background_documents) {
21
- content.background_documents['url'] =
22
- content.background_documents['download'];
23
- content.background_documents['title'] =
24
- content.background_documents['filename'];
25
- }
26
- const agenda_files = {
27
- section_title: 'Download the detailed agenda',
28
- cca_files: [content.agenda_file],
29
- show_counter: false,
30
- };
31
- const background_documents = {
32
- section_title: 'A background document for the event is available ',
33
- cca_files: [content.background_documents],
34
- show_counter: false,
35
- };
42
+ const {
43
+ event_language,
44
+ agenda_file,
45
+ background_documents,
46
+ participation,
47
+ contact_email,
48
+ } = content;
49
+
50
+ const {
51
+ blocks: filtered_blocks,
52
+ blocks_layout: filtered_blocks_layout,
53
+ } = filterBlocks(content, 'tabs_block');
36
54
 
37
55
  return (
38
56
  <div className="cca-event-view">
39
- <BannerTitle
40
- content={{ ...content, '@type': 'Climate adapt event' }}
41
- data={{
42
- info: [{ description: '' }],
43
- hideContentType: false,
44
- hideCreationDate: false,
45
- hideModificationDate: false,
46
- hidePublishingDate: false,
47
- hideDownloadButton: false,
48
- hideShareButton: false,
57
+ <RenderBlocks
58
+ {...props}
59
+ content={{
60
+ ...content,
61
+ '@type': 'climate-adapt-event',
62
+ blocks: filtered_blocks,
63
+ blocks_layout: filtered_blocks_layout,
49
64
  }}
50
65
  />
51
66
 
52
67
  <Container>
53
68
  <PortalMessage content={content} />
54
69
  <Grid columns="12">
55
- <div className="row">
70
+ <Grid.Row>
56
71
  <Grid.Column
57
72
  mobile={12}
58
73
  tablet={12}
@@ -69,9 +84,18 @@ function CcaEventView(props) {
69
84
  </h2>
70
85
  <HTMLField value={content.agenda} />
71
86
 
72
- {content?.agenda_file && <DocumentsList content={agenda_files} />}
73
- {content?.background_documents && (
74
- <DocumentsList content={background_documents} />
87
+ {agenda_file && (
88
+ <DocumentSection
89
+ title={intl.formatMessage(messages.download_agenda)}
90
+ file={agenda_file}
91
+ />
92
+ )}
93
+
94
+ {background_documents && (
95
+ <DocumentSection
96
+ title={intl.formatMessage(messages.download_documents)}
97
+ file={background_documents}
98
+ />
75
99
  )}
76
100
 
77
101
  <h2>
@@ -86,20 +110,21 @@ function CcaEventView(props) {
86
110
  defaultMessage="Participation"
87
111
  />
88
112
  </h3>
89
- <HTMLField value={content.participation} />
113
+ <HTMLField value={participation} />
90
114
 
91
115
  <h2>
92
116
  <FormattedMessage id="Contact" defaultMessage="Contact" />
93
117
  </h2>
94
- <p>
95
- <FormattedMessage
96
- id="If you have any further questions you can contact"
97
- defaultMessage="If you have any further questions you can contact"
98
- />{' '}
99
- <a href="mailto:{content.contact_email}">
100
- {content.contact_email}
101
- </a>
102
- </p>
118
+
119
+ {contact_email && (
120
+ <p>
121
+ <FormattedMessage
122
+ id="If you have any further questions you can contact"
123
+ defaultMessage="If you have any further questions you can contact"
124
+ />{' '}
125
+ <a href={`mailto:${contact_email}`}>{contact_email}</a>
126
+ </p>
127
+ )}
103
128
 
104
129
  {event_language && (
105
130
  <>
@@ -123,7 +148,7 @@ function CcaEventView(props) {
123
148
  <EventDetails {...props} />
124
149
  </Segment>
125
150
  </Grid.Column>
126
- </div>
151
+ </Grid.Row>
127
152
  </Grid>
128
153
  </Container>
129
154
  </div>
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ import DefaultView from '@plone/volto/components/theme/View/DefaultView';
4
4
  import {
5
5
  RASTWidgetView,
6
6
  TranslationDisclaimer,
7
+ RedirectToLogin,
7
8
  } from '@eeacms/volto-cca-policy/components';
8
9
  import { blockAvailableInMission } from '@eeacms/volto-cca-policy/utils';
9
10
 
@@ -382,6 +383,12 @@ const applyConfig = (config) => {
382
383
  match: '',
383
384
  component: TranslationDisclaimer,
384
385
  },
386
+ {
387
+ match: {
388
+ path: /(.*)\/add/,
389
+ },
390
+ component: RedirectToLogin,
391
+ },
385
392
  ];
386
393
 
387
394
  config.settings.apiExpanders = [