@eeacms/volto-cca-policy 0.1.53 → 0.1.55

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,38 @@ 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
+ ### [0.1.55](https://github.com/eea/volto-cca-policy/compare/0.1.54...0.1.55) - 21 December 2023
8
+
9
+ ### [0.1.54](https://github.com/eea/volto-cca-policy/compare/0.1.53...0.1.54) - 20 December 2023
10
+
11
+ #### :rocket: New Features
12
+
13
+ - feat: add mission projects search config + code refactoring [kreafox - [`bdc1e73`](https://github.com/eea/volto-cca-policy/commit/bdc1e7310e9bc8b3d66f2c63f1955c25ca233be6)]
14
+
15
+ #### :bug: Bug Fixes
16
+
17
+ - fix: import [kreafox - [`93e2726`](https://github.com/eea/volto-cca-policy/commit/93e2726b93385bda46b27bab9d8f910d939c4099)]
18
+
19
+ #### :nail_care: Enhancements
20
+
21
+ - change: update mission projects facets [kreafox - [`843a297`](https://github.com/eea/volto-cca-policy/commit/843a29710677a10e8714bbf5a2892841bfb1e029)]
22
+
23
+ #### :house: Internal changes
24
+
25
+ - style: Automated code fix [eea-jenkins - [`8fb22ff`](https://github.com/eea/volto-cca-policy/commit/8fb22ffe57b6be84ed4720a21836579839ecb7ae)]
26
+ - style: Automated code fix [eea-jenkins - [`8bf77c8`](https://github.com/eea/volto-cca-policy/commit/8bf77c8839cec40389a99fae3ab685ed5b69d146)]
27
+
28
+ #### :hammer_and_wrench: Others
29
+
30
+ - Refs #259267 - test [Tripon Eugen - [`74e7710`](https://github.com/eea/volto-cca-policy/commit/74e77106b923a9e146e5d30d9f2410cb06e2c34c)]
31
+ - Refs #259267 - test [Tripon Eugen - [`84039ba`](https://github.com/eea/volto-cca-policy/commit/84039bad25b855a708a601891796da4ff2ac8e71)]
32
+ - Refs #260715 - requested updates [Tripon Eugen - [`89214f6`](https://github.com/eea/volto-cca-policy/commit/89214f6e1b032372a40006706e142f98fb42fa12)]
33
+ - Refs #260715 - requested updates [Tripon Eugen - [`c0353d8`](https://github.com/eea/volto-cca-policy/commit/c0353d8a8016d5c51a0fc6d546f5487080ae253c)]
34
+ - Refs #260715 - requested updates [Tripon Eugen - [`a561804`](https://github.com/eea/volto-cca-policy/commit/a561804bfe548678ae7b497f6d0f645ce0ca928b)]
35
+ - test: fix duplications [kreafox - [`bdea7b7`](https://github.com/eea/volto-cca-policy/commit/bdea7b7fbe01a1f7e591c39010ae8c03b7bbcbe2)]
36
+ - test: increase code coverage [kreafox - [`794d1aa`](https://github.com/eea/volto-cca-policy/commit/794d1aafe7c5577aae089cd781dc997e015ea3a2)]
37
+ - Refs #260715 - filter getContent response to get only folders and test [Tripon Eugen - [`cc967d7`](https://github.com/eea/volto-cca-policy/commit/cc967d7c540d9725993ffe0f227f31ef1bd5a317)]
38
+ - Refs #260715 - filter getContent response to get only folders [Tripon Eugen - [`80b5866`](https://github.com/eea/volto-cca-policy/commit/80b58661648f9caf13b28dab8382d4058d070bd5)]
7
39
  ### [0.1.53](https://github.com/eea/volto-cca-policy/compare/0.1.52...0.1.53) - 19 December 2023
8
40
 
9
41
  #### :hammer_and_wrench: Others
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-cca-policy",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "description": "@eeacms/volto-cca-policy: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -32,7 +32,11 @@ export function ContextNavigationComponent(props) {
32
32
  activeMenu={activeMenu}
33
33
  />
34
34
  {items.length ? (
35
- <RASTAccordion items={items} activeMenu={activeMenu} />
35
+ <RASTAccordion
36
+ items={items}
37
+ curent_location={curent_location}
38
+ activeMenu={activeMenu}
39
+ />
36
40
  ) : null}
37
41
  </>
38
42
  );
@@ -1,33 +1,22 @@
1
1
  import React from 'react';
2
2
  import { Accordion, Icon } from 'semantic-ui-react';
3
3
  import RASTAccordionContent from './RASTAccordionContent';
4
+ import { useHistory } from 'react-router-dom';
4
5
 
5
6
  const RASTAccordion = (props) => {
6
- const { items = {}, activeMenu } = props;
7
+ const { items = {}, curent_location, activeMenu } = props;
7
8
 
8
- const [activeIndex, setActiveIndex] = React.useState([activeMenu]);
9
+ const history = useHistory();
9
10
 
10
- const handleActiveIndex = (index) => {
11
- setActiveIndex(index);
12
- };
13
- const handleClick = (e, titleProps) => {
14
- const { index } = titleProps;
15
-
16
- const newIndex =
17
- activeIndex.indexOf(index) === -1
18
- ? [...activeIndex, index]
19
- : activeIndex.filter((item) => item !== index);
20
-
21
- handleActiveIndex(newIndex);
22
- };
23
- const isActive = (id) => {
24
- return activeIndex.includes(id);
11
+ const handleClick = (e, item) => {
12
+ let itemUrl = '/' + item['@id'].split('/').slice(3).join('/');
13
+ history.push(itemUrl);
25
14
  };
26
15
  return (
27
16
  <>
28
17
  {items.map((item, index) => {
29
18
  const { id } = item;
30
- const active = isActive(index);
19
+ const active = activeMenu === index;
31
20
 
32
21
  return (
33
22
  <Accordion id={id} key={index} className="secondary">
@@ -37,7 +26,7 @@ const RASTAccordion = (props) => {
37
26
  active={active}
38
27
  aria-expanded={active}
39
28
  index={index}
40
- onClick={(e) => handleClick(e, { index, id, item })}
29
+ onClick={(e) => handleClick(e, item)}
41
30
  onKeyDown={(e) => {
42
31
  if (e.keyCode === 13 || e.keyCode === 32) {
43
32
  e.preventDefault();
@@ -54,6 +43,7 @@ const RASTAccordion = (props) => {
54
43
  </Accordion.Title>
55
44
  <Accordion.Content active={active}>
56
45
  <RASTAccordionContent
46
+ curent_location={curent_location}
57
47
  key={index}
58
48
  main={{
59
49
  title: item.title,
@@ -16,10 +16,12 @@ describe('RASTAccordion', () => {
16
16
  id: 'my-item',
17
17
  title: 'Hello',
18
18
  '@id': '/my-item',
19
+ '@type': 'Folder',
19
20
  href: '/my-item-href',
20
21
  },
21
22
  ],
22
23
  activeMenu: 1,
24
+ curent_location: '/',
23
25
  };
24
26
 
25
27
  const store = mockStore({
@@ -8,7 +8,7 @@ import { getContent } from '@plone/volto/actions';
8
8
  // import useChildren from './RASTView';
9
9
 
10
10
  const RASTAccordionContent = (props) => {
11
- const { main } = props;
11
+ const { main, curent_location } = props;
12
12
  const dispatch = useDispatch();
13
13
  const location = main.url;
14
14
  let items = [];
@@ -22,31 +22,30 @@ const RASTAccordionContent = (props) => {
22
22
  (state) => state.content?.subrequests?.[location]?.data?.items || [],
23
23
  );
24
24
  // const items = useChildren(location);
25
-
26
25
  return (
27
26
  <div className="dataset-content">
28
27
  <div>
29
- <List.Item key={'0'}>
30
- <List.Content>
31
- <div className="dataset-item">
32
- <Link to={flattenToAppURL(getBaseUrl(main.href))}>
33
- {main.title}
34
- </Link>
35
- </div>
36
- </List.Content>
37
- </List.Item>
38
28
  {items.length
39
- ? items.map((item) => (
40
- <List.Item key={item.id}>
41
- <List.Content>
42
- <div className="dataset-item">
43
- <Link to={flattenToAppURL(getBaseUrl(item['@id']))}>
44
- {item.title}
45
- </Link>
46
- </div>
47
- </List.Content>
48
- </List.Item>
49
- ))
29
+ ? items
30
+ .filter((item) => item['@type'] === 'Folder')
31
+ .map((item) => (
32
+ <List.Item
33
+ key={item.id}
34
+ className={`${
35
+ item['@id'].endsWith(curent_location.pathname)
36
+ ? 'active'
37
+ : ''
38
+ }`}
39
+ >
40
+ <List.Content>
41
+ <div className="dataset-item">
42
+ <Link to={flattenToAppURL(getBaseUrl(item['@id']))}>
43
+ {item.title}
44
+ </Link>
45
+ </div>
46
+ </List.Content>
47
+ </List.Item>
48
+ ))
50
49
  : null}
51
50
  </div>
52
51
  </div>
@@ -13,3 +13,7 @@
13
13
  .circle:hover {
14
14
  fill: @green-1;
15
15
  }
16
+
17
+ .rast-block .item.active a {
18
+ font-weight: bold;
19
+ }
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { Fragment } from 'react';
2
2
  import {
3
3
  HTMLField,
4
4
  ContentMetadata,
@@ -7,7 +7,6 @@ import {
7
7
  ShareInfo,
8
8
  } from '@eeacms/volto-cca-policy/helpers';
9
9
  import { Grid } from 'semantic-ui-react';
10
- import { Fragment } from 'react';
11
10
 
12
11
  const dataDisplay = [
13
12
  {
@@ -0,0 +1,143 @@
1
+ /**
2
+ * HtmlSlateWidget, a slate widget variant that saves its data as HTML
3
+ */
4
+
5
+ import React from 'react';
6
+ import ReactDOMServer from 'react-dom/server';
7
+ import configureStore from 'redux-mock-store';
8
+ import { MemoryRouter } from 'react-router-dom';
9
+ import { Provider, useSelector } from 'react-redux';
10
+ import { defineMessages, injectIntl } from 'react-intl';
11
+
12
+ import { FormFieldWrapper } from '@plone/volto/components';
13
+ import SlateEditor from '@plone/volto-slate/editor/SlateEditor';
14
+ import { serializeNodes } from '@plone/volto-slate/editor/render';
15
+ import { makeEditor } from '@plone/volto-slate/utils';
16
+ import deserialize from '@plone/volto-slate/editor/deserialize';
17
+
18
+ import {
19
+ createEmptyParagraph,
20
+ normalizeExternalData,
21
+ } from '@plone/volto-slate/utils';
22
+ import { ErrorBoundary } from '@plone/volto-slate/widgets/ErrorBoundary';
23
+
24
+ import '@plone/volto-slate/widgets/style.css';
25
+
26
+ const messages = defineMessages({
27
+ error: {
28
+ id:
29
+ 'An error has occurred while editing "{name}" field. We have been notified and we are looking into it. Please save your work and retry. If the issue persists please contact the site administrator.',
30
+ defaultMessage:
31
+ 'An error has occurred while editing "{name}" field. We have been notified and we are looking into it. Please save your work and retry. If the issue persists please contact the site administrator.',
32
+ },
33
+ });
34
+
35
+ const HtmlSlateWidget = (props) => {
36
+ const {
37
+ id,
38
+ onChange,
39
+ value,
40
+ focus,
41
+ className,
42
+ block,
43
+ placeholder,
44
+ properties,
45
+ intl,
46
+ } = props;
47
+
48
+ const [selected, setSelected] = React.useState(focus);
49
+
50
+ const editor = React.useMemo(() => makeEditor(), []);
51
+
52
+ const token = useSelector((state) => state.userSession.token);
53
+
54
+ const toHtml = React.useCallback(
55
+ (value) => {
56
+ const mockStore = configureStore();
57
+ const html = ReactDOMServer.renderToStaticMarkup(
58
+ <Provider store={mockStore({ userSession: { token } })}>
59
+ <MemoryRouter>{serializeNodes(value || [])}</MemoryRouter>
60
+ </Provider>,
61
+ );
62
+ // console.log('toHtml value', JSON.stringify(value));
63
+ // console.log('toHtml html', html);
64
+
65
+ return {
66
+ 'content-type': value ? value['content-type'] : 'text/html',
67
+ encoding: value ? value.encoding : 'utf8',
68
+ data: html,
69
+ };
70
+ },
71
+ [token],
72
+ );
73
+
74
+ const fromHtml = React.useCallback(
75
+ (value) => {
76
+ const html = value?.data || '';
77
+
78
+ const parsed = new DOMParser().parseFromString(html, 'text/html');
79
+ const body =
80
+ parsed.getElementsByTagName('google-sheets-html-origin').length > 0
81
+ ? parsed.querySelector('google-sheets-html-origin > table')
82
+ : parsed.body;
83
+ let data = deserialize(editor, body, { collapseWhitespace: false });
84
+ if (data.length) {
85
+ data = normalizeExternalData(editor, data);
86
+ } else {
87
+ return [createEmptyParagraph()];
88
+ }
89
+
90
+ // editor.children = data;
91
+ // Editor.normalize(editor);
92
+ // TODO: need to add {text: ""} placeholders between elements
93
+ const res = data.length ? data : [createEmptyParagraph()];
94
+ // console.log('from html', { html: value?.data, res });
95
+ return res;
96
+ },
97
+ [editor],
98
+ );
99
+
100
+ const valueFromHtml = React.useMemo(() => {
101
+ return fromHtml(value);
102
+ }, [value, fromHtml]);
103
+
104
+ const handleChange = React.useCallback(
105
+ (newValue) => {
106
+ onChange(id, toHtml(newValue));
107
+ },
108
+ [onChange, toHtml, id],
109
+ );
110
+
111
+ const handleClick = React.useCallback(() => {
112
+ setSelected(true);
113
+ }, []);
114
+
115
+ return (
116
+ <FormFieldWrapper {...props} draggable={false} className="slate_wysiwyg">
117
+ <div
118
+ className="slate_wysiwyg_box"
119
+ role="textbox"
120
+ tabIndex="-1"
121
+ style={{ boxSizing: 'initial' }}
122
+ onClick={handleClick}
123
+ onKeyDown={() => {}}
124
+ >
125
+ <ErrorBoundary name={intl.formatMessage(messages.error, { name: id })}>
126
+ <SlateEditor
127
+ className={className}
128
+ id={id}
129
+ name={id}
130
+ value={valueFromHtml}
131
+ onChange={handleChange}
132
+ block={block}
133
+ selected={selected}
134
+ properties={properties}
135
+ placeholder={placeholder}
136
+ />
137
+ </ErrorBoundary>
138
+ </div>
139
+ </FormFieldWrapper>
140
+ );
141
+ };
142
+
143
+ export default injectIntl(HtmlSlateWidget);
@@ -0,0 +1,9 @@
1
+ Customized for this
2
+
3
+ ```
4
+ if (data.length) {
5
+ data = normalizeExternalData(editor, data);
6
+ } else {
7
+ return [createEmptyParagraph()];
8
+ }
9
+ ```
@@ -1,19 +1,9 @@
1
1
  import { mergeConfig } from '@eeacms/search';
2
2
  import { build_runtime_mappings } from '@eeacms/volto-globalsearch/utils';
3
+ import { getClientProxyAddress } from './utils';
3
4
 
4
5
  import facets from './facets';
5
6
 
6
- // import views from './views';
7
- // import filters from './filters';
8
- // import vocabs from './vocabulary';
9
-
10
- const getClientProxyAddress = () => {
11
- const url = new URL(window.location);
12
- url.pathname = '';
13
- url.search = '';
14
- return url.toString();
15
- };
16
-
17
7
  const ccaConfig = {
18
8
  title: 'ClimateAdapt Main',
19
9
  };
@@ -186,7 +176,5 @@ export default function installMainSearch(config) {
186
176
  process.env.RAZZLE_ES_PROXY_ADDR || getClientProxyAddress();
187
177
  }
188
178
 
189
- // console.log(config.searchui.ccaSearch);
190
-
191
179
  return config;
192
180
  }
@@ -1,19 +1,10 @@
1
1
  import { mergeConfig } from '@eeacms/search';
2
2
  import { build_runtime_mappings } from '@eeacms/volto-globalsearch/utils';
3
+ import { getClientProxyAddress } from './../utils';
3
4
 
4
5
  import facets from './facets-health';
5
6
  import views from './views-health';
6
7
 
7
- // import filters from './filters';
8
- // import vocabs from './vocabulary';
9
-
10
- const getClientProxyAddress = () => {
11
- const url = new URL(window.location);
12
- url.pathname = '';
13
- url.search = '';
14
- return url.toString();
15
- };
16
-
17
8
  const ccaConfig = {
18
9
  title: 'ClimateAdapt Health',
19
10
  ...views,
@@ -1,5 +1,5 @@
1
1
  import { booleanFacet } from '@eeacms/search';
2
- import { getTodayWithTime } from './utils';
2
+ import { getTodayWithTime } from './../utils';
3
3
 
4
4
  const special = [
5
5
  {
@@ -1,30 +1,21 @@
1
1
  import installMainSearch from './config';
2
- import installHealthSearch from './config-health';
3
- import installMissionStoriesSearch from './config-mission-stories';
4
-
5
- // import DatahubCardItem from './components/Result/DatahubCardItem';
6
- // import DatahubItemView from './components/ItemView/ItemView';
7
- //
8
- // import { DatahubResultModel } from './config/models';
9
- //
10
- // import { datahub_results } from './store';
11
-
12
- // function tweakForNLPService(body, config) {
13
- // if (!config.enableNLP) {
14
- // delete body.source;
15
- // delete body.index;
16
- // return body;
17
- // }
18
- // return body;
19
- // }
2
+ import installHealthSearch from './health_observatory/config-health';
3
+ import installMissionStoriesSearch from './mission_stories/config-stories';
4
+ import installMissionProjectsSearch from './mission_projects/config-projects';
20
5
 
21
6
  const applyConfig = (config) => {
22
7
  config.settings.searchlib = installHealthSearch(
23
8
  installMainSearch(config.settings.searchlib),
24
9
  );
10
+
25
11
  config.settings.searchlib = installMissionStoriesSearch(
26
12
  config.settings.searchlib,
27
13
  );
14
+
15
+ config.settings.searchlib = installMissionProjectsSearch(
16
+ installMainSearch(config.settings.searchlib),
17
+ );
18
+
28
19
  return config;
29
20
  };
30
21
 
@@ -0,0 +1,69 @@
1
+ import { mergeConfig } from '@eeacms/search';
2
+ import { build_runtime_mappings } from '@eeacms/volto-globalsearch/utils';
3
+ import { getClientProxyAddress } from './../utils';
4
+
5
+ import facets from './facets-projects';
6
+
7
+ const missionProjectsConfig = {
8
+ title: 'Mission Projects',
9
+ };
10
+
11
+ export const clusters = {
12
+ name: 'op_cluster',
13
+ field: 'objectProvides',
14
+ clusters: [
15
+ // {
16
+ // name: 'Type1',
17
+ // icon: { name: 'bullhorn' },
18
+ // values: ['Video', 'Guidance'],
19
+ // defaultResultView: 'horizontalCard',
20
+ // },
21
+ ],
22
+ };
23
+
24
+ export default function installMainSearch(config) {
25
+ const envConfig = process.env.RAZZLE_ENV_CONFIG
26
+ ? JSON.parse(process.env.RAZZLE_ENV_CONFIG)
27
+ : missionProjectsConfig;
28
+
29
+ const pjson = require('@eeacms/volto-cca-policy/../package.json');
30
+
31
+ envConfig.app_name = pjson.name;
32
+ envConfig.app_version = pjson.version;
33
+
34
+ config.searchui.missionProjects = {
35
+ ...mergeConfig(envConfig, config.searchui.globalsearchbase),
36
+ elastic_index: '_es/globalsearch',
37
+ index_name: 'data_searchui',
38
+ host: process.env.RAZZLE_ES_PROXY_ADDR || 'http://localhost:3000',
39
+ vocab: {
40
+ cluster_name: {
41
+ cca: 'Climate-ADAPT',
42
+ },
43
+ },
44
+ runtime_mappings: build_runtime_mappings(clusters),
45
+ };
46
+
47
+ const { missionProjects } = config.searchui;
48
+
49
+ missionProjects.permanentFilters.push({
50
+ term: {
51
+ cca_include_in_mission: 'true',
52
+ },
53
+ });
54
+
55
+ missionProjects.permanentFilters.push({
56
+ terms: {
57
+ objectProvides: ['Research and knowledge project'],
58
+ },
59
+ });
60
+
61
+ missionProjects.facets = facets;
62
+
63
+ if (typeof window !== 'undefined') {
64
+ config.searchui.missionProjects.host =
65
+ process.env.RAZZLE_ES_PROXY_ADDR || getClientProxyAddress();
66
+ }
67
+
68
+ return config;
69
+ }
@@ -0,0 +1,30 @@
1
+ import { multiTermFacet } from '@eeacms/search';
2
+
3
+ import globalSearchBaseConfig from '@eeacms/volto-globalsearch/config/global-search-base-config.js';
4
+
5
+ const facets = [
6
+ ...globalSearchBaseConfig.facets,
7
+ multiTermFacet({
8
+ field: 'cca_adaptation_sectors.keyword',
9
+ isFilterable: false,
10
+ isMulti: true,
11
+ label: 'Sectors',
12
+ alwaysVisible: false,
13
+ }),
14
+ multiTermFacet({
15
+ field: 'cca_climate_impacts.keyword',
16
+ isFilterable: false,
17
+ isMulti: true,
18
+ label: 'Climate impacts',
19
+ alwaysVisible: false,
20
+ }),
21
+ multiTermFacet({
22
+ field: 'cca_adaptation_elements.keyword',
23
+ isFilterable: false,
24
+ isMulti: true,
25
+ label: 'Adaptation Elements',
26
+ alwaysVisible: false,
27
+ }),
28
+ ];
29
+
30
+ export default facets;
@@ -1,18 +1,10 @@
1
1
  import { mergeConfig } from '@eeacms/search';
2
-
3
- import facets from './facets-mission-stories';
4
-
5
- const getClientProxyAddress = () => {
6
- const url = new URL(window.location);
7
- url.pathname = '';
8
- url.search = '';
9
- return url.toString();
10
- };
2
+ import { getClientProxyAddress } from './../utils';
3
+ import facets from './facets-stories';
11
4
 
12
5
  const missionStoriesConfig = {
13
6
  title: 'Mission stories',
14
7
  ...facets,
15
- // ...views,
16
8
  };
17
9
 
18
10
  export default function installMissionStoriesSearch(config) {
@@ -27,3 +27,10 @@ export function getTodayWithTime() {
27
27
  ].join('');
28
28
  return output;
29
29
  }
30
+
31
+ export function getClientProxyAddress() {
32
+ const url = new URL(window.location);
33
+ url.pathname = '';
34
+ url.search = '';
35
+ return url.toString();
36
+ }
@@ -0,0 +1,11 @@
1
+ import { getTodayWithTime } from './utils';
2
+ import '@testing-library/jest-dom/extend-expect';
3
+
4
+ describe('getTodayWithTime', () => {
5
+ it('should return the current date in UTC format', () => {
6
+ const output = getTodayWithTime();
7
+
8
+ expect(typeof output).toBe('string');
9
+ expect(output).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/);
10
+ });
11
+ });