@eeacms/volto-datahub 1.0.24 → 1.0.26
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 +29 -6
- package/DEVELOP.md +56 -0
- package/README.md +35 -23
- package/docker-compose.yml +32 -0
- package/jest-addon.config.js +1 -0
- package/locales/de/LC_MESSAGES/volto.po +14 -0
- package/locales/it/LC_MESSAGES/volto.po +14 -0
- package/locales/ro/LC_MESSAGES/volto.po +14 -0
- package/locales/volto.pot +16 -0
- package/package.json +6 -3
- package/src/components/ItemView/Datasets/DatasetItemDownloadList.jsx +7 -59
- package/src/components/ItemView/Datasets/DatasetItemsList.jsx +227 -108
- package/src/components/ItemView/Datasets/DatasetsTab.jsx +28 -26
- package/src/components/ItemView/Datasets/DatasetsView.jsx +2 -3
- package/src/components/ItemView/ItemView.jsx +3 -21
- package/src/components/ItemView/MetadataSection.test.jsx +18 -0
- package/src/components/ItemView/utils.test.js +128 -0
- package/src/components/LandingPage/DatahubLandingPage.jsx +0 -8
- package/src/components/Result/DatahubCardItem.jsx +1 -85
- package/src/config/facets.js +1 -1
- package/src/config/index.js +0 -1
- package/src/express-middleware.js +56 -1
- package/src/index.js +8 -0
- package/.i18n.babel.config.js +0 -1
|
@@ -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
|
+
});
|
|
@@ -4,12 +4,6 @@ import { Tab, Menu, Divider, List } from 'semantic-ui-react';
|
|
|
4
4
|
import useDeepCompareEffect from 'use-deep-compare-effect';
|
|
5
5
|
import { useAtom } from 'jotai';
|
|
6
6
|
|
|
7
|
-
// import { showFacetsAsideAtom } from '@eeacms/search/state';
|
|
8
|
-
// import { getFacetCounts } from '@eeacms/search/components/LandingPage/request';
|
|
9
|
-
// import buildStateFacets from '@eeacms/search/lib/search/state/facets';
|
|
10
|
-
// import { customOrder } from '@eeacms/search/lib/utils';
|
|
11
|
-
// import { Icon, Term } from '@eeacms/search/components';
|
|
12
|
-
|
|
13
7
|
import {
|
|
14
8
|
customOrder,
|
|
15
9
|
showFacetsAsideAtom,
|
|
@@ -50,7 +44,6 @@ const LandingPage = (props) => {
|
|
|
50
44
|
const { appConfig, children, setFilter, setSort } = props;
|
|
51
45
|
const { appName } = appConfig;
|
|
52
46
|
const { onlyLandingPage = false } = appConfig;
|
|
53
|
-
// const facetsConfig = appConfig.facets;
|
|
54
47
|
|
|
55
48
|
const {
|
|
56
49
|
sections = [],
|
|
@@ -126,7 +119,6 @@ const LandingPage = (props) => {
|
|
|
126
119
|
type: filterType,
|
|
127
120
|
})),
|
|
128
121
|
};
|
|
129
|
-
// console.log('state', state);
|
|
130
122
|
const facetCounts = await getFacetCounts(
|
|
131
123
|
state,
|
|
132
124
|
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;
|
package/src/config/facets.js
CHANGED
package/src/config/index.js
CHANGED
|
@@ -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(
|
|
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',
|
package/.i18n.babel.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@plone/volto/babel');
|