@eeacms/volto-datahub 1.0.26 → 1.0.28

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.
@@ -0,0 +1,2 @@
1
+ [ -n "$CI" ] && exit 0
2
+ yarn lint-staged
package/CHANGELOG.md CHANGED
@@ -4,6 +4,30 @@ 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.28](https://github.com/eea/volto-datahub/compare/1.0.27...1.0.28) - 8 September 2023
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - Add tests [Tiberiu Ichim - [`6a8bd4d`](https://github.com/eea/volto-datahub/commit/6a8bd4d92b0fc68ef1653f412a13a38b22c2401b)]
12
+ - Avoid code duplicates [Tiberiu Ichim - [`3c1adb2`](https://github.com/eea/volto-datahub/commit/3c1adb2f2b38c2fbc3527dc7db89fe3c6e62caef)]
13
+ - Avoid code duplicates [Tiberiu Ichim - [`77d251c`](https://github.com/eea/volto-datahub/commit/77d251c1ba79d0eb8c2b1adedeedc129438cffcd)]
14
+ - Code cleanup [Tiberiu Ichim - [`f27e7b4`](https://github.com/eea/volto-datahub/commit/f27e7b4447d03898cf24e9ab6b24d543954c6b17)]
15
+ - Dont emit broken dates [Tiberiu Ichim - [`a2e9fb4`](https://github.com/eea/volto-datahub/commit/a2e9fb477b5fe3ae0bc3bffc275d3871ba52a4dd)]
16
+ - Directly link to accordion [Tiberiu Ichim - [`2e637bc`](https://github.com/eea/volto-datahub/commit/2e637bc39ec88eaaf3c88c93d43b3c5b2a950f1e)]
17
+ - Improve RSS feed for dataseries [Tiberiu Ichim - [`1a7cb1b`](https://github.com/eea/volto-datahub/commit/1a7cb1bfdce32d837f1d342744e1f94d423813a0)]
18
+ - Fix content type for rss feed [Tiberiu Ichim - [`65b73a7`](https://github.com/eea/volto-datahub/commit/65b73a79d73e626f652716305e80d9a2b017c85c)]
19
+ - test: EN locales, pre-commit fix, feature PRs checks Refs #257193 [valentinab25 - [`ead1c04`](https://github.com/eea/volto-datahub/commit/ead1c042d1358b385c19ec66ec84d7c736574b1d)]
20
+ - Added 'DOI' links to datahub [Zoltan Szabo - [`b33a657`](https://github.com/eea/volto-datahub/commit/b33a657096eaec4caa641379e69e941a3b2c1583)]
21
+ - test: Fix eslint and yarn i18n [Alin Voinea - [`39a4a69`](https://github.com/eea/volto-datahub/commit/39a4a695733514890075886753b9d7b91d853646)]
22
+ - i18n: Add en [Alin Voinea - [`cdb303f`](https://github.com/eea/volto-datahub/commit/cdb303f2ac5e1f9eb22eda46bb58087c62af6ba5)]
23
+ ### [1.0.27](https://github.com/eea/volto-datahub/compare/1.0.26...1.0.27) - 25 August 2023
24
+
25
+ #### :hammer_and_wrench: Others
26
+
27
+ - Add tests to increase coverage [kreafox - [`b112058`](https://github.com/eea/volto-datahub/commit/b112058ce16c34397e9cf59d5d96bcbc34dc70cf)]
28
+ - Formatting [kreafox - [`b0b0077`](https://github.com/eea/volto-datahub/commit/b0b007794b113a09e937ca7333b298555a947e68)]
29
+ - Accessibility improvements [kreafox - [`193ce3f`](https://github.com/eea/volto-datahub/commit/193ce3f99931ded1118065f46c5ef672ee49cbb2)]
30
+ - Accessibility improvements [kreafox - [`4301b19`](https://github.com/eea/volto-datahub/commit/4301b1946642a1c83f4f5194a73afab6f5d150fc)]
7
31
  ### [1.0.26](https://github.com/eea/volto-datahub/compare/1.0.25...1.0.26) - 23 August 2023
8
32
 
9
33
  #### :hammer_and_wrench: Others
@@ -42,6 +66,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
42
66
 
43
67
  #### :house: Internal changes
44
68
 
69
+ - chore: [JENKINS] Deprecate circularity website [valentinab25 - [`e5933ce`](https://github.com/eea/volto-datahub/commit/e5933ce8879d98aabe0bab56980dbd50ce856a36)]
45
70
 
46
71
  #### :hammer_and_wrench: Others
47
72
 
@@ -96,6 +121,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
96
121
  - added utils.js [Zoltan Szabo - [`fdb33c3`](https://github.com/eea/volto-datahub/commit/fdb33c37e1af2fe071dbe8f4f5dcd2b82932edc8)]
97
122
  - Show 'Obsolete' info in the metadata section in the banner [Zoltan Szabo - [`fddfd2a`](https://github.com/eea/volto-datahub/commit/fddfd2aea63d1a1d1567c163ab29dd7119781117)]
98
123
  - Show 'More information' section only if it's not empty [Zoltan Szabo - [`612f035`](https://github.com/eea/volto-datahub/commit/612f03509c6adf143631ae6dee5ca2bd48a501c3)]
124
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`b9100f6`](https://github.com/eea/volto-datahub/commit/b9100f6b2b2e9e9a26b9c11708c8fda94137cecc)]
99
125
  ### [1.0.15](https://github.com/eea/volto-datahub/compare/1.0.14...1.0.15) - 1 March 2023
100
126
 
101
127
  ### [1.0.14](https://github.com/eea/volto-datahub/compare/1.0.13...1.0.14) - 1 March 2023
@@ -188,9 +214,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
188
214
  #### :hammer_and_wrench: Others
189
215
 
190
216
  - Fix eslintrc: add @eeacms/search [kreafox - [`465816f`](https://github.com/eea/volto-datahub/commit/465816feb8f58095ab4b5b3168cd29ebede3a10c)]
217
+ - Use latest Volto before yarn 3 [Tiberiu Ichim - [`69f5859`](https://github.com/eea/volto-datahub/commit/69f585980fd9a38ff99d0c7875704671857720f7)]
191
218
  - Reorder sections on landing page [kreafox - [`46fac8d`](https://github.com/eea/volto-datahub/commit/46fac8d821cf93fe1b2c380380719de130c3f1cb)]
192
219
  - Fix project eslintrc [kreafox - [`5baa150`](https://github.com/eea/volto-datahub/commit/5baa1505ec38ed313269f5608c186c6a6a8bbfc4)]
193
220
  - Open dataset links in new tab [kreafox - [`bbed914`](https://github.com/eea/volto-datahub/commit/bbed914dc2edf6c749d1d73d93a423bc642e680c)]
221
+ - Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`380a2a9`](https://github.com/eea/volto-datahub/commit/380a2a9625c6f799df7a7c343fad3f3b3d959f96)]
194
222
  ## [1.0.0](https://github.com/eea/volto-datahub/compare/0.1.12...1.0.0) - 28 October 2022
195
223
 
196
224
  #### :nail_care: Enhancements
@@ -215,6 +243,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
215
243
  #### :hammer_and_wrench: Others
216
244
 
217
245
  - fixed query for related items [Zoltan Szabo - [`b66faee`](https://github.com/eea/volto-datahub/commit/b66faee1f8a1922cd22b3a36eccc9c7b92e377d4)]
246
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`158fe1a`](https://github.com/eea/volto-datahub/commit/158fe1a0b1767452e2e51a3e2ef97169589a50e8)]
218
247
  ### [0.1.10](https://github.com/eea/volto-datahub/compare/0.1.9...0.1.10) - 21 September 2022
219
248
 
220
249
  #### :hammer_and_wrench: Others
@@ -303,6 +332,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
303
332
  #### :hammer_and_wrench: Others
304
333
 
305
334
  - Hide questions & fix landing page [kreafox - [`a1ef303`](https://github.com/eea/volto-datahub/commit/a1ef3033df0e84f3a72dd0f984c8717dff2a771c)]
335
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`910688e`](https://github.com/eea/volto-datahub/commit/910688e3ddf2f8cda4f941595ae9a6ee0ec0ea3b)]
306
336
  ### [0.1.1](https://github.com/eea/volto-datahub/compare/0.1.0...0.1.1) - 10 June 2022
307
337
 
308
338
  ### [0.1.0](https://github.com/eea/volto-datahub/compare/0.0.1...0.1.0) - 9 June 2022
package/cypress.config.js CHANGED
@@ -2,12 +2,12 @@ const { defineConfig } = require('cypress');
2
2
 
3
3
  module.exports = defineConfig({
4
4
  viewportWidth: 1280,
5
- defaultCommandTimeout: 8888,
5
+ defaultCommandTimeout: 5000,
6
6
  chromeWebSecurity: false,
7
7
  reporter: 'junit',
8
8
  video: true,
9
9
  retries: {
10
- runMode: 8,
10
+ runMode: 1,
11
11
  openMode: 0,
12
12
  },
13
13
  reporterOptions: {
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-datahub",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "@eeacms/volto-datahub: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -17,15 +17,17 @@
17
17
  "url": "git@github.com:eea/volto-datahub.git"
18
18
  },
19
19
  "dependencies": {
20
+ "@eeacms/volto-accordion-block": "*",
20
21
  "@eeacms/volto-globalsearch": "*",
21
22
  "@eeacms/volto-listing-block": "*",
22
- "@eeacms/volto-accordion-block": "*",
23
23
  "feed": "4.2.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@cypress/code-coverage": "^3.10.0",
27
27
  "@plone/scripts": "*",
28
28
  "babel-plugin-transform-class-properties": "^6.24.1",
29
+ "husky": "*",
30
+ "lint-staged": "*",
29
31
  "md5": "^2.3.0"
30
32
  },
31
33
  "addons": [
@@ -33,6 +35,27 @@
33
35
  "@eeacms/volto-listing-block",
34
36
  "@eeacms/volto-accordion-block"
35
37
  ],
38
+ "lint-staged": {
39
+ "src/**/*.{js,jsx,ts,tsx,json}": [
40
+ "make lint-fix",
41
+ "make prettier-fix"
42
+ ],
43
+ "src/**/*.{jsx}": [
44
+ "make i18n"
45
+ ],
46
+ "theme/**/*.{css,less}": [
47
+ "make stylelint-fix"
48
+ ],
49
+ "src/**/*.{css,less}": [
50
+ "make stylelint-fix"
51
+ ],
52
+ "theme/**/*.overrides": [
53
+ "make stylelint-fix"
54
+ ],
55
+ "src/**/*.overrides": [
56
+ "make stylelint-fix"
57
+ ]
58
+ },
36
59
  "scripts": {
37
60
  "release": "release-it",
38
61
  "release-major-beta": "release-it major --preRelease=beta",
@@ -50,6 +73,7 @@
50
73
  "lint:fix": "make lint-fix",
51
74
  "i18n": "make i18n",
52
75
  "cypress:run": "make cypress-run",
53
- "cypress:open": "make cypress-open"
76
+ "cypress:open": "make cypress-open",
77
+ "prepare": "husky install"
54
78
  }
55
79
  }
@@ -0,0 +1,42 @@
1
+ import { List } from 'semantic-ui-react';
2
+ import { SVGIcon } from '../utils.js';
3
+
4
+ import lockSVG from 'remixicon/icons/System/lock-line.svg';
5
+ import { isInternalURL } from '@eeacms/volto-datahub/utils';
6
+ import servicesSVG from '../icons/services.svg';
7
+
8
+ const ItemLink = ({ item }) => (
9
+ <List.Item key={item.id}>
10
+ <List.Content>
11
+ <div>
12
+ <SVGIcon name={servicesSVG} size="20px" />
13
+ <a
14
+ className="item-link"
15
+ href={item.url}
16
+ target="_blank"
17
+ rel="noreferrer"
18
+ >
19
+ {item.protocol} {item.name || item.description}
20
+ </a>
21
+ {isInternalURL(item.url) && <SVGIcon name={lockSVG} size="20px" />}
22
+ </div>
23
+ </List.Content>
24
+ </List.Item>
25
+ );
26
+
27
+ export default function DatasetEsri({ dataset }) {
28
+ return (
29
+ (dataset['ESRI:REST'] || dataset['OGC:WMS']) && (
30
+ <>
31
+ <h5>Services:</h5>
32
+ <List divided relaxed>
33
+ {[...(dataset['ESRI:REST'] || []), ...(dataset['OGC:WMS'] || [])].map(
34
+ (item, i) => (
35
+ <ItemLink item={item} key={item.id} />
36
+ ),
37
+ )}
38
+ </List>
39
+ </>
40
+ )
41
+ );
42
+ }
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+
4
+ import DatasetEsri from './DatasetEsri';
5
+
6
+ jest.mock('@eeacms/search', () => ({
7
+ runRequest: jest.fn(),
8
+ }));
9
+
10
+ const dataset = {
11
+ 'ESRI:REST': [
12
+ {
13
+ id: 1,
14
+ url: 'https://example.org/1',
15
+ protocol: 'https',
16
+ name: 'First',
17
+ description: 'Something here',
18
+ },
19
+ ],
20
+ };
21
+
22
+ describe('DatasetEsri', () => {
23
+ it('renders correctly', () => {
24
+ const tree = renderer.create(<DatasetEsri dataset={dataset} />).toJSON();
25
+ expect(tree).toMatchSnapshot();
26
+ });
27
+ });
@@ -0,0 +1,67 @@
1
+ import { Icon, List } from 'semantic-ui-react';
2
+ import { isInternalURL } from '@eeacms/volto-datahub/utils';
3
+ import { SVGIcon } from '../utils.js';
4
+
5
+ import lockSVG from 'remixicon/icons/System/lock-line.svg';
6
+
7
+ export default function DatasetHttpLinks({ dataset }) {
8
+ return (
9
+ (dataset['WWW:LINK-1.0-http--link'] || dataset['DOI']) && (
10
+ <>
11
+ <h5>Links:</h5>
12
+ <List divided relaxed>
13
+ {(dataset['WWW:LINK-1.0-http--link'] || []).map((item, i) => {
14
+ return (
15
+ <List.Item key={i}>
16
+ <List.Content>
17
+ <div className="dataset-item">
18
+ <Icon className="linkify" />
19
+ <a
20
+ href={item.url}
21
+ className="item-link"
22
+ target="_blank"
23
+ rel="noreferrer"
24
+ >
25
+ <span>{item.name || item.url}</span>
26
+ </a>
27
+ {isInternalURL(item.url) && (
28
+ <SVGIcon name={lockSVG} size="20px" />
29
+ )}
30
+ </div>
31
+ </List.Content>
32
+ {item.description && (
33
+ <span className="item-description">{item.description}</span>
34
+ )}
35
+ </List.Item>
36
+ );
37
+ })}
38
+ {(dataset['DOI'] || []).map((item, i) => {
39
+ return (
40
+ <List.Item key={i}>
41
+ <List.Content>
42
+ <div className="dataset-item">
43
+ <Icon className="info circle" />
44
+ <a
45
+ href={item.url}
46
+ className="item-link"
47
+ target="_blank"
48
+ rel="noreferrer"
49
+ >
50
+ <span>{item.name || item.url}</span>
51
+ </a>
52
+ {isInternalURL(item.url) && (
53
+ <SVGIcon name={lockSVG} size="20px" />
54
+ )}
55
+ </div>
56
+ </List.Content>
57
+ {item.description && (
58
+ <span className="item-description">{item.description}</span>
59
+ )}
60
+ </List.Item>
61
+ );
62
+ })}
63
+ </List>
64
+ </>
65
+ )
66
+ );
67
+ }
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+
4
+ import DatasetHttpLinks from './DatasetHttpLinks';
5
+
6
+ jest.mock('@eeacms/search', () => ({
7
+ runRequest: jest.fn(),
8
+ }));
9
+
10
+ const dataset = {
11
+ 'WWW:LINK-1.0-http--link': [
12
+ {
13
+ id: 1,
14
+ url: 'https://example.org/1',
15
+ protocol: 'https',
16
+ name: 'First',
17
+ description: 'Something here',
18
+ },
19
+ ],
20
+ DOI: [
21
+ {
22
+ id: 1,
23
+ url: 'https://example.org/1',
24
+ protocol: 'https',
25
+ name: 'First',
26
+ description: 'Something here',
27
+ },
28
+ ],
29
+ };
30
+
31
+ describe('DatasetHttpLinks', () => {
32
+ it('renders correctly', () => {
33
+ const tree = renderer
34
+ .create(<DatasetHttpLinks dataset={dataset} />)
35
+ .toJSON();
36
+ expect(tree).toMatchSnapshot();
37
+ });
38
+ });
@@ -1,9 +1,11 @@
1
1
  import React from 'react';
2
- import { Icon, List } from 'semantic-ui-react';
3
- import { isInternalURL, groupBy, SVGIcon } from '../utils.js';
2
+ import { List } from 'semantic-ui-react';
4
3
 
5
- import servicesSVG from '../icons/services.svg';
6
- import lockSVG from 'remixicon/icons/System/lock-line.svg';
4
+ import { groupBy } from '@eeacms/volto-datahub/utils';
5
+ import DatasetUrls from './DatasetUrls';
6
+ import DatasetLinks from './DatasetLinks';
7
+ import DatasetEsri from './DatasetEsri';
8
+ import DatasetHttpLinks from './DatasetHttpLinks';
7
9
 
8
10
  const DatasetItemDownloadList = (props) => {
9
11
  const { link } = props;
@@ -18,156 +20,14 @@ const DatasetItemDownloadList = (props) => {
18
20
  <>
19
21
  <h5>Download:</h5>
20
22
  <List divided relaxed>
21
- {(dataset['WWW:URL'] || []).map((item, i) => {
22
- return (
23
- <List.Item key={i}>
24
- <List.Content>
25
- <div className="dataset-item">
26
- <Icon className="download" />
27
- <a
28
- href={item.url}
29
- className="item-link"
30
- target="_blank"
31
- rel="noreferrer"
32
- >
33
- <span>{item.name}</span>
34
- </a>
35
- {isInternalURL(item.url) && (
36
- <SVGIcon name={lockSVG} size="20px" />
37
- )}
38
- </div>
39
- </List.Content>
40
- {item.description && (
41
- <span className="item-description" title={item.description}>
42
- {item.description}
43
- </span>
44
- )}
45
- </List.Item>
46
- );
47
- })}
48
-
49
- {(dataset['WWW:LINK'] || []).map((item, i) => {
50
- return (
51
- <List.Item key={i}>
52
- <List.Content>
53
- <div className="dataset-item">
54
- <Icon className="download" />
55
- {item.name ? (
56
- <a
57
- href={item.url}
58
- className="item-link"
59
- target="_blank"
60
- rel="noreferrer"
61
- >
62
- {item.name}
63
- </a>
64
- ) : (
65
- <a
66
- href={item.url}
67
- className="item-link"
68
- target="_blank"
69
- rel="noreferrer"
70
- >
71
- Download link
72
- </a>
73
- )}
74
- {isInternalURL(item.url) && (
75
- <SVGIcon name={lockSVG} size="20px" />
76
- )}
77
- </div>
78
- </List.Content>
79
- </List.Item>
80
- );
81
- })}
23
+ <DatasetUrls dataset={dataset} />
24
+ <DatasetLinks dataset={dataset} />
82
25
  </List>
83
26
  </>
84
27
  )}
85
28
 
86
- {(dataset['ESRI:REST'] || dataset['OGC:WMS']) && (
87
- <>
88
- <h5>Services:</h5>
89
- <List divided relaxed>
90
- {(dataset['ESRI:REST'] || []).map((item, i) => {
91
- return (
92
- <List.Item key={i}>
93
- <List.Content>
94
- <div>
95
- <SVGIcon name={servicesSVG} size="20px" />
96
- <a
97
- className="item-link"
98
- href={item.url}
99
- target="_blank"
100
- rel="noreferrer"
101
- >
102
- {item.protocol} {item.name || item.description}
103
- </a>
104
- {isInternalURL(item.url) && (
105
- <SVGIcon name={lockSVG} size="20px" />
106
- )}
107
- </div>
108
- </List.Content>
109
- </List.Item>
110
- );
111
- })}
112
-
113
- {(dataset['OGC:WMS'] || []).map((item, i) => {
114
- return (
115
- <List.Item key={i}>
116
- <List.Content>
117
- <div>
118
- <SVGIcon name={servicesSVG} size="20px" />
119
- <a
120
- className="item-link"
121
- href={item.url}
122
- target="_blank"
123
- rel="noreferrer"
124
- >
125
- {item.protocol} {item.name || item.description}
126
- </a>
127
- {isInternalURL(item.url) && (
128
- <SVGIcon name={lockSVG} size="20px" />
129
- )}
130
- </div>
131
- </List.Content>
132
- </List.Item>
133
- );
134
- })}
135
- </List>
136
- </>
137
- )}
138
-
139
- {dataset['WWW:LINK-1.0-http--link'] && (
140
- <>
141
- <h5>Links:</h5>
142
- <List divided relaxed>
143
- {(dataset['WWW:LINK-1.0-http--link'] || []).map((item, i) => {
144
- return (
145
- <List.Item key={i}>
146
- <List.Content>
147
- <div className="dataset-item">
148
- <Icon className="linkify" />
149
- <a
150
- href={item.url}
151
- className="item-link"
152
- target="_blank"
153
- rel="noreferrer"
154
- >
155
- <span>{item.name || item.url}</span>
156
- </a>
157
- {isInternalURL(item.url) && (
158
- <SVGIcon name={lockSVG} size="20px" />
159
- )}
160
- </div>
161
- </List.Content>
162
- {item.description && (
163
- <span className="item-description">{item.description}</span>
164
- )}
165
- </List.Item>
166
- );
167
- })}
168
- </List>
169
- </>
170
- )}
29
+ <DatasetEsri dataset={dataset} />
30
+ <DatasetHttpLinks dataset={dataset} />
171
31
  </div>
172
32
  );
173
33
  };
@@ -6,8 +6,9 @@ import { useLocation, useHistory } from 'react-router-dom';
6
6
  import { DateTime } from '@eeacms/search';
7
7
  import { AccordionFilter } from '@eeacms/volto-accordion-block/components';
8
8
 
9
- import { isInternal, SVGIcon, isObsolete } from '../utils.js';
9
+ import { SVGIcon } from '../utils.js';
10
10
  import DatasetItemDownloadList from './DatasetItemDownloadList';
11
+ import { isInternal, isObsolete } from '@eeacms/volto-datahub/utils';
11
12
 
12
13
  import lockSVG from 'remixicon/icons/System/lock-line.svg';
13
14
 
@@ -147,13 +148,16 @@ const DatasetItemsList = (props) => {
147
148
  <>
148
149
  <Accordion id={id} key={index}>
149
150
  <Accordion.Title
151
+ role="button"
150
152
  tabIndex={0}
151
153
  active={active}
154
+ aria-expanded={active}
152
155
  index={index}
153
156
  onClick={(e) => handleClick(e, { index, id, item })}
154
157
  onKeyDown={(e) => {
155
- if (e.key === 'Enter') {
156
- handleClick(e, { index });
158
+ if (e.keyCode === 13 || e.keyCode === 32) {
159
+ e.preventDefault();
160
+ handleClick(e, { index, id, item });
157
161
  }
158
162
  }}
159
163
  >
@@ -206,7 +210,11 @@ const DatasetItemsList = (props) => {
206
210
  )}
207
211
  </span>
208
212
  </span>
209
- <Icon className="ri-arrow-down-s-line" />
213
+ {active ? (
214
+ <Icon className="ri-arrow-up-s-line" />
215
+ ) : (
216
+ <Icon className="ri-arrow-down-s-line" />
217
+ )}
210
218
  </Accordion.Title>
211
219
  <Accordion.Content active={active}>
212
220
  <div className="dataset-content">
@@ -0,0 +1,39 @@
1
+ import { Icon, List } from 'semantic-ui-react';
2
+ import { SVGIcon } from '../utils.js';
3
+
4
+ import lockSVG from 'remixicon/icons/System/lock-line.svg';
5
+ import { isInternalURL } from '@eeacms/volto-datahub/utils';
6
+
7
+ export default function DatasetLinks({ dataset }) {
8
+ return (dataset['WWW:LINK'] || []).map((item, i) => {
9
+ return (
10
+ <List.Item key={i}>
11
+ <List.Content>
12
+ <div className="dataset-item">
13
+ <Icon className="download" />
14
+ {item.name ? (
15
+ <a
16
+ href={item.url}
17
+ className="item-link"
18
+ target="_blank"
19
+ rel="noreferrer"
20
+ >
21
+ {item.name}
22
+ </a>
23
+ ) : (
24
+ <a
25
+ href={item.url}
26
+ className="item-link"
27
+ target="_blank"
28
+ rel="noreferrer"
29
+ >
30
+ Download link
31
+ </a>
32
+ )}
33
+ {isInternalURL(item.url) && <SVGIcon name={lockSVG} size="20px" />}
34
+ </div>
35
+ </List.Content>
36
+ </List.Item>
37
+ );
38
+ });
39
+ }
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+
4
+ import DatasetLinks from './DatasetLinks';
5
+
6
+ jest.mock('@eeacms/search', () => ({
7
+ runRequest: jest.fn(),
8
+ }));
9
+
10
+ const dataset = {
11
+ 'WWW:LINK': [
12
+ {
13
+ id: 1,
14
+ url: 'https://example.org/1',
15
+ protocol: 'https',
16
+ name: 'First',
17
+ description: 'Something here',
18
+ },
19
+ ],
20
+ };
21
+
22
+ describe('DatasetEsri', () => {
23
+ it('renders correctly', () => {
24
+ const tree = renderer.create(<DatasetLinks dataset={dataset} />).toJSON();
25
+ expect(tree).toMatchSnapshot();
26
+ });
27
+ });
@@ -0,0 +1,33 @@
1
+ import { Icon, List } from 'semantic-ui-react';
2
+ import { SVGIcon } from '../utils.js';
3
+
4
+ import lockSVG from 'remixicon/icons/System/lock-line.svg';
5
+ import { isInternalURL } from '@eeacms/volto-datahub/utils';
6
+
7
+ export default function DatasetUrls({ dataset }) {
8
+ return (dataset['WWW:URL'] || []).map((item, i) => {
9
+ return (
10
+ <List.Item key={i}>
11
+ <List.Content>
12
+ <div className="dataset-item">
13
+ <Icon className="download" />
14
+ <a
15
+ href={item.url}
16
+ className="item-link"
17
+ target="_blank"
18
+ rel="noreferrer"
19
+ >
20
+ <span>{item.name}</span>
21
+ </a>
22
+ {isInternalURL(item.url) && <SVGIcon name={lockSVG} size="20px" />}
23
+ </div>
24
+ </List.Content>
25
+ {item.description && (
26
+ <span className="item-description" title={item.description}>
27
+ {item.description}
28
+ </span>
29
+ )}
30
+ </List.Item>
31
+ );
32
+ });
33
+ }
@@ -32,12 +32,21 @@ const DatasetsTab = (props) => {
32
32
 
33
33
  const panes = (items || []).map((item, i) => ({
34
34
  menuItem: (
35
- <Menu.Item key={i} tabIndex={0}>
35
+ <Menu.Item
36
+ key={i}
37
+ tabIndex={0}
38
+ onKeyDown={(e) => {
39
+ if (e.keyCode === 13 || e.keyCode === 32) {
40
+ e.preventDefault();
41
+ setActiveTabIndex(i);
42
+ }
43
+ }}
44
+ >
36
45
  {item.date ? <span>{item.date}</span> : 'No date'}
37
46
  </Menu.Item>
38
47
  ),
39
48
  render: () => (
40
- <Tab.Pane>
49
+ <Tab.Pane tabIndex={0}>
41
50
  <DatasetItemsList
42
51
  item={item}
43
52
  appConfig={appConfig}
@@ -1,65 +1,14 @@
1
1
  import React from 'react';
2
- import { isObsolete, isInternal, groupBy } from '../utils.js';
3
2
  import DatasetsTab from './DatasetsTab';
3
+ import { parseDatasets } from '@eeacms/volto-datahub/utils';
4
4
 
5
5
  const DatasetsView = (props) => {
6
6
  const { item, appConfig } = props;
7
7
  const { children } = item?.raw_value?.raw || {};
8
-
9
- const all_datasets = children.map((v, e) => {
10
- let date;
11
- if (v.resourceTemporalExtentDetails) {
12
- const tc = v.resourceTemporalExtentDetails[0];
13
- const { start, end } = tc || {};
14
- const tc_start = start?.date
15
- ? new Date(Date.parse(start.date)).getFullYear()
16
- : '';
17
- const tc_end = end?.date
18
- ? new Date(Date.parse(end.date)).getFullYear()
19
- : '';
20
- if (tc_start === tc_end) {
21
- date = tc_start;
22
- } else {
23
- date = tc_start + '-' + tc_end;
24
- }
25
- } else {
26
- date = '';
27
- }
28
-
29
- return Object.assign({ temporalDateRange: date, ...v }, e);
30
- });
31
-
32
- const datasets = all_datasets.filter((v) => {
33
- return !(isObsolete(v.cl_status) || isInternal(v));
34
- });
35
-
36
- const archivedOrRestrictedDatasets = all_datasets.filter((v) => {
37
- return isObsolete(v.cl_status) || isInternal(v);
38
- });
39
-
40
- const groupDatasets = (items) => {
41
- const datasetsByCoverage = groupBy(items, 'temporalDateRange');
42
-
43
- const sortedDatasets = Object.keys(datasetsByCoverage).sort(function (
44
- a,
45
- b,
46
- ) {
47
- a = Math.max(...a.split('-'));
48
- b = Math.max(...b.split('-'));
49
- return b - a;
50
- });
51
-
52
- const groupedDatasets = sortedDatasets.map((v, i) => {
53
- return { id: i, date: v, children: datasetsByCoverage[v] };
54
- });
55
-
56
- return groupedDatasets;
57
- };
58
-
59
- const groupedByTemporalCoverage = groupDatasets(datasets);
60
- const groupedByArchivedOrRestricted = groupDatasets(
61
- archivedOrRestrictedDatasets,
62
- );
8
+ const {
9
+ groupedByTemporalCoverage,
10
+ groupedByArchivedOrRestricted,
11
+ } = parseDatasets(children);
63
12
 
64
13
  return (
65
14
  <>
@@ -8,6 +8,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';
11
+ import { defineMessages, useIntl } from 'react-intl';
11
12
  import {
12
13
  MoreLikeThis,
13
14
  MetadataSection,
@@ -16,7 +17,8 @@ import {
16
17
  import { fetchResult } from '@eeacms/search/lib/hocs/useResult';
17
18
  import { setDatahubResult } from '@eeacms/volto-datahub/store';
18
19
 
19
- import { isObsolete } from './utils.js';
20
+ import { viewRouteId } from '@eeacms/volto-datahub/constants';
21
+ import { isObsolete } from '@eeacms/volto-datahub/utils';
20
22
 
21
23
  const appName = 'datahub';
22
24
  const WORD_COUNT = 60;
@@ -46,6 +48,13 @@ function IsomorphicPortal({ children }) {
46
48
  );
47
49
  }
48
50
 
51
+ const messages = defineMessages({
52
+ rssFeed: {
53
+ id: 'rssFeed',
54
+ defaultMessage: 'RSS Feed',
55
+ },
56
+ });
57
+
49
58
  function ItemView(props) {
50
59
  const { docid, staticContext } = props;
51
60
  const dispatch = useDispatch();
@@ -93,6 +102,7 @@ function ItemView(props) {
93
102
  WORD_COUNT,
94
103
  );
95
104
  const [isReadMore, setIsReadMore] = React.useState(false);
105
+ const currentUrl = `/en/datahub/${viewRouteId}/${docid}`;
96
106
 
97
107
  React.useEffect(() => {
98
108
  const handler = async () => {
@@ -107,7 +117,7 @@ function ItemView(props) {
107
117
  },
108
118
  {
109
119
  title: rawTitle,
110
- '@id': `/en/datahub/view/${docid}`,
120
+ '@id': currentUrl,
111
121
  },
112
122
  ],
113
123
  },
@@ -118,7 +128,15 @@ function ItemView(props) {
118
128
  };
119
129
 
120
130
  handler();
121
- }, [item, dispatch, docid, rawTitle]);
131
+ }, [item, dispatch, docid, rawTitle, currentUrl]);
132
+
133
+ const intl = useIntl();
134
+ const rssLinks = [
135
+ {
136
+ title: 'RSS',
137
+ href: `${currentUrl}/datahub_rss.xml`,
138
+ },
139
+ ];
122
140
 
123
141
  return item && item._meta.found ? (
124
142
  <div className="dataset-view">
@@ -126,7 +144,35 @@ function ItemView(props) {
126
144
  <IsomorphicPortal>
127
145
  <div className="dataset">
128
146
  <Banner>
129
- <Banner.Content>
147
+ <Banner.Content
148
+ actions={rssLinks?.map((rssLink, index) => (
149
+ <>
150
+ <Helmet
151
+ link={[
152
+ {
153
+ rel: 'alternate',
154
+ title:
155
+ rssLink.title ?? intl.formatMessage(messages.rssFeed),
156
+ href: rssLink.href,
157
+ type:
158
+ rssLink.feedType === 'atom'
159
+ ? 'application/atom+xml'
160
+ : 'application/rss+xml',
161
+ },
162
+ ]}
163
+ />
164
+ <Banner.Action
165
+ icon="ri-rss-fill"
166
+ title={
167
+ rssLink.title ?? intl.formatMessage(messages.rssFeed)
168
+ }
169
+ className="rssfeed"
170
+ href={rssLink.href}
171
+ target="_blank"
172
+ />
173
+ </>
174
+ ))}
175
+ >
130
176
  <Banner.Subtitle>
131
177
  <Link to={appConfig.landingPageURL}>
132
178
  <Icon className="arrow left" />
@@ -81,7 +81,10 @@ const MetadataSection = (props) => {
81
81
  <a
82
82
  target="_blank"
83
83
  rel="noreferrer"
84
- href={`${appConfig.indexBaseUrl}/catalogue/datahub/api/records/${docid}/formatters/xsl-view?output=pdf&language=eng&approved=true`}
84
+ href={
85
+ `${appConfig.indexBaseUrl}/catalogue/datahub/api/records/` +
86
+ `${docid}/formatters/xsl-view?output=pdf&language=eng&approved=true`
87
+ }
85
88
  >
86
89
  Metadata Factsheet
87
90
  </a>
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+
4
+ import MoreLikeThis from './MoreLikeThis';
5
+
6
+ jest.mock('@eeacms/search', () => ({
7
+ runRequest: jest.fn(),
8
+ }));
9
+
10
+ describe('MoreLikeThis', () => {
11
+ it('renders correctly', () => {
12
+ const tree = renderer.create(<MoreLikeThis appConfig={{}} />).toJSON();
13
+ expect(tree).toMatchSnapshot();
14
+ });
15
+ });
@@ -1,3 +1,3 @@
1
- export DatasetsView from './Datasets/DatasetsView';
2
- export MetadataSection from './MetadataSection';
3
- export MoreLikeThis from './MoreLikeThis';
1
+ export { default as DatasetsView } from './Datasets/DatasetsView';
2
+ export { default as MetadataSection } from './MetadataSection';
3
+ export { default as MoreLikeThis } from './MoreLikeThis';
@@ -1,53 +1,3 @@
1
- const OBSOLETE_KEYS = ['obsolete', 'superseded'];
2
-
3
- export const isObsolete = (status) => {
4
- let obsolete = false;
5
- if (status) {
6
- if (Array.isArray(status)) {
7
- if (
8
- status.filter((stat) => OBSOLETE_KEYS.includes(stat?.key)).length > 0
9
- ) {
10
- obsolete = true;
11
- }
12
- } else {
13
- if (OBSOLETE_KEYS.includes(status?.key)) {
14
- obsolete = true;
15
- }
16
- }
17
- }
18
- return obsolete;
19
- };
20
-
21
- export const isInternalURL = (url) => {
22
- let internal = false;
23
- url.split('/').forEach((part) => {
24
- if (part.split('_')[6] === 'i') {
25
- internal = true;
26
- }
27
- });
28
- return internal;
29
- };
30
-
31
- export const isInternal = (item) => {
32
- let internal = false;
33
- const links = item?.link || [];
34
- links.forEach((link) => {
35
- if (isInternalURL(link?.url)) {
36
- internal = true;
37
- }
38
- });
39
- return internal;
40
- };
41
-
42
- export const groupBy = (obj, key) => {
43
- return obj.reduce((rv, item) => {
44
- const group = rv[item[key]] || [];
45
- group.push(item);
46
- rv[item[key]] = group;
47
- return rv;
48
- }, {});
49
- };
50
-
51
1
  export const SVGIcon = ({ name, size, color, className, title, onClick }) => {
52
2
  return (
53
3
  <svg
@@ -1,11 +1,11 @@
1
1
  import { render, cleanup, fireEvent } from '@testing-library/react';
2
+ import { SVGIcon } from './utils';
2
3
  import {
3
4
  isObsolete,
4
5
  isInternalURL,
5
6
  isInternal,
6
7
  groupBy,
7
- SVGIcon,
8
- } from './utils';
8
+ } from '@eeacms/volto-datahub/utils';
9
9
 
10
10
  describe('isObsolete', () => {
11
11
  it('should return true if status array contains obsolete keys', () => {
@@ -0,0 +1,3 @@
1
+ export const viewRouteId = 'datahubitem-view';
2
+ export const rssRouteId = 'datahub_rss.xml';
3
+ export const redirectRouteId = 'dataset-redirect';
@@ -1,10 +1,16 @@
1
1
  import { registry } from '@eeacms/search';
2
2
  import express from 'express';
3
- import buildRequest from '@eeacms/search/lib/search/query';
4
3
  import superagent from 'superagent';
5
4
  import { Feed } from 'feed';
6
5
 
7
- // import zlib from 'zlib';
6
+ import buildRequest from '@eeacms/search/lib/search/query';
7
+ import { fetchResult } from '@eeacms/search/lib/hocs/useResult';
8
+
9
+ import {
10
+ rssRouteId,
11
+ viewRouteId,
12
+ redirectRouteId,
13
+ } from '@eeacms/volto-datahub/constants';
8
14
 
9
15
  const getUrlES = (appName) => {
10
16
  return (
@@ -35,11 +41,11 @@ function handleSearchRequest(body, params) {
35
41
  });
36
42
  }
37
43
 
38
- function toPublicURL(id) {
39
- return `https://www.eea.europa.eu/en/datahub/datahubitem-view/${id}`;
40
- }
41
-
42
44
  function generateSitemap(appConfig) {
45
+ const toPublicURL = (id) => {
46
+ return `https://eea.europa.eu/en/datahub/${viewRouteId}/${id}`;
47
+ };
48
+
43
49
  return new Promise((resolve, reject) => {
44
50
  const body = buildRequest({ filters: [] }, appConfig);
45
51
  delete body['source'];
@@ -60,10 +66,6 @@ function generateSitemap(appConfig) {
60
66
  '\n',
61
67
  )}\n</urlset>`;
62
68
 
63
- // zlib.gzip(Buffer.from(result, 'utf8'), (_err, buffer) => {
64
- // resolve(buffer);
65
- // });
66
-
67
69
  resolve(result);
68
70
  });
69
71
  });
@@ -112,7 +114,7 @@ function datasetRedirect(req, res, next) {
112
114
  });
113
115
  }
114
116
 
115
- function generateRSS(appConfig) {
117
+ function generateRSS({ appConfig, feedUrl, toPublicURL }) {
116
118
  return new Promise((resolve, reject) => {
117
119
  const body = buildRequest({ filters: [] }, appConfig);
118
120
  delete body['source'];
@@ -135,6 +137,9 @@ function generateRSS(appConfig) {
135
137
  id: 'https://eea.europa.eu/en/datahub',
136
138
  generator: 'EEA Website',
137
139
  link: 'https://eea.europa.eu/en/datahub',
140
+ feedLinks: {
141
+ rss: feedUrl,
142
+ },
138
143
  });
139
144
 
140
145
  items.forEach((item) => {
@@ -146,7 +151,7 @@ function generateRSS(appConfig) {
146
151
  });
147
152
  });
148
153
 
149
- const result = feed.rss2();
154
+ const result = feed.rss2(); // TODO: make this pluggable
150
155
 
151
156
  resolve(result);
152
157
  })
@@ -154,14 +159,61 @@ function generateRSS(appConfig) {
154
159
  });
155
160
  }
156
161
 
157
- function rssMiddleware(req, res, next) {
158
- const appConfig = registry.searchui['datahub'];
162
+ function generateItemRSS({ appConfig, feedUrl, toPublicURL, params }) {
163
+ return new Promise((resolve, reject) => {
164
+ const docid = params['id'];
159
165
 
160
- generateRSS(appConfig)
161
- .then((body) => res.send(body))
162
- .catch((body) => {
163
- res.send({ error: body });
164
- });
166
+ fetchResult(docid, appConfig, registry)
167
+ .then((body) => {
168
+ const result = body._result;
169
+ const url = toPublicURL(docid);
170
+ const title = result.title.raw;
171
+ const feed = new Feed({
172
+ title,
173
+ description: `Latest changes in ${title}`,
174
+ id: url,
175
+ generator: 'EEA Website',
176
+ link: url,
177
+ feedLinks: {
178
+ rss: feedUrl,
179
+ },
180
+ });
181
+ const items = result['raw_value']['raw']['children'];
182
+
183
+ items.forEach((item) => {
184
+ const date = item.publicationDateForResource?.[0];
185
+ feed.addItem({
186
+ id: `${docid}/${item.id}`,
187
+ title: item.resourceTitleObject.default,
188
+ link: `${url}?activeAccordion=${item.id}`,
189
+ ...(date ? { date: new Date(date) } : {}),
190
+ });
191
+ });
192
+
193
+ resolve(feed.rss2());
194
+ })
195
+ .catch(reject);
196
+ });
197
+ }
198
+
199
+ function make_rssMiddleware(config, generator) {
200
+ function rssMiddleware(req, res, next) {
201
+ const appConfig = registry.searchui['datahub'];
202
+ const feedUrl = `${config.settings.apiPath}${req.path}`;
203
+
204
+ const toPublicURL = (id) =>
205
+ `${config.settings.apiPath}/en/datahub/${viewRouteId}/${id}`;
206
+
207
+ generator({ appConfig, feedUrl, toPublicURL, params: req.params })
208
+ .then((body) => {
209
+ res.setHeader('content-type', 'application/rss+xml');
210
+ res.send(body);
211
+ })
212
+ .catch((body) => {
213
+ res.send({ error: body });
214
+ });
215
+ }
216
+ return rssMiddleware;
165
217
  }
166
218
 
167
219
  export default function makeMiddlewares(config) {
@@ -170,8 +222,15 @@ export default function makeMiddlewares(config) {
170
222
  middleware.use(express.urlencoded({ extended: true }));
171
223
 
172
224
  middleware.all('**/datahub/sitemap-data.xml', sitemap);
173
- middleware.all('**/datahub/rss.xml', rssMiddleware);
174
- middleware.all('**/datahub/dataset-redirect/:id', datasetRedirect);
225
+ middleware.all(
226
+ '**/datahub/datahub_rss.xml',
227
+ make_rssMiddleware(config, generateRSS),
228
+ );
229
+ middleware.all(
230
+ `**/datahub/${viewRouteId}/:id/${rssRouteId}`,
231
+ make_rssMiddleware(config, generateItemRSS),
232
+ );
233
+ middleware.all(`**/datahub/${redirectRouteId}/:id`, datasetRedirect);
175
234
  middleware.id = 'datahub-middlewares';
176
235
 
177
236
  return middleware;
package/src/index.js CHANGED
@@ -3,6 +3,7 @@ import DatahubCardItem from './components/Result/DatahubCardItem';
3
3
  import DatahubItemView from './components/ItemView/ItemView';
4
4
  import { DatahubResultModel } from './config/models';
5
5
  import { datahub_results } from './store';
6
+ import { viewRouteId, rssRouteId } from '@eeacms/volto-datahub/constants';
6
7
 
7
8
  function tweakForNLPService(body, config) {
8
9
  if (!config.enableNLP) {
@@ -35,18 +36,22 @@ const applyConfig = (config) => {
35
36
  // datahub.resultViews[0].factories.item = "DatahubListingViewItem"
36
37
  datahub.resultItemModel.factory = 'DatahubResultModel';
37
38
 
38
- config.settings.nonContentRoutes.push(/datahubitem-view\/(.*)/); // \/(.*)\/
39
- config.settings.nonContentRoutes.push(/datahub\/rss\.xml/);
39
+ config.settings.nonContentRoutes.push(new RegExp(`${viewRouteId}\\/(.*)`));
40
+ const rssRouteIdRegexp = rssRouteId.replace('.', '\\.');
41
+ config.settings.nonContentRoutes.push(
42
+ new RegExp(`/.+/datahub/${rssRouteIdRegexp}`),
43
+ );
44
+
40
45
  config.settings.externalRoutes.push({
41
46
  match: {
42
- path: /\/.+\/datahub\/rss\.xml/,
47
+ path: new RegExp(`/.+/${rssRouteIdRegexp}`),
43
48
  strict: true,
44
49
  exact: true,
45
50
  },
46
51
  });
47
52
  config.addonRoutes = [
48
53
  {
49
- path: '*/datahubitem-view/:id',
54
+ path: `*/${viewRouteId}/:id`,
50
55
  component: DatahubItemView,
51
56
  },
52
57
 
package/src/utils.js ADDED
@@ -0,0 +1,114 @@
1
+ const OBSOLETE_KEYS = ['obsolete', 'superseded'];
2
+
3
+ export const isInternalURL = (url) => {
4
+ let internal = false;
5
+ url.split('/').forEach((part) => {
6
+ if (part.split('_')[6] === 'i') {
7
+ internal = true;
8
+ }
9
+ });
10
+ return internal;
11
+ };
12
+
13
+ export const isObsolete = (status) => {
14
+ let obsolete = false;
15
+ if (status) {
16
+ if (Array.isArray(status)) {
17
+ if (
18
+ status.filter((stat) => OBSOLETE_KEYS.includes(stat?.key)).length > 0
19
+ ) {
20
+ obsolete = true;
21
+ }
22
+ } else {
23
+ if (OBSOLETE_KEYS.includes(status?.key)) {
24
+ obsolete = true;
25
+ }
26
+ }
27
+ }
28
+ return obsolete;
29
+ };
30
+
31
+ export const isInternal = (item) => {
32
+ let internal = false;
33
+ const links = item?.link || [];
34
+ links.forEach((link) => {
35
+ if (isInternalURL(link?.url)) {
36
+ internal = true;
37
+ }
38
+ });
39
+ return internal;
40
+ };
41
+
42
+ export const groupBy = (obj, key) => {
43
+ return obj.reduce((rv, item) => {
44
+ const group = rv[item[key]] || [];
45
+ group.push(item);
46
+ rv[item[key]] = group;
47
+ return rv;
48
+ }, {});
49
+ };
50
+
51
+ export function parseDatasets(children) {
52
+ const all_datasets = children.map((v, e) => {
53
+ let date;
54
+ if (v.resourceTemporalExtentDetails) {
55
+ const tc = v.resourceTemporalExtentDetails[0];
56
+ const { start, end } = tc || {};
57
+ const tc_start = start?.date
58
+ ? new Date(Date.parse(start.date)).getFullYear()
59
+ : '';
60
+ const tc_end = end?.date
61
+ ? new Date(Date.parse(end.date)).getFullYear()
62
+ : '';
63
+ if (tc_start === tc_end) {
64
+ date = tc_start;
65
+ } else {
66
+ date = tc_start + '-' + tc_end;
67
+ }
68
+ } else {
69
+ date = '';
70
+ }
71
+
72
+ return Object.assign({ temporalDateRange: date, ...v }, e);
73
+ });
74
+
75
+ const datasets = all_datasets.filter((v) => {
76
+ return !(isObsolete(v.cl_status) || isInternal(v));
77
+ });
78
+
79
+ const archivedOrRestrictedDatasets = all_datasets.filter((v) => {
80
+ return isObsolete(v.cl_status) || isInternal(v);
81
+ });
82
+
83
+ const groupDatasets = (items) => {
84
+ const datasetsByCoverage = groupBy(items, 'temporalDateRange');
85
+
86
+ const sortedDatasets = Object.keys(datasetsByCoverage).sort(function (
87
+ a,
88
+ b,
89
+ ) {
90
+ a = Math.max(...a.split('-'));
91
+ b = Math.max(...b.split('-'));
92
+ return b - a;
93
+ });
94
+
95
+ const groupedDatasets = sortedDatasets.map((v, i) => {
96
+ return { id: i, date: v, children: datasetsByCoverage[v] };
97
+ });
98
+
99
+ return groupedDatasets;
100
+ };
101
+
102
+ const groupedByTemporalCoverage = groupDatasets(datasets);
103
+ const groupedByArchivedOrRestricted = groupDatasets(
104
+ archivedOrRestrictedDatasets,
105
+ );
106
+
107
+ return {
108
+ all_datasets,
109
+ datasets,
110
+ archivedOrRestrictedDatasets,
111
+ groupedByTemporalCoverage,
112
+ groupedByArchivedOrRestricted,
113
+ };
114
+ }