@eeacms/volto-datahub 0.1.8 → 0.1.10

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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { Button } from 'semantic-ui-react';
3
+ import { Tab, Card, Menu } from 'semantic-ui-react';
4
4
  import useDeepCompareEffect from 'use-deep-compare-effect';
5
5
  import { useAtom } from 'jotai';
6
6
 
@@ -151,79 +151,96 @@ const LandingPage = (props) => {
151
151
  sections,
152
152
  ]);
153
153
 
154
- return (
155
- <div className="landing-page-container">
156
- <div className="landing-page">
157
- <h4 className="browse-by">Browse by</h4>
154
+ const panes = sections
155
+ .filter((section) => !section.hidden)
156
+ .map((section, index) => {
157
+ const tabIndex = index + 1;
158
158
 
159
- <div className="filters">
160
- {sections
161
- .filter((section) => !section.hidden)
162
- .map((section) => {
163
- return (
164
- <Button
165
- key={section.facetField}
166
- toggle
159
+ return {
160
+ id: section,
161
+ menuItem: {
162
+ children: () => {
163
+ return (
164
+ <React.Fragment key={`tab-${tabIndex}`}>
165
+ <Menu.Item
167
166
  active={activeSection === section.facetField}
168
- className="ui button"
169
167
  onClick={() => setActiveSection(section.facetField)}
170
168
  >
171
169
  {section.title}
172
- </Button>
173
- );
174
- })}
175
- </div>
176
- <div className="landing-page-cards">
177
- <div className="ui cards">
178
- {sortedTiles(tiles, activeSectionConfig, appConfig).map((topic) => {
179
- const onClickHandler = () => {
180
- setFilter(
181
- activeSection,
182
- topic.value,
183
- activeSectionConfig.filterType || 'any',
184
- );
170
+ </Menu.Item>
171
+ </React.Fragment>
172
+ );
173
+ },
174
+ },
175
+ render: () => {
176
+ return (
177
+ <Tab.Pane>
178
+ <div className="landing-page-cards">
179
+ <Card.Group itemsPerRow={5}>
180
+ {sortedTiles(tiles, activeSectionConfig, appConfig).map(
181
+ (topic, index) => {
182
+ const onClickHandler = () => {
183
+ setFilter(
184
+ activeSection,
185
+ topic.value,
186
+ activeSectionConfig.filterType || 'any',
187
+ );
185
188
 
186
- // apply configured default values
187
- appConfig.facets
188
- .filter((f) => f.field !== activeSection && f.default)
189
- .forEach((facet) => {
190
- facet.default.values.forEach((value) =>
191
- setFilter(
192
- facet.field,
193
- value,
194
- facet.default.type || 'any',
195
- ),
196
- );
197
- });
198
- setSort(sortField, sortDirection);
199
- setShowFacets(true);
200
- };
189
+ // apply configured default values
190
+ appConfig.facets
191
+ .filter((f) => f.field !== activeSection && f.default)
192
+ .forEach((facet) => {
193
+ facet.default.values.forEach((value) =>
194
+ setFilter(
195
+ facet.field,
196
+ value,
197
+ facet.default.type || 'any',
198
+ ),
199
+ );
200
+ });
201
+ setSort(sortField, sortDirection);
202
+ setShowFacets(true);
203
+ };
201
204
 
202
- return (
203
- <div
204
- key={topic.value}
205
- tabIndex="-1"
206
- role="button"
207
- onKeyDown={onClickHandler}
208
- className="ui card"
209
- onClick={onClickHandler}
210
- >
211
- <div className="content">
212
- <div className="header">
213
- {icon ? <Icon {...icon} type={topic.value} /> : ''}
214
- <Term term={topic.value} field={activeSection} />
215
- </div>
216
- </div>
217
- <div className="extra content">
218
- <span className="count">
219
- {topic.count} {topic.count === 1 ? 'item' : 'items'}
220
- </span>
221
- </div>
222
- </div>
223
- );
224
- })}
225
- </div>
226
- </div>
205
+ return (
206
+ <Card onClick={onClickHandler} key={index}>
207
+ <Card.Content>
208
+ <Card.Header>
209
+ {icon ? (
210
+ <Icon {...icon} type={topic.value} />
211
+ ) : (
212
+ ''
213
+ )}
214
+ <Term term={topic.value} field={activeSection} />
215
+ </Card.Header>
216
+ </Card.Content>
217
+ <Card.Content extra>
218
+ <span className="count">
219
+ {topic.count}{' '}
220
+ {topic.count === 1 ? 'item' : 'items'}
221
+ </span>
222
+ </Card.Content>
223
+ </Card>
224
+ );
225
+ },
226
+ )}
227
+ </Card.Group>
228
+ </div>
229
+ </Tab.Pane>
230
+ );
231
+ },
232
+ };
233
+ });
234
+
235
+ return (
236
+ <div className="landing-page-container">
237
+ <div className="landing-page">
238
+ <h4 className="browse-by">Browse by</h4>
239
+ <Tab
240
+ className="search-tab"
241
+ menu={{ secondary: true, pointing: true }}
242
+ panes={panes}
243
+ />
227
244
  {hasOverflow ? (
228
245
  <div className="info">
229
246
  <p>Only first {maxPerSection} items are displayed.</p>
@@ -1,199 +1,142 @@
1
1
  import React from 'react';
2
- import cx from 'classnames';
3
- import {
4
- Label,
5
- // Button,
6
- // Dropdown
7
- } from 'semantic-ui-react';
8
- import { DateTime as FormattedDate, StringList } from '@eeacms/search';
9
- import { DateTime } from 'luxon';
10
- // import { useAppConfig, useWindowDimensions } from '@eeacms/search/lib/hocs';
11
- // import { TagsList } from '@eeacms/search/components'; // SegmentedBreadcrumb,
12
- // import { firstWords, getTermDisplayValue } from '@eeacms/search/lib/utils';
13
- // import MoreLikeThisTrigger from '@eeacms/search/components/Result/MoreLikeThisTrigger';
14
- // import ExternalLink from '@eeacms/search/components/Result/ExternalLink';
15
- // import ResultContext from '@eeacms/search/components/Result/ResultContext';
16
- // import ContentClusters from '@eeacms/search/components/Result/ContentClusters';
17
- import {
18
- useAppConfig,
19
- ResultContext,
20
- firstWords,
21
- // ContentClusters,
22
- // useWindowDimensions,
23
- // MoreLikeThisTrigger,
24
- // TagsList,
25
- // ExternalLink,
26
- // getTermDisplayValue,
27
- } from '@eeacms/search';
2
+
3
+ import { DateTime, StringList } from '@eeacms/search';
4
+ import { ResultContext } from '@eeacms/search';
28
5
  import { Link } from 'react-router-dom';
6
+ import { UniversalItem } from '@eeacms/volto-listing-block';
29
7
 
30
8
  const DatahubCardItem = (props) => {
31
- const {
32
- result,
33
- // showControls = true
34
- } = props;
35
- const { appConfig } = useAppConfig();
36
- const {
37
- // vocab = {},
38
- debugQuery,
39
- } = appConfig;
9
+ const { result } = props;
40
10
  const { topic } = result._result || [];
41
- const [hovered, setHovered] = React.useState(false);
42
-
43
- // const { pathname, search } = useLocation();
44
11
 
45
- let metaType = result.metaTypes || '';
46
- if (metaType.length === 0) {
47
- metaType = 'Others';
48
- }
12
+ // let metaType = result.metaTypes || '';
13
+ // if (metaType.length === 0) {
14
+ // metaType = 'Others';
15
+ // }
49
16
 
50
- const classColLeft = result.hasImage ? 'col-left' : 'col-left no-image';
51
17
  const [resultId] = (result.href || '').split('/').reverse();
52
18
 
53
- // const { width } = useWindowDimensions();
54
- // const isSmallScreen = width < 1000;
55
- // const clusters = result.clusterInfo;
56
- // console.log('result', result.metaTypes, result._result);
57
-
58
- return (
59
- <div
60
- className={cx('search-result', { hovered })}
61
- onMouseEnter={() => setHovered(true)}
62
- onMouseLeave={() => setHovered(false)}
63
- >
64
- {/*<div className="col-full">
65
- <div className="meta">
66
- <ContentClusters clusters={clusters} item={result} />
67
- <div className="tags-list">
68
- <TagsList value={result.tags} />
69
- </div>
19
+ const item = {
20
+ title: (
21
+ <Link
22
+ to={{
23
+ pathname: `/en/datahub/datahubitem-view/${resultId}`,
24
+ state: {
25
+ fromPathname: window.location.pathname,
26
+ fromSearch: window.location.search,
27
+ },
28
+ }}
29
+ title={result.title}
30
+ >
31
+ {result.title}
32
+ </Link>
33
+ ),
34
+ description: <ResultContext {...props} />,
35
+ preview_image_url: result.hasImage ? result.thumbUrl : undefined,
36
+ extra: (
37
+ <div className="result-bottom">
38
+ <div className="result-info">
39
+ <span className="result-info-title">Published: </span>
40
+ <DateTime format="DATE_MED" value={result.issued} />
70
41
  </div>
71
- </div>*/}
72
- <div className={classColLeft}>
73
- <div className="details">
42
+ {topic ? (
74
43
  <div className="result-info">
75
- <span className="result-info-title">Author: </span>
76
- {result._result?.raw_value?.raw.Org}
44
+ <span className="result-info-title">Topics: </span>
45
+ <StringList value={topic.raw} />
77
46
  </div>
78
- <h3>
79
- <Link
80
- to={{
81
- pathname: `/en/datahub/datahubitem-view/${resultId}`,
82
- state: {
83
- fromPathname: window.location.pathname,
84
- fromSearch: window.location.search,
85
- },
86
- }}
87
- title={result.title}
88
- >
89
- {firstWords(result.title, 12)}
90
- </Link>
91
- {result.isNew && (
92
- <Label className="new-item" horizontal>
93
- New
94
- </Label>
95
- )}
96
- {result.isExpired && (
97
- <Label className="archived-item" horizontal>
98
- Archived
99
- </Label>
100
- )}
101
- </h3>
102
- {/* <SegmentedBreadcrumb */}
103
- {/* href={result.href} */}
104
- {/* short={true} */}
105
- {/* maxChars={40} */}
106
- {/* /> */}
47
+ ) : null}
48
+ <div className="result-info">
49
+ <span className="result-info-title">Available formats: </span>
50
+ [Icons]
51
+ </div>
52
+ </div>
53
+ ),
54
+ };
107
55
 
108
- {/*<div className="source">
109
- <span>Source: </span>
110
- <Link to={`/datahub/view/${resultId}`} title={result.title}>
111
- <strong title={result.source} className="source">
112
- {firstWords(
113
- getTermDisplayValue({
114
- vocab,
115
- field: 'cluster_name',
116
- term: result.source,
117
- }),
118
- 8,
119
- )}
120
- </strong>
121
- </Link>
56
+ const itemModel = {
57
+ hasImage: result.hasImage,
58
+ hasDescription: true,
59
+ '@type': 'searchItem',
60
+ };
122
61
 
123
- {showControls && !isSmallScreen && (
124
- <MoreLikeThisTrigger
125
- view={Button}
126
- className="mlt"
127
- compact
128
- color="green"
129
- size="mini"
130
- result={result}
131
- >
132
- more like this
133
- </MoreLikeThisTrigger>
134
- )}
135
- {showControls && isSmallScreen && (
136
- <Dropdown icon="ellipsis vertical">
137
- <Dropdown.Menu className="mlt">
138
- <MoreLikeThisTrigger result={result} view={Dropdown.Item}>
139
- More like this
140
- </MoreLikeThisTrigger>
141
- </Dropdown.Menu>
142
- </Dropdown>
143
- )}
144
- </div>*/}
62
+ return <UniversalItem item={item} itemModel={itemModel} />;
63
+ };
145
64
 
146
- {props.children ? props.children : <ResultContext {...props} />}
65
+ // <div
66
+ // className={cx('search-result', { hovered })}
67
+ // onMouseEnter={() => setHovered(true)}
68
+ // onMouseLeave={() => setHovered(false)}
69
+ // >
70
+ // <div className={classColLeft}>
71
+ // <div className="details">
72
+ // <h3>
73
+ // <Link
74
+ // to={{
75
+ // pathname: `/en/datahub/datahubitem-view/${resultId}`,
76
+ // state: {
77
+ // fromPathname: window.location.pathname,
78
+ // fromSearch: window.location.search,
79
+ // },
80
+ // }}
81
+ // title={result.title}
82
+ // >
83
+ // {firstWords(result.title, 12)}
84
+ // </Link>
85
+ // {result.isNew && (
86
+ // <Label className="new-item" horizontal>
87
+ // New
88
+ // </Label>
89
+ // )}
90
+ // {result.isExpired && (
91
+ // <Label className="archived-item" horizontal>
92
+ // Archived
93
+ // </Label>
94
+ // )}
95
+ // </h3>
96
+ // {props.children ? props.children : <ResultContext {...props} />}
147
97
 
148
- <div className="result-bottom">
149
- {topic ? (
150
- <div className="result-info">
151
- <span className="result-info-title">Topics: </span>
152
- <StringList value={topic.raw} />
153
- </div>
154
- ) : null}
155
- <div className="result-info">
156
- <span className="result-info-title">Last modified: </span>
157
- <FormattedDate
158
- format="DATE_MED"
159
- value={DateTime.fromISO(
160
- result?._result?.raw_value.raw.changeDate,
161
- )}
162
- />
163
- </div>
164
- <div className="result-info">
165
- <span className="result-info-title">Available formats: </span>
166
- [Icons]
167
- </div>
168
- </div>
169
- </div>
170
- {debugQuery && (
171
- <div>
172
- <div>Explanation:</div>
173
- <pre>{JSON.stringify(result.explanation, undefined, 2)}</pre>
174
- </div>
175
- )}
176
- </div>
177
- {result.hasImage ? (
178
- <div className="col-right">
179
- <a
180
- className={`centered fluid image img-thumbnail`}
181
- href={result.href}
182
- target="_blank"
183
- rel="noreferrer"
184
- >
185
- <img
186
- alt={result.title}
187
- src={result.thumbUrl}
188
- onError={(e) => {
189
- e.target.style.display = 'none';
190
- }}
191
- />
192
- </a>
193
- </div>
194
- ) : null}
195
- </div>
196
- );
197
- };
98
+ // <div className="result-bottom">
99
+ // {topic ? (
100
+ // <div className="result-info">
101
+ // <span className="result-info-title">Topics: </span>
102
+ // <StringList value={topic.raw} />
103
+ // </div>
104
+ // ) : null}
105
+ // <div className="result-info">
106
+ // <span className="result-info-title">Published: </span>
107
+ // <DateTime format="DATE_MED" value={result.issued} />
108
+ // </div>
109
+ // <div className="result-info">
110
+ // <span className="result-info-title">Available formats: </span>
111
+ // [Icons]
112
+ // </div>
113
+ // </div>
114
+ // </div>
115
+ // {debugQuery && (
116
+ // <div>
117
+ // <div>Explanation:</div>
118
+ // <pre>{JSON.stringify(result.explanation, undefined, 2)}</pre>
119
+ // </div>
120
+ // )}
121
+ // </div>
122
+ // {result.hasImage ? (
123
+ // <div className="col-right">
124
+ // <a
125
+ // className={`centered fluid image img-thumbnail`}
126
+ // href={result.href}
127
+ // target="_blank"
128
+ // rel="noreferrer"
129
+ // >
130
+ // <img
131
+ // alt={result.title}
132
+ // src={result.thumbUrl}
133
+ // onError={(e) => {
134
+ // e.target.style.display = 'none';
135
+ // }}
136
+ // />
137
+ // </a>
138
+ // </div>
139
+ // ) : null}
140
+ // </div>
198
141
 
199
142
  export default DatahubCardItem;
@@ -14,7 +14,7 @@ const datahubConfig = {
14
14
  ...filters,
15
15
  ...vocabs,
16
16
 
17
- sourceExcludedFields: ['nlp_*', 'event'], // don't need these in results
17
+ sourceExcludedFields: ['nlp_*', 'event', 'raw_value'], // don't need these in results
18
18
  };
19
19
 
20
20
  const getClientProxyAddress = () => {
package/src/index.js CHANGED
@@ -4,7 +4,6 @@ import DatahubItemView from './components/ItemView/ItemView';
4
4
 
5
5
  function tweakForNLPService(body, config) {
6
6
  if (!config.enableNLP) {
7
- body._source = { ...body.source };
8
7
  delete body.source;
9
8
  delete body.index;
10
9
  return body;
@@ -25,9 +24,10 @@ const applyConfig = (config) => {
25
24
  // Tweak the searchlib config to use the middleware instead of the index
26
25
  datahub.elastic_index = '_es/datahub';
27
26
  datahub.index_name = 'data_searchui_datahub';
28
- datahub.enableNLP = false;
27
+ datahub.enableNLP = true;
29
28
  datahub.showPromptQueries = false;
30
29
  datahub.requestBodyModifiers.push(tweakForNLPService);
30
+ datahub.indexBaseUrl = 'https://galliwasp.eea.europa.eu';
31
31
  // datahub.resultViews[0].factories.item = "DatahubListingViewItem"
32
32
 
33
33
  config.settings.nonContentRoutes.push(/datahubitem-view\/(.*)/); // \/(.*)\/