@eeacms/volto-datahub 1.0.24 → 1.0.25

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,6 +4,19 @@ 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
+ ### [1.0.25](https://github.com/eea/volto-datahub/compare/1.0.24...1.0.25) - 15 August 2023
8
+
9
+ #### :house: Documentation changes
10
+
11
+ - docs: Cleanup Makefile, update DEVELOP documentation, i18n - refs #254894 [valentinab25 - [`7c942a0`](https://github.com/eea/volto-datahub/commit/7c942a004214f5f2f66f690372be2febfb743491)]
12
+
13
+ #### :hammer_and_wrench: Others
14
+
15
+ - Update Jenkinsfile [kreafox - [`4a950b1`](https://github.com/eea/volto-datahub/commit/4a950b19149a6ecc1d04e974b94c242d563731e1)]
16
+ - Fix sonarqube issues to improve code quality [kreafox - [`8bd8364`](https://github.com/eea/volto-datahub/commit/8bd83646fb39611d5fb93a342d562dfa255f264c)]
17
+ - Configure externals [Tiberiu Ichim - [`72eef0f`](https://github.com/eea/volto-datahub/commit/72eef0fcaf30440b9a0eb2523975a2a0d6e011a6)]
18
+ - Add rss middleware [Tiberiu Ichim - [`61b215b`](https://github.com/eea/volto-datahub/commit/61b215b64bf6908421ce5c411f0a834bff11929e)]
19
+ - Linking to accordion item on datahub item page [kreafox - [`1e3768c`](https://github.com/eea/volto-datahub/commit/1e3768cd96343ea837431e6e61327f67c0ced1c8)]
7
20
  ### [1.0.24](https://github.com/eea/volto-datahub/compare/1.0.23...1.0.24) - 13 June 2023
8
21
 
9
22
  #### :hammer_and_wrench: Others
package/DEVELOP.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  ## Develop
4
4
 
5
+ 1. Make sure you have `docker` and `docker compose` installed and running on your machine:
6
+
7
+ ```Bash
8
+ git clone https://github.com/eea/volto-datahub.git
9
+ cd volto-datahub
10
+ git checkout -b bugfix-123456 develop
11
+ make
12
+ make start
13
+ ```
14
+
15
+ 1. Wait for `Volto started at 0.0.0.0:3000` meesage
16
+
17
+ 1. Go to http://localhost:3000
18
+
19
+ 1. Happy hacking!
20
+
21
+ ```Bash
22
+ cd src/addons/volto-datahub/
23
+ ```
24
+
25
+ ### Or add @eeacms/volto-datahub to your Volto project
26
+
5
27
  Before starting make sure your development environment is properly set. See [Volto Developer Documentation](https://docs.voltocms.com/getting-started/install/)
6
28
 
7
29
  1. Make sure you have installed `yo`, `@plone/generator-volto` and `mrs-developer`
@@ -50,3 +72,37 @@ Before starting make sure your development environment is properly set. See [Vol
50
72
 
51
73
  cd src/addons/volto-datahub/
52
74
  cd src/addons/volto-addon-template/
75
+
76
+ ## Cypress
77
+
78
+ To run cypress locally, first make sure you don't have any Volto/Plone running on ports `8080` and `3000`.
79
+
80
+ You don't have to be in a `clean-volto-project`, you can be in any Volto Frontend
81
+ project where you added `volto-datahub` to `mrs.developer.json`
82
+
83
+ Go to:
84
+
85
+ ```BASH
86
+ cd src/addons/volto-datahub/
87
+ ```
88
+
89
+ Start:
90
+
91
+ ```Bash
92
+ make
93
+ make start
94
+ ```
95
+
96
+ This will build and start with Docker a clean `Plone backend` and `Volto Frontend` with `volto-datahub` block installed.
97
+
98
+ Open Cypress Interface:
99
+
100
+ ```Bash
101
+ make cypress-open
102
+ ```
103
+
104
+ Or run it:
105
+
106
+ ```Bash
107
+ make cypress-run
108
+ ```
package/README.md CHANGED
@@ -1,43 +1,56 @@
1
- # volto-addon-template
1
+ # volto-datahub
2
2
 
3
- [![Releases](https://img.shields.io/github/v/release/eea/volto-addon-template)](https://github.com/eea/volto-addon-template/releases)
3
+ [![Releases](https://img.shields.io/github/v/release/eea/volto-datahub)](https://github.com/eea/volto-datahub/releases)
4
4
 
5
- [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-addon-template%2Fmaster&subject=master)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-addon-template/job/master/display/redirect)
6
- [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-addon-template-master&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-addon-template-master)
7
- [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-addon-template-master&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-addon-template-master)
8
- [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-addon-template-master&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-addon-template-master)
9
- [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-addon-template-master&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-addon-template-master)
5
+ [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-datahub%2Fmaster&subject=master)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-datahub/job/master/display/redirect)
6
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-datahub-master&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-datahub-master)
7
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-datahub-master&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-datahub-master)
8
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-datahub-master&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-datahub-master)
9
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-datahub-master&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-datahub-master)
10
10
 
11
- [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-addon-template%2Fdevelop&subject=develop)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-addon-template/job/develop/display/redirect)
12
- [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-addon-template-develop&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-addon-template-develop)
13
- [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-addon-template-develop&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-addon-template-develop)
14
- [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-addon-template-develop&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-addon-template-develop)
15
- [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-addon-template-develop&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-addon-template-develop)
11
+ [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-datahub%2Fdevelop&subject=develop)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-datahub/job/develop/display/redirect)
12
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-datahub-develop&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-datahub-develop)
13
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-datahub-develop&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-datahub-develop)
14
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-datahub-develop&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-datahub-develop)
15
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-datahub-develop&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-datahub-develop)
16
16
 
17
17
 
18
- EEA DataHub search [Volto](https://github.com/plone/volto) add-on
18
+ [Volto](https://github.com/plone/volto) add-on
19
19
 
20
- ## Demo
20
+ ## Features
21
21
 
22
- - https://demo-www.eea.europa.eu/en/datahub
22
+ Demo GIF
23
23
 
24
24
  ## Getting started
25
25
 
26
- ### Add volto-addon-template to your Volto project
26
+ ### Try volto-datahub with Docker
27
+
28
+ git clone https://github.com/eea/volto-datahub.git
29
+ cd volto-datahub
30
+ make
31
+ make start
32
+
33
+ Go to http://localhost:3000
34
+
35
+ ### Add volto-datahub to your Volto project
27
36
 
28
37
  1. Make sure you have a [Plone backend](https://plone.org/download) up-and-running at http://localhost:8080/Plone
29
38
 
39
+ ```Bash
40
+ docker compose up backend
41
+ ```
42
+
30
43
  1. Start Volto frontend
31
44
 
32
45
  * If you already have a volto project, just update `package.json`:
33
46
 
34
47
  ```JSON
35
48
  "addons": [
36
- "@eeacms/volto-addon-template"
49
+ "@eeacms/volto-datahub"
37
50
  ],
38
51
 
39
52
  "dependencies": {
40
- "@eeacms/volto-addon-template": "*"
53
+ "@eeacms/volto-datahub": "*"
41
54
  }
42
55
  ```
43
56
 
@@ -45,7 +58,7 @@ EEA DataHub search [Volto](https://github.com/plone/volto) add-on
45
58
 
46
59
  ```
47
60
  npm install -g yo @plone/generator-volto
48
- yo @plone/volto my-volto-project --addon @eeacms/volto-addon-template
61
+ yo @plone/volto my-volto-project --canary --addon @eeacms/volto-datahub
49
62
  cd my-volto-project
50
63
  ```
51
64
 
@@ -62,20 +75,19 @@ EEA DataHub search [Volto](https://github.com/plone/volto) add-on
62
75
 
63
76
  ## Release
64
77
 
65
- See [RELEASE.md](https://github.com/eea/volto-addon-template/blob/master/RELEASE.md).
78
+ See [RELEASE.md](https://github.com/eea/volto-datahub/blob/master/RELEASE.md).
66
79
 
67
80
  ## How to contribute
68
81
 
69
- See [DEVELOP.md](https://github.com/eea/volto-addon-template/blob/master/DEVELOP.md).
82
+ See [DEVELOP.md](https://github.com/eea/volto-datahub/blob/master/DEVELOP.md).
70
83
 
71
84
  ## Copyright and license
72
85
 
73
86
  The Initial Owner of the Original Code is European Environment Agency (EEA).
74
87
  All Rights Reserved.
75
88
 
76
- See [LICENSE.md](https://github.com/eea/volto-addon-template/blob/master/LICENSE.md) for details.
89
+ See [LICENSE.md](https://github.com/eea/volto-datahub/blob/master/LICENSE.md) for details.
77
90
 
78
91
  ## Funding
79
92
 
80
93
  [European Environment Agency (EU)](http://eea.europa.eu)
81
-
@@ -0,0 +1,28 @@
1
+ version: "3"
2
+ services:
3
+ backend:
4
+ image: plone/plone-backend:${PLONE_VERSION:-6}
5
+ ports:
6
+ - "8080:8080"
7
+ environment:
8
+ SITE: "Plone"
9
+
10
+ frontend:
11
+ build:
12
+ context: ./
13
+ dockerfile: ./Dockerfile
14
+ args:
15
+ ADDON_NAME: "${ADDON_NAME}"
16
+ ADDON_PATH: "${ADDON_PATH}"
17
+ VOLTO_VERSION: ${VOLTO_VERSION:-16}
18
+ ports:
19
+ - "3000:3000"
20
+ - "3001:3001"
21
+ depends_on:
22
+ - backend
23
+ volumes:
24
+ - ./:/app/src/addons/${ADDON_PATH}
25
+ environment:
26
+ RAZZLE_INTERNAL_API_PATH: "http://backend:8080/Plone"
27
+ RAZZLE_DEV_PROXY_API_PATH: "http://backend:8080/Plone"
28
+ HOST: "0.0.0.0"
@@ -0,0 +1,14 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: \n"
8
+ "Language: \n"
9
+ "Language-Team: \n"
10
+ "Content-Type: \n"
11
+ "Content-Transfer-Encoding: \n"
12
+ "Plural-Forms: \n"
13
+
14
+
@@ -0,0 +1,14 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: \n"
8
+ "Language: \n"
9
+ "Language-Team: \n"
10
+ "Content-Type: \n"
11
+ "Content-Transfer-Encoding: \n"
12
+ "Plural-Forms: \n"
13
+
14
+
@@ -0,0 +1,14 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: \n"
8
+ "Language: \n"
9
+ "Language-Team: \n"
10
+ "Content-Type: \n"
11
+ "Content-Transfer-Encoding: \n"
12
+ "Plural-Forms: \n"
13
+
14
+
package/locales/volto.pot CHANGED
@@ -0,0 +1,16 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Plone\n"
4
+ "POT-Creation-Date: 2023-06-28T10:48:22.678Z\n"
5
+ "Last-Translator: Plone i18n <plone-i18n@lists.sourceforge.net>\n"
6
+ "Language-Team: Plone i18n <plone-i18n@lists.sourceforge.net>\n"
7
+ "MIME-Version: 1.0\n"
8
+ "Content-Type: text/plain; charset=utf-8\n"
9
+ "Content-Transfer-Encoding: 8bit\n"
10
+ "Plural-Forms: nplurals=1; plural=0;\n"
11
+ "Language-Code: en\n"
12
+ "Language-Name: English\n"
13
+ "Preferred-Encodings: utf-8\n"
14
+ "Domain: volto\n"
15
+
16
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-datahub",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "@eeacms/volto-datahub: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -18,7 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@eeacms/volto-globalsearch": "*",
21
- "@eeacms/volto-listing-block": "*"
21
+ "@eeacms/volto-listing-block": "*",
22
+ "feed": "4.2.2"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@cypress/code-coverage": "^3.10.0",
@@ -79,52 +79,6 @@ const DatasetItemDownloadList = (props) => {
79
79
  </List.Item>
80
80
  );
81
81
  })}
82
-
83
- {/* {(dataset['EEA:FILEPATH'] || []).map((item, i) => {
84
- return (
85
- <List.Item key={i}>
86
- <List.Content>
87
- <div className="dataset-item">
88
- <Icon className="download" />
89
- <a
90
- href={item.url}
91
- className="item-link"
92
- target="_blank"
93
- rel="noreferrer"
94
- >
95
- WebDAV: {item.name || item.function}
96
- </a>
97
- {isInternalURL(item.url) && (
98
- <SVGIcon name={lockSVG} size="18" />
99
- )}
100
- </div>
101
- </List.Content>
102
- </List.Item>
103
- );
104
- })}
105
-
106
- {(dataset['EEA:FOLDERPATH'] || []).map((item, i) => {
107
- return (
108
- <List.Item key={i}>
109
- <List.Content>
110
- <div className="dataset-item">
111
- <Icon className="download" />
112
- <a
113
- href={item.url}
114
- className="item-link"
115
- target="_blank"
116
- rel="noreferrer"
117
- >
118
- WebDAV1: {item.name || item.function}
119
- </a>
120
- {isInternalURL(item.url) && (
121
- <SVGIcon name={lockSVG} size="18" />
122
- )}
123
- </div>
124
- </List.Content>
125
- </List.Item>
126
- );
127
- })} */}
128
82
  </List>
129
83
  </>
130
84
  )}
@@ -139,9 +93,6 @@ const DatasetItemDownloadList = (props) => {
139
93
  <List.Content>
140
94
  <div>
141
95
  <SVGIcon name={servicesSVG} size="18" />
142
- {/* {(item.name || item.description) && (
143
- <span className="item-protocol">{item.protocol}:</span>
144
- )} */}
145
96
  <a
146
97
  className="item-link"
147
98
  href={item.url}
@@ -165,9 +116,6 @@ const DatasetItemDownloadList = (props) => {
165
116
  <List.Content>
166
117
  <div>
167
118
  <SVGIcon name={servicesSVG} size="18" />
168
- {/* {(item.name || item.description) && (
169
- <span className="item-protocol">{item.protocol}:</span>
170
- )} */}
171
119
  <a
172
120
  className="item-link"
173
121
  href={item.url}
@@ -1,35 +1,109 @@
1
1
  import React from 'react';
2
- import { Accordion } from 'semantic-ui-react';
3
- import { Icon } from 'semantic-ui-react';
2
+ import { Accordion, Icon } from 'semantic-ui-react';
4
3
  import { DateTime } from '@eeacms/search';
5
4
  import { isInternal, SVGIcon, isObsolete } from '../utils.js';
6
5
  import DatasetItemDownloadList from './DatasetItemDownloadList';
7
6
 
7
+ import AnimateHeight from 'react-animate-height';
8
+
8
9
  import lockSVG from 'remixicon/icons/System/lock-line.svg';
9
10
 
11
+ import { useLocation, useHistory } from 'react-router-dom';
12
+
13
+ const useQuery = (location) => {
14
+ const { search } = location;
15
+ return React.useMemo(() => new URLSearchParams(search), [search]);
16
+ };
17
+
10
18
  const DatasetItemsList = (props) => {
11
- const { appConfig, item, setActiveTabIndex, activeTabIndex } = props;
19
+ const { appConfig, item, setActiveAccordion } = props;
20
+
21
+ const location = useLocation();
22
+ const history = useHistory();
23
+ const query = useQuery(location);
24
+ const { search } = useLocation();
25
+
26
+ const activePanels = query.get('activeAccordion')?.split(',') || [];
27
+ const [itemToScroll, setItemToScroll] = React.useState('');
28
+ const [activeIndex, setActiveIndex] = React.useState([]);
29
+ const [activePanel, setActivePanel] = React.useState([]);
30
+ const activePanelsRef = React.useRef(activePanels);
31
+
32
+ const addQueryParam = (key, value) => {
33
+ const searchParams = new URLSearchParams(location.search);
34
+ searchParams.set(key, value);
35
+
36
+ history.push({
37
+ hash: location.hash,
38
+ pathname: location.pathname,
39
+ search: searchParams.toString(),
40
+ });
41
+ };
12
42
 
13
- const [activeIndex, setActiveIndex] = React.useState(activeTabIndex);
43
+ React.useEffect(() => {
44
+ const query = new URLSearchParams(search);
45
+ const panels = query.get('activeAccordion')?.split(',') || [];
46
+ setActiveAccordion(panels);
47
+ }, [search, setActiveAccordion]);
48
+
49
+ const handleClick = (e, titleProps) => {
50
+ const { index, id } = titleProps;
51
+
52
+ const newIndex =
53
+ activeIndex.indexOf(index) === -1
54
+ ? [...activeIndex, index]
55
+ : activeIndex.filter((item) => item !== index);
56
+
57
+ const newPanel =
58
+ activePanel.indexOf(id) === -1
59
+ ? [...activePanel, id]
60
+ : activePanel.filter((item) => item !== id);
61
+
62
+ handleActiveIndex(newIndex, newPanel);
63
+ };
64
+
65
+ const handleActiveIndex = (index, id) => {
66
+ setActiveIndex(index);
67
+ setActivePanel(id);
68
+ addQueryParam('activeAccordion', id);
69
+ };
70
+
71
+ const scrollToElement = () => {
72
+ if (!!activePanels && !!activePanels[0].length) {
73
+ let element = document.getElementById(
74
+ activePanels[activePanels.length - 1],
75
+ );
76
+ element.scrollIntoView({ behavior: 'smooth' });
77
+ }
78
+ };
79
+
80
+ const isActive = (id) => {
81
+ return activePanel.includes(id);
82
+ };
14
83
 
15
84
  React.useEffect(() => {
16
- setActiveIndex(activeTabIndex);
17
- }, [activeTabIndex]);
85
+ const firstAccordion = item?.children?.[0].id;
86
+ if (activePanel.length < 1) {
87
+ setActivePanel([firstAccordion]);
88
+ }
89
+ }, [activePanel.length, item.children]);
18
90
 
19
91
  React.useEffect(() => {
20
- setActiveTabIndex(activeIndex);
21
- }, [activeIndex, setActiveTabIndex]);
92
+ !!activePanelsRef.current &&
93
+ setItemToScroll(
94
+ activePanelsRef.current[activePanelsRef.current?.length - 1],
95
+ );
96
+ }, []);
22
97
 
23
- function handleClick(e, titleProps) {
24
- const { index } = titleProps;
25
- const newIndex = activeIndex === index ? -1 : index;
26
- setActiveIndex(newIndex);
27
- }
98
+ React.useEffect(() => {
99
+ setActivePanel(activePanelsRef.current || []);
100
+ }, []);
28
101
 
29
102
  return (
30
103
  <Accordion>
31
104
  {item?.children.map((dataset, index) => {
32
105
  const {
106
+ id,
33
107
  resourceTemporalExtentDetails,
34
108
  temporalDateRange,
35
109
  publicationDateForResource,
@@ -37,12 +111,12 @@ const DatasetItemsList = (props) => {
37
111
  const archived = isObsolete(dataset.cl_status);
38
112
 
39
113
  return (
40
- <React.Fragment key={index}>
114
+ <div key={index} id={id}>
41
115
  <Accordion.Title
42
116
  tabIndex={0}
43
- active={activeIndex === index}
117
+ active={isActive(id)}
44
118
  index={index}
45
- onClick={handleClick}
119
+ onClick={(e) => handleClick(e, { index, id })}
46
120
  onKeyDown={(e) => {
47
121
  if (e.key === 'Enter') {
48
122
  handleClick(e, { index });
@@ -51,7 +125,6 @@ const DatasetItemsList = (props) => {
51
125
  >
52
126
  <span className="dataset-title">
53
127
  {dataset.resourceTitleObject.default}
54
-
55
128
  <span className="formats">
56
129
  {(dataset.format || [])
57
130
  .filter((item, pos, self) => self.indexOf(item) === pos)
@@ -93,49 +166,61 @@ const DatasetItemsList = (props) => {
93
166
  </span>
94
167
  <Icon className="ri-arrow-down-s-line" />
95
168
  </Accordion.Title>
96
- <Accordion.Content active={activeIndex === index}>
97
- <div className="dataset-content">
98
- <div>
99
- {publicationDateForResource && (
100
- <div>
101
- <strong>Published: </strong>
102
- <DateTime
103
- format="DATE_MED"
104
- value={publicationDateForResource}
105
- />
106
- </div>
107
- )}
108
-
109
- {resourceTemporalExtentDetails &&
110
- resourceTemporalExtentDetails?.length > 0 && (
169
+ <AnimateHeight
170
+ animateOpacity
171
+ duration={500}
172
+ height={isActive(id) ? 'auto' : 0}
173
+ onTransitionEnd={() => {
174
+ if (!!activePanels && id === itemToScroll) {
175
+ setItemToScroll('');
176
+ scrollToElement();
177
+ }
178
+ }}
179
+ >
180
+ <Accordion.Content active={isActive(id)}>
181
+ <div className="dataset-content">
182
+ <div>
183
+ {publicationDateForResource && (
111
184
  <div>
112
- <strong>Temporal coverage: </strong>
113
- {temporalDateRange}
185
+ <strong>Published: </strong>
186
+ <DateTime
187
+ format="DATE_MED"
188
+ value={publicationDateForResource}
189
+ />
114
190
  </div>
115
191
  )}
116
- </div>
117
192
 
118
- {dataset.resourceType[0] !== 'nonGeographicDataset' && (
119
- <div className="dataset-pdf">
120
- <div className="d-link">
121
- <Icon className="file pdf" />
122
- <a
123
- target="_blank"
124
- rel="noreferrer"
125
- href={`${appConfig.indexBaseUrl}/catalogue/datahub/api/records/${dataset.metadataIdentifier}/formatters/xsl-view?output=pdf&language=eng&approved=true`}
126
- >
127
- Metadata Factsheet
128
- </a>
129
- </div>
193
+ {resourceTemporalExtentDetails &&
194
+ resourceTemporalExtentDetails?.length > 0 && (
195
+ <div>
196
+ <strong>Temporal coverage: </strong>
197
+ {temporalDateRange}
198
+ </div>
199
+ )}
130
200
  </div>
131
- )}
132
- </div>
133
201
 
134
- {!!dataset.link && dataset.link.length > 0 && (
135
- <DatasetItemDownloadList link={dataset.link} />
136
- )}
137
- </Accordion.Content>
138
- </React.Fragment>
202
+ {dataset.resourceType[0] !== 'nonGeographicDataset' && (
203
+ <div className="dataset-pdf">
204
+ <div className="d-link">
205
+ <Icon className="file pdf" />
206
+ <a
207
+ target="_blank"
208
+ rel="noreferrer"
209
+ href={`${appConfig.indexBaseUrl}/catalogue/datahub/api/records/${dataset.metadataIdentifier}/formatters/xsl-view?output=pdf&language=eng&approved=true`}
210
+ >
211
+ Metadata Factsheet
212
+ </a>
213
+ </div>
214
+ </div>
215
+ )}
216
+ </div>
217
+
218
+ {!!dataset.link && dataset.link.length > 0 && (
219
+ <DatasetItemDownloadList link={dataset.link} />
220
+ )}
221
+ </Accordion.Content>
222
+ </AnimateHeight>
223
+ </div>
139
224
  );
140
225
  })}
141
226
  </Accordion>
@@ -4,34 +4,28 @@ import { Tab, Menu } from 'semantic-ui-react';
4
4
  import DatasetItemsList from './DatasetItemsList';
5
5
 
6
6
  const DatasetsTab = (props) => {
7
- const { items, appConfig, defaultAccordionOpenIndex } = props;
8
-
9
- const [activeAccordionIndex, setActiveAccordionIndex] = React.useState(
10
- defaultAccordionOpenIndex,
11
- );
7
+ const { items, appConfig } = props;
12
8
 
13
9
  const [activeTabIndex, setActiveTabIndex] = React.useState(0);
10
+ const [activeAccordionId, setActiveAccordionId] = React.useState();
14
11
 
15
12
  React.useEffect(() => {
16
- if (defaultAccordionOpenIndex !== undefined) {
17
- setActiveAccordionIndex(defaultAccordionOpenIndex);
18
- } else {
19
- setActiveAccordionIndex(-1);
20
- }
21
- }, [defaultAccordionOpenIndex]);
13
+ const lastAccordionSelected =
14
+ activeAccordionId?.[activeAccordionId.length - 1];
15
+
16
+ const activeTab = items.filter((item) =>
17
+ item.children.find((child) => child.id === lastAccordionSelected),
18
+ );
19
+ setActiveTabIndex(activeTab?.[0]?.id);
20
+ }, [activeAccordionId, items]);
21
+
22
+ const handleTabChange = (e, { activeIndex }) => {
23
+ setActiveTabIndex(activeIndex);
24
+ };
22
25
 
23
26
  const panes = (items || []).map((item, i) => ({
24
27
  menuItem: (
25
- <Menu.Item
26
- key={i}
27
- tabIndex={0}
28
- onClick={() => setActiveTabIndex(i)}
29
- onKeyDown={(e) => {
30
- if (e.key === 'Enter') {
31
- setActiveTabIndex(i);
32
- }
33
- }}
34
- >
28
+ <Menu.Item key={i} tabIndex={0}>
35
29
  {item.date ? <span>{item.date}</span> : 'No date'}
36
30
  </Menu.Item>
37
31
  ),
@@ -40,8 +34,7 @@ const DatasetsTab = (props) => {
40
34
  <DatasetItemsList
41
35
  appConfig={appConfig}
42
36
  item={item}
43
- activeTabIndex={activeAccordionIndex}
44
- setActiveTabIndex={setActiveAccordionIndex}
37
+ setActiveAccordion={setActiveAccordionId}
45
38
  />
46
39
  </Tab.Pane>
47
40
  ),
@@ -53,9 +46,7 @@ const DatasetsTab = (props) => {
53
46
  activeIndex={activeTabIndex}
54
47
  menu={{ vertical: true, secondary: true, pointing: true }}
55
48
  panes={panes}
56
- onTabChange={() => {
57
- setActiveAccordionIndex(0);
58
- }}
49
+ onTabChange={handleTabChange}
59
50
  />
60
51
  );
61
52
  };
@@ -49,8 +49,8 @@ const DatasetsView = (props) => {
49
49
  return b - a;
50
50
  });
51
51
 
52
- const groupedDatasets = sortedDatasets.map((v) => {
53
- return { date: v, children: datasetsByCoverage[v] };
52
+ const groupedDatasets = sortedDatasets.map((v, i) => {
53
+ return { id: i, date: v, children: datasetsByCoverage[v] };
54
54
  });
55
55
 
56
56
  return groupedDatasets;
@@ -71,7 +71,6 @@ const DatasetsView = (props) => {
71
71
  <DatasetsTab
72
72
  appConfig={appConfig}
73
73
  items={groupedByTemporalCoverage}
74
- defaultAccordionOpenIndex={0}
75
74
  />
76
75
  </>
77
76
  )}
@@ -4,7 +4,7 @@ import { useDispatch, useSelector } from 'react-redux';
4
4
  import { Link, useLocation } from 'react-router-dom';
5
5
  import { Container, Icon, Button } from 'semantic-ui-react';
6
6
  import { Toolbar } from '@plone/volto/components';
7
- import { BodyClass } from '@plone/volto/helpers';
7
+ import { BodyClass, asyncConnect, Helmet } from '@plone/volto/helpers';
8
8
  import config from '@plone/volto/registry';
9
9
  import { rebind, applyConfigurationSchema } from '@eeacms/search';
10
10
  import { Callout, Banner } from '@eeacms/volto-eea-design-system/ui';
@@ -13,8 +13,6 @@ import {
13
13
  MetadataSection,
14
14
  DatasetsView,
15
15
  } from '@eeacms/volto-datahub/components/ItemView';
16
-
17
- import { asyncConnect, Helmet } from '@plone/volto/helpers';
18
16
  import { fetchResult } from '@eeacms/search/lib/hocs/useResult';
19
17
  import { setDatahubResult } from '@eeacms/volto-datahub/store';
20
18
 
@@ -51,7 +49,6 @@ function IsomorphicPortal({ children }) {
51
49
  function ItemView(props) {
52
50
  const { docid, staticContext } = props;
53
51
  const dispatch = useDispatch();
54
- // const content = useSelector((state) => state.content.data);
55
52
  let result = useSelector((state) => state.datahub_results?.[docid]);
56
53
  if (__SERVER__ && !result?._original?.found) {
57
54
  staticContext.error_code = 404;
@@ -0,0 +1,128 @@
1
+ import { render, cleanup, fireEvent } from '@testing-library/react';
2
+ import {
3
+ isObsolete,
4
+ isInternalURL,
5
+ isInternal,
6
+ groupBy,
7
+ SVGIcon,
8
+ } from './utils';
9
+
10
+ describe('isObsolete', () => {
11
+ it('should return true if status array contains obsolete keys', () => {
12
+ const status = [{ key: 'obsolete' }, { key: 'active' }];
13
+ expect(isObsolete(status)).toBe(true);
14
+ });
15
+
16
+ it('should return true if single status object key is obsolete', () => {
17
+ const status = { key: 'superseded' };
18
+ expect(isObsolete(status)).toBe(true);
19
+ });
20
+
21
+ it('should return false if status array does not contain obsolete keys', () => {
22
+ const status = [{ key: 'active' }];
23
+ expect(isObsolete(status)).toBe(false);
24
+ });
25
+
26
+ it('should return false if single status object key is not obsolete', () => {
27
+ const status = { key: 'active' };
28
+ expect(isObsolete(status)).toBe(false);
29
+ });
30
+
31
+ it('should return false if status is undefined', () => {
32
+ const status = undefined;
33
+ expect(isObsolete(status)).toBe(false);
34
+ });
35
+ });
36
+
37
+ describe('isInternalURL', () => {
38
+ it('should return true if a part of the URL contains "_i" as the seventh substring split by "_"', () => {
39
+ const url = 'https://test.com/a/b/c/d/e/f/h_i_j_k_l_m_i_n/o/p';
40
+ expect(isInternalURL(url)).toBe(true);
41
+ });
42
+
43
+ it('should return false if no part of the URL contains "_i" as the seventh substring split by "_"', () => {
44
+ const url = 'https://test.com/a/b/c/d/e/f/h_i_j_k_l_m_n/o/p';
45
+ expect(isInternalURL(url)).toBe(false);
46
+ });
47
+ });
48
+
49
+ describe('isInternal', () => {
50
+ it('should return true if any link in the item is internal', () => {
51
+ const item = {
52
+ link: [{ url: 'https://test.com/a/b/c/d/e/f/h_i_j_k_l_m_i_n/o/p' }],
53
+ };
54
+ expect(isInternal(item)).toBe(true);
55
+ });
56
+
57
+ it('should return false if link is undefined', () => {
58
+ const item = {
59
+ link: undefined,
60
+ };
61
+ expect(isInternal(item)).toBe(false);
62
+ });
63
+
64
+ it('should return false if no link in the item is internal', () => {
65
+ const item = {
66
+ link: [{ url: 'https://test.com/a/b/c/d/e/f/h_i_j_k_l_m_n/o/p' }],
67
+ };
68
+ expect(isInternal(item)).toBe(false);
69
+ });
70
+ });
71
+
72
+ describe('groupBy', () => {
73
+ it('should group array of objects by specified key', () => {
74
+ const arr = [
75
+ { id: 1, name: 'test1' },
76
+ { id: 2, name: 'test2' },
77
+ { id: 1, name: 'test3' },
78
+ ];
79
+ expect(groupBy(arr, 'id')).toEqual({
80
+ '1': [
81
+ { id: 1, name: 'test1' },
82
+ { id: 1, name: 'test3' },
83
+ ],
84
+ '2': [{ id: 2, name: 'test2' }],
85
+ });
86
+ });
87
+ });
88
+
89
+ describe('SVGIcon', () => {
90
+ afterEach(cleanup);
91
+
92
+ it('should render SVGIcon correctly', () => {
93
+ const { container } = render(
94
+ <SVGIcon
95
+ name={{
96
+ attributes: {
97
+ xmlns: 'http://www.w3.org/2000/svg',
98
+ viewBox: '0 0 32 32',
99
+ },
100
+ content: '<path d="M2 9h28l-14 14L2 9z"></path>',
101
+ }}
102
+ className={'test'}
103
+ title={'test title'}
104
+ size="32px"
105
+ />,
106
+ );
107
+ expect(container.firstChild).toMatchSnapshot();
108
+ });
109
+
110
+ it('should call onClick when clicked', () => {
111
+ const onClick = jest.fn();
112
+ const { container } = render(
113
+ <SVGIcon
114
+ name={{
115
+ attributes: {
116
+ xmlns: 'http://www.w3.org/2000/svg',
117
+ viewBox: '0 0 32 32',
118
+ },
119
+ content: '<path d="M2 9h28l-14 14L2 9z"></path>',
120
+ }}
121
+ size="32px"
122
+ onClick={onClick}
123
+ />,
124
+ );
125
+ fireEvent.click(container.getElementsByClassName('icon')[0]);
126
+ expect(onClick).toHaveBeenCalled();
127
+ });
128
+ });
@@ -126,7 +126,6 @@ const LandingPage = (props) => {
126
126
  type: filterType,
127
127
  })),
128
128
  };
129
- // console.log('state', state);
130
129
  const facetCounts = await getFacetCounts(
131
130
  state,
132
131
  appConfig,
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { Label } from 'semantic-ui-react';
4
- import { DateTime, StringList } from '@eeacms/search';
5
- import { ResultContext } from '@eeacms/search';
4
+ import { DateTime, StringList, ResultContext } from '@eeacms/search';
6
5
  import { Link } from 'react-router-dom';
7
6
  import { UniversalCard } from '@eeacms/volto-listing-block';
8
7
 
@@ -10,11 +9,6 @@ const DatahubCardItem = (props) => {
10
9
  const { result } = props;
11
10
  const { topic, dataset_formats } = result._result || [];
12
11
 
13
- // let metaType = result.metaTypes || '';
14
- // if (metaType.length === 0) {
15
- // metaType = 'Others';
16
- // }
17
-
18
12
  const item = {
19
13
  title: (
20
14
  <>
@@ -32,7 +26,6 @@ const DatahubCardItem = (props) => {
32
26
  extra: (
33
27
  <div className="result-bottom">
34
28
  <div className="result-info">
35
- {/* <span className="result-info-title">Published: </span> */}
36
29
  <DateTime format="DATE_MED" value={result.issued} />
37
30
  </div>
38
31
  {topic ? (
@@ -60,81 +53,4 @@ const DatahubCardItem = (props) => {
60
53
  return <UniversalCard item={item} itemModel={itemModel} />;
61
54
  };
62
55
 
63
- // <div
64
- // className={cx('search-result', { hovered })}
65
- // onMouseEnter={() => setHovered(true)}
66
- // onMouseLeave={() => setHovered(false)}
67
- // >
68
- // <div className={classColLeft}>
69
- // <div className="details">
70
- // <h3>
71
- // <Link
72
- // to={{
73
- // pathname: `/en/datahub/datahubitem-view/${resultId}`,
74
- // state: {
75
- // fromPathname: window.location.pathname,
76
- // fromSearch: window.location.search,
77
- // },
78
- // }}
79
- // title={result.title}
80
- // >
81
- // {firstWords(result.title, 12)}
82
- // </Link>
83
- // {result.isNew && (
84
- // <Label className="new-item" horizontal>
85
- // New
86
- // </Label>
87
- // )}
88
- // {result.isExpired && (
89
- // <Label className="archived-item" horizontal>
90
- // Archived
91
- // </Label>
92
- // )}
93
- // </h3>
94
- // {props.children ? props.children : <ResultContext {...props} />}
95
-
96
- // <div className="result-bottom">
97
- // {topic ? (
98
- // <div className="result-info">
99
- // <span className="result-info-title">Topics: </span>
100
- // <StringList value={topic.raw} />
101
- // </div>
102
- // ) : null}
103
- // <div className="result-info">
104
- // <span className="result-info-title">Published: </span>
105
- // <DateTime format="DATE_MED" value={result.issued} />
106
- // </div>
107
- // <div className="result-info">
108
- // <span className="result-info-title">Available formats: </span>
109
- // [Icons]
110
- // </div>
111
- // </div>
112
- // </div>
113
- // {debugQuery && (
114
- // <div>
115
- // <div>Explanation:</div>
116
- // <pre>{JSON.stringify(result.explanation, undefined, 2)}</pre>
117
- // </div>
118
- // )}
119
- // </div>
120
- // {result.hasImage ? (
121
- // <div className="col-right">
122
- // <a
123
- // className={`centered fluid image img-thumbnail`}
124
- // href={result.href}
125
- // target="_blank"
126
- // rel="noreferrer"
127
- // >
128
- // <img
129
- // alt={result.title}
130
- // src={result.thumbUrl}
131
- // onError={(e) => {
132
- // e.target.style.display = 'none';
133
- // }}
134
- // />
135
- // </a>
136
- // </div>
137
- // ) : null}
138
- // </div>
139
-
140
56
  export default DatahubCardItem;
@@ -4,8 +4,8 @@ import {
4
4
  histogramFacet,
5
5
  makeRange,
6
6
  booleanFacet,
7
+ dateRangeFacet,
7
8
  } from '@eeacms/search';
8
- import { dateRangeFacet } from '@eeacms/search';
9
9
 
10
10
  export function getTodayWithTime() {
11
11
  const d = new Date();
@@ -25,7 +25,6 @@ const getClientProxyAddress = () => {
25
25
  };
26
26
 
27
27
  export default function install(config) {
28
- // console.log(process.env.RAZZLE_ENV_CONFIG);
29
28
  const envConfig = process.env.RAZZLE_ENV_CONFIG
30
29
  ? JSON.parse(process.env.RAZZLE_ENV_CONFIG)
31
30
  : datahubConfig;
@@ -2,6 +2,8 @@ import { registry } from '@eeacms/search';
2
2
  import express from 'express';
3
3
  import buildRequest from '@eeacms/search/lib/search/query';
4
4
  import superagent from 'superagent';
5
+ import { Feed } from 'feed';
6
+
5
7
  // import zlib from 'zlib';
6
8
 
7
9
  const getUrlES = (appName) => {
@@ -28,7 +30,7 @@ function handleSearchRequest(body, params) {
28
30
  if (resp && resp.body) {
29
31
  return resolve(resp.body);
30
32
  }
31
- return reject({ error: 'Error' });
33
+ return reject(err);
32
34
  });
33
35
  });
34
36
  }
@@ -110,12 +112,65 @@ function datasetRedirect(req, res, next) {
110
112
  });
111
113
  }
112
114
 
115
+ function generateRSS(appConfig) {
116
+ return new Promise((resolve, reject) => {
117
+ const body = buildRequest({ filters: [] }, appConfig);
118
+ delete body['source'];
119
+ delete body['params'];
120
+ delete body['runtime_mappings'];
121
+ delete body['index'];
122
+ body._source = {
123
+ include: ['about', 'last_modified', 'title', 'description'],
124
+ };
125
+ body.size = 10000;
126
+ const urlES = getUrlES('datahub');
127
+
128
+ handleSearchRequest(body, { urlES })
129
+ .then((body) => {
130
+ const items = body?.hits?.hits || [];
131
+
132
+ const feed = new Feed({
133
+ title: 'EEA Datahub',
134
+ description: 'Latest changes in EEA Datahub',
135
+ id: 'https://eea.europa.eu/en/datahub',
136
+ generator: 'EEA Website',
137
+ link: 'https://eea.europa.eu/en/datahub',
138
+ });
139
+
140
+ items.forEach((item) => {
141
+ feed.addItem({
142
+ id: toPublicURL(item._id),
143
+ title: item._source.title,
144
+ description: item._source.description,
145
+ date: new Date(item._source.last_modified),
146
+ });
147
+ });
148
+
149
+ const result = feed.rss2();
150
+
151
+ resolve(result);
152
+ })
153
+ .catch(reject);
154
+ });
155
+ }
156
+
157
+ function rssMiddleware(req, res, next) {
158
+ const appConfig = registry.searchui['datahub'];
159
+
160
+ generateRSS(appConfig)
161
+ .then((body) => res.send(body))
162
+ .catch((body) => {
163
+ res.send({ error: body });
164
+ });
165
+ }
166
+
113
167
  export default function makeMiddlewares(config) {
114
168
  const middleware = express.Router();
115
169
  // middleware.use(express.json({ limit: config.settings.maxResponseSize }));
116
170
  middleware.use(express.urlencoded({ extended: true }));
117
171
 
118
172
  middleware.all('**/datahub/sitemap-data.xml', sitemap);
173
+ middleware.all('**/datahub/rss.xml', rssMiddleware);
119
174
  middleware.all('**/datahub/dataset-redirect/:id', datasetRedirect);
120
175
  middleware.id = 'datahub-middlewares';
121
176
 
package/src/index.js CHANGED
@@ -36,6 +36,14 @@ const applyConfig = (config) => {
36
36
  datahub.resultItemModel.factory = 'DatahubResultModel';
37
37
 
38
38
  config.settings.nonContentRoutes.push(/datahubitem-view\/(.*)/); // \/(.*)\/
39
+ config.settings.nonContentRoutes.push(/datahub\/rss\.xml/);
40
+ config.settings.externalRoutes.push({
41
+ match: {
42
+ path: /\/.+\/datahub\/rss\.xml/,
43
+ strict: true,
44
+ exact: true,
45
+ },
46
+ });
39
47
  config.addonRoutes = [
40
48
  {
41
49
  path: '*/datahubitem-view/:id',
@@ -1 +0,0 @@
1
- module.exports = require('@plone/volto/babel');