@eeacms/volto-datahub 1.0.2 → 1.0.3

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,21 @@ 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.3](https://github.com/eea/volto-datahub/compare/1.0.2...1.0.3) - 25 November 2022
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - Use volto alpha [kreafox - [`a70c4c0`](https://github.com/eea/volto-datahub/commit/a70c4c02a53e69f5fee3cc27c4f4fa0aaad5ff95)]
12
+ - SSR for datahub item [Tiberiu Ichim - [`5cc9695`](https://github.com/eea/volto-datahub/commit/5cc9695f6e0c9d098a83c261135ebbb56ee2655a)]
13
+ - updated condition for displaying message for missing product id [Zoltan Szabo - [`1aab056`](https://github.com/eea/volto-datahub/commit/1aab0560020c4e13db7ac39301c806f0362a1bea)]
14
+ - updated message [Zoltan Szabo - [`4d71ec7`](https://github.com/eea/volto-datahub/commit/4d71ec75fba697fbc99286ae4312b8e65c2dfdd9)]
15
+ - wip, show error message when product id is not found [Zoltan Szabo - [`6fff576`](https://github.com/eea/volto-datahub/commit/6fff57609a53cb9f4dea5196e67e74a688371eba)]
16
+ - moved up the legal instruments facet [Zoltan Szabo - [`c453842`](https://github.com/eea/volto-datahub/commit/c4538426f2b54318e99ab2584f8d3d87984a33f6)]
17
+ - Added new facet for available formats [Zoltan Szabo - [`1c3de33`](https://github.com/eea/volto-datahub/commit/1c3de33e28b73d696e972aa81695f7ca8c176d0b)]
18
+ - show available formats on listing [Zoltan Szabo - [`0ee2f6b`](https://github.com/eea/volto-datahub/commit/0ee2f6b1a3a64b3b25748c4a8baedac547d04868)]
19
+ - show the access level info for datasets [Zoltan Szabo - [`217641e`](https://github.com/eea/volto-datahub/commit/217641e2fe8b6d16331d80fbbe2a5c7a1b12b894)]
20
+ - Revert "test(estlint): Fix .project.eslintrc.js" [Tiberiu Ichim - [`3c36650`](https://github.com/eea/volto-datahub/commit/3c36650806b3a8c9a11ffc6ad16445f0a4cacee9)]
21
+ - test(estlint): Fix .project.eslintrc.js [Alin Voinea - [`cdfbbdd`](https://github.com/eea/volto-datahub/commit/cdfbbdd0a777bd56118d961f56b8005800faeb2c)]
7
22
  ### [1.0.2](https://github.com/eea/volto-datahub/compare/1.0.1...1.0.2) - 15 November 2022
8
23
 
9
24
  #### :hammer_and_wrench: Others
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-datahub",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "@eeacms/volto-datahub: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -21,8 +21,8 @@
21
21
  "@eeacms/volto-listing-block": "*"
22
22
  },
23
23
  "devDependencies": {
24
- "@plone/scripts": "*",
25
24
  "@cypress/code-coverage": "^3.10.0",
25
+ "@plone/scripts": "*",
26
26
  "babel-plugin-transform-class-properties": "^6.24.1",
27
27
  "md5": "^2.3.0"
28
28
  },
@@ -2,6 +2,28 @@ import React from 'react';
2
2
  import { Icon, List, Accordion } from 'semantic-ui-react';
3
3
 
4
4
  import servicesSVG from './icons/services.svg';
5
+ import lockSVG from 'remixicon/icons/System/lock-line.svg';
6
+
7
+ const is_internal_url = (url) => {
8
+ let internal = false;
9
+ url.split('/').forEach((part) => {
10
+ if (part.split('_')[6] === 'i') {
11
+ internal = true;
12
+ }
13
+ });
14
+ return internal;
15
+ };
16
+
17
+ const is_internal = (dataset) => {
18
+ let internal = false;
19
+ const links = dataset?.link || [];
20
+ links.forEach((link) => {
21
+ if (is_internal_url(link?.url)) {
22
+ internal = true;
23
+ }
24
+ });
25
+ return internal;
26
+ };
5
27
 
6
28
  const SVGIcon = ({ name, size, color, className, title, onClick }) => {
7
29
  return (
@@ -51,6 +73,9 @@ const DatasetList = (props) => {
51
73
  >
52
74
  <span>{item.name}</span>
53
75
  </a>
76
+ {is_internal_url(item.url) && (
77
+ <SVGIcon name={lockSVG} size="18" />
78
+ )}
54
79
  </div>
55
80
  </List.Content>
56
81
  {item.description && (
@@ -87,6 +112,9 @@ const DatasetList = (props) => {
87
112
  Download link
88
113
  </a>
89
114
  )}
115
+ {is_internal_url(item.url) && (
116
+ <SVGIcon name={lockSVG} size="18" />
117
+ )}
90
118
  </div>
91
119
  </List.Content>
92
120
  </List.Item>
@@ -107,6 +135,9 @@ const DatasetList = (props) => {
107
135
  >
108
136
  WebDAV: {item.name || item.function}
109
137
  </a>
138
+ {is_internal_url(item.url) && (
139
+ <SVGIcon name={lockSVG} size="18" />
140
+ )}
110
141
  </div>
111
142
  </List.Content>
112
143
  </List.Item>
@@ -127,6 +158,9 @@ const DatasetList = (props) => {
127
158
  >
128
159
  WebDAV: {item.name || item.function}
129
160
  </a>
161
+ {is_internal_url(item.url) && (
162
+ <SVGIcon name={lockSVG} size="18" />
163
+ )}
130
164
  </div>
131
165
  </List.Content>
132
166
  </List.Item>
@@ -144,13 +178,18 @@ const DatasetList = (props) => {
144
178
  return (
145
179
  <List.Item key={i}>
146
180
  <List.Content>
147
- <SVGIcon name={servicesSVG} size="18" />
148
- {/* {(item.name || item.description) && (
149
- <span className="item-protocol">{item.protocol}:</span>
150
- )} */}
151
- <a className="item-link" href={item.url}>
152
- {item.protocol} {item.name || item.description}
153
- </a>
181
+ <div>
182
+ <SVGIcon name={servicesSVG} size="18" />
183
+ {/* {(item.name || item.description) && (
184
+ <span className="item-protocol">{item.protocol}:</span>
185
+ )} */}
186
+ <a className="item-link" href={item.url}>
187
+ {item.protocol} {item.name || item.description}
188
+ </a>
189
+ {is_internal_url(item.url) && (
190
+ <SVGIcon name={lockSVG} size="18" />
191
+ )}
192
+ </div>
154
193
  </List.Content>
155
194
  </List.Item>
156
195
  );
@@ -160,13 +199,18 @@ const DatasetList = (props) => {
160
199
  return (
161
200
  <List.Item key={i}>
162
201
  <List.Content>
163
- <SVGIcon name={servicesSVG} size="18" />
164
- {/* {(item.name || item.description) && (
165
- <span className="item-protocol">{item.protocol}:</span>
166
- )} */}
167
- <a className="item-link" href={item.url}>
168
- {item.protocol} {item.name || item.description}
169
- </a>
202
+ <div>
203
+ <SVGIcon name={servicesSVG} size="18" />
204
+ {/* {(item.name || item.description) && (
205
+ <span className="item-protocol">{item.protocol}:</span>
206
+ )} */}
207
+ <a className="item-link" href={item.url}>
208
+ {item.protocol} {item.name || item.description}
209
+ </a>
210
+ {is_internal_url(item.url) && (
211
+ <SVGIcon name={lockSVG} size="18" />
212
+ )}
213
+ </div>
170
214
  </List.Content>
171
215
  </List.Item>
172
216
  );
@@ -193,6 +237,9 @@ const DatasetList = (props) => {
193
237
  >
194
238
  <span>{item.name || item.url}</span>
195
239
  </a>
240
+ {is_internal_url(item.url) && (
241
+ <SVGIcon name={lockSVG} size="18" />
242
+ )}
196
243
  </div>
197
244
  </List.Content>
198
245
  {item.description && (
@@ -259,6 +306,7 @@ const Datasets = (props) => {
259
306
  );
260
307
  })}
261
308
  </span>
309
+ {is_internal(dataset) && <SVGIcon name={lockSVG} size="18" />}
262
310
  </span>
263
311
  <Icon className="ri-arrow-down-s-line" />
264
312
  </Accordion.Title>
@@ -1,36 +1,53 @@
1
1
  import React from 'react';
2
2
  import { Portal } from 'react-portal';
3
- import { useDispatch } from 'react-redux';
3
+ import { useDispatch, useSelector } from 'react-redux';
4
4
  import { Link, useLocation } from 'react-router-dom';
5
5
  import { Container, Icon } from 'semantic-ui-react';
6
6
  import { Toolbar } from '@plone/volto/components';
7
7
  import { BodyClass } from '@plone/volto/helpers';
8
8
  import config from '@plone/volto/registry';
9
- import {
10
- useResult,
11
- AppConfigContext,
12
- SearchContext,
13
- rebind,
14
- applyConfigurationSchema,
15
- DateTime,
16
- } from '@eeacms/search';
17
- import { SearchProvider, WithSearch } from '@elastic/react-search-ui';
9
+ import { rebind, applyConfigurationSchema, DateTime } from '@eeacms/search';
18
10
  import { Callout, Banner } from '@eeacms/volto-eea-design-system/ui';
19
11
  import {
20
12
  MoreLikeThis,
21
13
  MetadataSection,
22
14
  Datasets,
23
15
  } from '@eeacms/volto-datahub/components/ItemView';
24
- // import bannerBG from './banner.svg';
16
+
17
+ import { asyncConnect, Helmet } from '@plone/volto/helpers';
18
+ import { fetchResult } from '@eeacms/search/lib/hocs/useResult';
19
+ import { setDatahubResult } from '@eeacms/volto-datahub/store';
25
20
 
26
21
  const appName = 'datahub';
27
22
 
28
23
  function ItemView(props) {
29
- const { docid, location, appConfig } = props;
24
+ const { docid, location } = props;
30
25
  const { fromPathname, fromSearch } = location?.state || {};
31
26
  const dispatch = useDispatch();
32
27
  // const content = useSelector((state) => state.content.data);
33
- const result = useResult(null, docid);
28
+ let result = useSelector((state) => state.datahub_results?.[docid]);
29
+ const registry = config.settings.searchlib;
30
+ const appConfig = React.useMemo(
31
+ () => applyConfigurationSchema(rebind(registry.searchui[appName])),
32
+ [registry.searchui],
33
+ );
34
+
35
+ React.useEffect(() => {
36
+ let ignore = false;
37
+
38
+ const doIt = async () => {
39
+ const result = await fetchResult(docid, appConfig, registry);
40
+ dispatch(setDatahubResult(docid, result));
41
+ };
42
+
43
+ if (!ignore && !result) {
44
+ doIt();
45
+ }
46
+ return () => {
47
+ ignore = true;
48
+ };
49
+ }, [result, docid, appConfig, registry, dispatch]);
50
+
34
51
  const item = result ? result._result : null;
35
52
  const { title, description, raw_value } = item || {}; // readingTime
36
53
  const { changeDate, resourceIdentifier } = raw_value?.raw || {};
@@ -39,7 +56,7 @@ function ItemView(props) {
39
56
  return p.code.includes('DAT');
40
57
  })[0]?.code;
41
58
 
42
- const rawTitle = title?.raw || '';
59
+ const rawTitle = item && item._meta.found ? title?.raw || '' : docid;
43
60
 
44
61
  React.useEffect(() => {
45
62
  const handler = async () => {
@@ -67,48 +84,54 @@ function ItemView(props) {
67
84
  handler();
68
85
  }, [item, dispatch, docid, rawTitle]);
69
86
 
70
- return item ? (
87
+ const [isClient, setIsClient] = React.useState();
88
+ React.useEffect(() => setIsClient(true), []);
89
+
90
+ return item && item._meta.found ? (
71
91
  <div className="dataset-view">
72
- <Portal node={document.getElementById('page-header')}>
73
- <div className="dataset">
74
- <Banner>
75
- <Banner.Content>
76
- <Banner.Subtitle>
77
- <Link
78
- to={
79
- location?.state
80
- ? { pathname: fromPathname, search: fromSearch }
81
- : {
82
- pathname: '/en/datahub/',
83
- }
84
- }
85
- >
86
- <Icon className="arrow left" />
87
- Datahub overview
88
- </Link>
89
- </Banner.Subtitle>
90
- <Banner.Title>{title?.raw}</Banner.Title>
91
- <Banner.Metadata>
92
- <Banner.MetadataField label="Prod-ID" value={prodID} />
93
- <Banner.MetadataField
94
- label="Published"
95
- type="date"
96
- value={<DateTime format="DATE_MED" value={result.issued} />}
97
- />
98
- <Banner.MetadataField
99
- label="Last modified"
100
- type="date"
101
- value={<DateTime format="DATE_MED" value={changeDate} />}
102
- />
103
- {/* <Banner.MetadataField
92
+ <Helmet title={title?.raw} />
93
+ {isClient && (
94
+ <Portal node={document.getElementById('page-header')}>
95
+ <div className="dataset">
96
+ <Banner>
97
+ <Banner.Content>
98
+ <Banner.Subtitle>
99
+ <Link
100
+ to={
101
+ location?.state
102
+ ? { pathname: fromPathname, search: fromSearch }
103
+ : {
104
+ pathname: '/en/datahub/',
105
+ }
106
+ }
107
+ >
108
+ <Icon className="arrow left" />
109
+ Datahub overview
110
+ </Link>
111
+ </Banner.Subtitle>
112
+ <Banner.Title>{title?.raw}</Banner.Title>
113
+ <Banner.Metadata>
114
+ <Banner.MetadataField label="Prod-ID" value={prodID} />
115
+ <Banner.MetadataField
116
+ label="Published"
117
+ type="date"
118
+ value={<DateTime format="DATE_MED" value={result.issued} />}
119
+ />
120
+ <Banner.MetadataField
121
+ label="Last modified"
122
+ type="date"
123
+ value={<DateTime format="DATE_MED" value={changeDate} />}
124
+ />
125
+ {/* <Banner.MetadataField
104
126
  label="Reading time"
105
127
  value={readingTime?.raw}
106
128
  /> */}
107
- </Banner.Metadata>
108
- </Banner.Content>
109
- </Banner>
110
- </div>
111
- </Portal>
129
+ </Banner.Metadata>
130
+ </Banner.Content>
131
+ </Banner>
132
+ </div>
133
+ </Portal>
134
+ )}
112
135
 
113
136
  <div className="dataset-container">
114
137
  <Callout>{description?.raw}</Callout>
@@ -127,7 +150,13 @@ function ItemView(props) {
127
150
  </div>
128
151
  </div> */}
129
152
  </div>
130
- ) : null;
153
+ ) : item ? (
154
+ <>
155
+ <h1>Data series not found...</h1>
156
+ </>
157
+ ) : (
158
+ <></>
159
+ );
131
160
  }
132
161
 
133
162
  function DatahubItemView(props) {
@@ -136,16 +165,6 @@ function DatahubItemView(props) {
136
165
  React.useEffect(() => setIsClient(true), []);
137
166
 
138
167
  const docid = props.match?.params?.id;
139
- const registry = config.settings.searchlib;
140
-
141
- const appConfig = React.useMemo(
142
- () => applyConfigurationSchema(rebind(registry.searchui[appName])),
143
- [registry],
144
- );
145
- const appConfigContext = React.useMemo(() => ({ appConfig, registry }), [
146
- appConfig,
147
- registry,
148
- ]);
149
168
 
150
169
  return (
151
170
  <div id="view">
@@ -153,28 +172,7 @@ function DatahubItemView(props) {
153
172
  {/* Body class if displayName in component is set */}
154
173
  <BodyClass className="view-datahub-item" />
155
174
  <Container className="view-wrapper">
156
- <SearchProvider config={config}>
157
- <WithSearch
158
- mapContextToProps={(searchContext) => ({
159
- ...searchContext,
160
- })}
161
- >
162
- {(params) => {
163
- // TODO: this needs to be optimized, it causes unmounts
164
- return (
165
- <AppConfigContext.Provider value={appConfigContext}>
166
- <SearchContext.Provider value={params}>
167
- <ItemView
168
- docid={docid}
169
- location={location}
170
- appConfig={appConfig}
171
- />
172
- </SearchContext.Provider>
173
- </AppConfigContext.Provider>
174
- );
175
- }}
176
- </WithSearch>
177
- </SearchProvider>
175
+ <ItemView docid={docid} location={location} />
178
176
  </Container>
179
177
  {isClient && (
180
178
  <Portal node={document.getElementById('toolbar')}>
@@ -184,5 +182,23 @@ function DatahubItemView(props) {
184
182
  </div>
185
183
  );
186
184
  }
187
-
188
- export default DatahubItemView;
185
+ export default asyncConnect([
186
+ {
187
+ key: 'datahubItem',
188
+ promise: function datahubItem({
189
+ location,
190
+ store,
191
+ match: {
192
+ params: { id },
193
+ },
194
+ }) {
195
+ const registry = config.settings.searchlib;
196
+ const appConfig = applyConfigurationSchema(
197
+ rebind(registry.searchui[appName]),
198
+ );
199
+ return fetchResult(id, appConfig, registry).then((result) => {
200
+ store.dispatch(setDatahubResult(id, result));
201
+ });
202
+ },
203
+ },
204
+ ])(DatahubItemView);
@@ -7,13 +7,12 @@ import { UniversalCard } from '@eeacms/volto-listing-block';
7
7
 
8
8
  const DatahubCardItem = (props) => {
9
9
  const { result } = props;
10
- const { topic } = result._result || [];
10
+ const { topic, dataset_formats } = result._result || [];
11
11
 
12
12
  // let metaType = result.metaTypes || '';
13
13
  // if (metaType.length === 0) {
14
14
  // metaType = 'Others';
15
15
  // }
16
-
17
16
  const item = {
18
17
  title: (
19
18
  <Link
@@ -43,10 +42,12 @@ const DatahubCardItem = (props) => {
43
42
  <StringList value={topic.raw} />
44
43
  </div>
45
44
  ) : null}
46
- <div className="result-info">
47
- <span className="result-info-title">Available formats: </span>
48
- [Icons]
49
- </div>
45
+ {dataset_formats ? (
46
+ <div className="result-info">
47
+ <span className="result-info-title">Available formats: </span>
48
+ <StringList value={dataset_formats.raw} />
49
+ </div>
50
+ ) : null}
50
51
  </div>
51
52
  ),
52
53
  };
@@ -8,18 +8,18 @@ import { dateRangeFacet } from '@eeacms/search';
8
8
 
9
9
  const facets = [
10
10
  multiTermFacet({
11
- field: 'rod',
11
+ field: 'instrument',
12
12
  isFilterable: true,
13
13
  isMulti: true,
14
- label: 'Reporting obligations',
14
+ label: 'Legal instruments',
15
15
  show: 10000,
16
16
  showAllOptions: true, // show all options (even if 0) in modal facet
17
17
  }),
18
18
  multiTermFacet({
19
- field: 'instrument',
19
+ field: 'rod',
20
20
  isFilterable: true,
21
21
  isMulti: true,
22
- label: 'Legal instruments',
22
+ label: 'Reporting obligations',
23
23
  show: 10000,
24
24
  showAllOptions: true, // show all options (even if 0) in modal facet
25
25
  }),
@@ -32,6 +32,14 @@ const facets = [
32
32
  showAllOptions: true, // show all options (even if 0) in modal facet
33
33
  alwaysVisible: true,
34
34
  }),
35
+ multiTermFacet({
36
+ field: 'dataset_formats',
37
+ isFilterable: true,
38
+ isMulti: true,
39
+ label: 'Available formats',
40
+ show: 10000,
41
+ showAllOptions: true, // show all options (even if 0) in modal facet
42
+ }),
35
43
  multiTermFacet({
36
44
  field: 'gemet',
37
45
  isFilterable: true,
package/src/index.js CHANGED
@@ -2,6 +2,7 @@ import installDatahub from './config';
2
2
  import DatahubCardItem from './components/Result/DatahubCardItem';
3
3
  import DatahubItemView from './components/ItemView/ItemView';
4
4
  import { DatahubResultModel } from './config/models';
5
+ import { datahub_results } from './store';
5
6
 
6
7
  function tweakForNLPService(body, config) {
7
8
  if (!config.enableNLP) {
@@ -42,6 +43,7 @@ const applyConfig = (config) => {
42
43
 
43
44
  ...(config.addonRoutes || []),
44
45
  ];
46
+ config.addonReducers.datahub_results = datahub_results;
45
47
  return config;
46
48
  };
47
49
 
package/src/store.js ADDED
@@ -0,0 +1,16 @@
1
+ export const setDatahubResult = (id, result) => {
2
+ return {
3
+ type: 'SET_DATAHUB_RESULT',
4
+ id,
5
+ result,
6
+ };
7
+ };
8
+
9
+ const initialState = {};
10
+
11
+ export const datahub_results = (state = initialState, action) => {
12
+ return {
13
+ ...state,
14
+ [action.id]: action.result,
15
+ };
16
+ };