@eeacms/volto-bise-policy 1.2.32 → 1.2.34

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/package.json +3 -1
  3. package/src/components/Widgets/GeolocationWidget.jsx +143 -0
  4. package/src/components/Widgets/GeolocationWidgetMapContainer.jsx +131 -0
  5. package/src/components/Widgets/NRRWidgets.jsx +95 -0
  6. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyExplorerEdit.jsx +5 -0
  7. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyExplorerView.jsx +107 -0
  8. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyExplorerView.test.jsx +89 -0
  9. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyFilters.jsx +339 -0
  10. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyFilters.test.jsx +111 -0
  11. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyListing.jsx +330 -0
  12. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyListing.test.jsx +166 -0
  13. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyMap.jsx +237 -0
  14. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyMap.test.jsx +176 -0
  15. package/src/components/manage/Blocks/CaseStudyExplorer/FeatureDisplay.jsx +41 -0
  16. package/src/components/manage/Blocks/CaseStudyExplorer/FeatureDisplay.test.jsx +32 -0
  17. package/src/components/manage/Blocks/CaseStudyExplorer/FeatureInteraction.jsx +98 -0
  18. package/src/components/manage/Blocks/CaseStudyExplorer/FeatureInteraction.test.jsx +160 -0
  19. package/src/components/manage/Blocks/CaseStudyExplorer/InfoOverlay.jsx +82 -0
  20. package/src/components/manage/Blocks/CaseStudyExplorer/InfoOverlay.test.jsx +153 -0
  21. package/src/components/manage/Blocks/CaseStudyExplorer/hooks.js +20 -0
  22. package/src/components/manage/Blocks/CaseStudyExplorer/images/icon-depth.png +0 -0
  23. package/src/components/manage/Blocks/CaseStudyExplorer/images/icon-light.png +0 -0
  24. package/src/components/manage/Blocks/CaseStudyExplorer/images/search.svg +3 -0
  25. package/src/components/manage/Blocks/CaseStudyExplorer/index.js +16 -0
  26. package/src/components/manage/Blocks/CaseStudyExplorer/mockJsdom.js +8 -0
  27. package/src/components/manage/Blocks/CaseStudyExplorer/styles.less +359 -0
  28. package/src/components/manage/Blocks/CaseStudyExplorer/styles.less_old +201 -0
  29. package/src/components/manage/Blocks/CaseStudyExplorer/utils.js +144 -0
  30. package/src/components/manage/Blocks/CaseStudyExplorer/utils.test.js +88 -0
  31. package/src/components/manage/Blocks/index.js +2 -0
  32. package/src/express-middleware.js +37 -0
  33. package/src/index.js +29 -0
  34. package/theme/globals/site.overrides +12 -4
@@ -0,0 +1,339 @@
1
+ import React from 'react';
2
+
3
+ import { centerAndResetMapZoom, scrollToElement } from './utils';
4
+ import { withOpenLayers } from '@eeacms/volto-openlayers-map';
5
+
6
+ const normalizeSearchInput = (searchInput) => {
7
+ let normInput = searchInput
8
+ .toLowerCase()
9
+ .replace('(', '')
10
+ .replace(')', '')
11
+ .replace('?', '.')
12
+ .replace('*', '[^\\s]+');
13
+
14
+ return '\\b' + normInput + '\\b';
15
+ };
16
+
17
+ export function CaseStudyFilter(props) {
18
+ const {
19
+ filterTitle,
20
+ filters,
21
+ activeFilters,
22
+ setActiveFilters,
23
+ filterName,
24
+ map,
25
+ ol,
26
+ } = props;
27
+
28
+ const showInputs = (event) => {
29
+ event.currentTarget.parentElement.classList.add('active');
30
+ };
31
+
32
+ return (
33
+ <div className="filter-wrapper">
34
+ <button
35
+ className="ui basic button facet-btn"
36
+ onClick={(e) => showInputs(e)}
37
+ >
38
+ <span>
39
+ {filterTitle}
40
+ <i aria-hidden="true" className="icon angle down"></i>
41
+ </span>
42
+ </button>
43
+ <div className="filter-inputs-wrapper">
44
+ {Object.entries(filters?.[filterName] || {}).length > 7 ? (
45
+ <input
46
+ type="text"
47
+ className="filterInputText"
48
+ onKeyUp={(e) => {
49
+ const filterValue = e.currentTarget.value.toUpperCase();
50
+ const inputs = e.currentTarget.nextSibling.children;
51
+
52
+ for (let i = 0; i < inputs.length; i++) {
53
+ let inputValue = inputs[i].textContent || inputs[i].innerText;
54
+ if (inputValue.toUpperCase().indexOf(filterValue) > -1) {
55
+ inputs[i].style.display = 'block';
56
+ } else {
57
+ inputs[i].style.display = 'none';
58
+ }
59
+ }
60
+ }}
61
+ placeholder="Quick search"
62
+ title="Type in a name"
63
+ />
64
+ ) : (
65
+ ''
66
+ )}
67
+
68
+ <div className="filter-inputs">
69
+ {Object.entries(filters?.[filterName] || {})
70
+ .sort((item1, item2) => item1[1].localeCompare(item2[1]))
71
+ .map(([value, label], index) => (
72
+ <label
73
+ htmlFor={label + index}
74
+ className="filter-input"
75
+ key={index}
76
+ >
77
+ <input
78
+ value={value}
79
+ type="checkbox"
80
+ id={label + index}
81
+ onChange={(e) => {
82
+ const temp = JSON.parse(JSON.stringify(activeFilters));
83
+ if (e.target.checked) {
84
+ temp[filterName].push(e.target.value);
85
+ } else {
86
+ temp[filterName] = temp[filterName].filter((value) => {
87
+ if (value !== e.target.value) return value;
88
+ return null;
89
+ });
90
+ }
91
+ setActiveFilters(temp);
92
+ scrollToElement('search-input');
93
+ centerAndResetMapZoom({ map, ol });
94
+ }}
95
+ />
96
+ <span>{label}</span>
97
+ </label>
98
+ ))}
99
+ </div>
100
+ </div>
101
+ </div>
102
+ );
103
+ }
104
+
105
+ function CaseStudyFiltersComponent(props) {
106
+ const { filters, activeFilters, setActiveFilters, map, ol } = props;
107
+
108
+ React.useEffect(() => {
109
+ window.addEventListener('click', (event) => {
110
+ const filters = document.getElementsByClassName('filter-wrapper');
111
+
112
+ for (let i = 0; i < filters.length; i++) {
113
+ if (!filters[i].contains(event.target)) {
114
+ filters[i].classList.remove('active');
115
+ }
116
+ }
117
+ });
118
+ }, []);
119
+
120
+ return (
121
+ <>
122
+ <CaseStudyFilter
123
+ filterTitle="Measures"
124
+ filterName="measures_implemented"
125
+ filters={filters}
126
+ activeFilters={activeFilters}
127
+ setActiveFilters={setActiveFilters}
128
+ map={map}
129
+ ol={ol}
130
+ />
131
+
132
+ <CaseStudyFilter
133
+ filterTitle="Typology of measure"
134
+ filterName="typology_of_measures"
135
+ filters={filters}
136
+ activeFilters={activeFilters}
137
+ setActiveFilters={setActiveFilters}
138
+ map={map}
139
+ ol={ol}
140
+ />
141
+ </>
142
+ );
143
+ }
144
+
145
+ function SearchBoxComponent(props) {
146
+ const { setSearchInput, map, ol } = props;
147
+ const [showClearButton, setShowClearButton] = React.useState(false);
148
+
149
+ return (
150
+ <div className="header-content">
151
+ <div className="sui-search-box">
152
+ <div className="search-input">
153
+ <div className="terms-box">
154
+ <input
155
+ id="search-input"
156
+ placeholder="Search with a keyword..."
157
+ onChange={(event) => {
158
+ const _showClearButton = event.target.value ? true : false;
159
+ setShowClearButton(_showClearButton);
160
+ }}
161
+ onKeyDown={(event) => {
162
+ if (event.code !== 'Enter') {
163
+ return;
164
+ }
165
+ let searchInput = normalizeSearchInput(event.target.value);
166
+
167
+ setSearchInput(searchInput);
168
+ scrollToElement('search-input');
169
+ centerAndResetMapZoom({ map, ol });
170
+ }}
171
+ ></input>
172
+ <div className="terms-box-left">
173
+ <div className="input-controls">
174
+ {showClearButton ? (
175
+ <div className="ui button basic clear-button">
176
+ <i
177
+ aria-hidden="true"
178
+ className="close icon"
179
+ role="button"
180
+ onClick={() => {
181
+ const searchInputElement =
182
+ document.getElementById('search-input');
183
+ searchInputElement.value = '';
184
+ setSearchInput('');
185
+ setShowClearButton(false);
186
+ scrollToElement('search-input');
187
+ centerAndResetMapZoom({ map, ol });
188
+ }}
189
+ ></i>
190
+ </div>
191
+ ) : (
192
+ ''
193
+ )}
194
+ </div>
195
+ <div
196
+ className="search-icon"
197
+ role="button"
198
+ onClick={() => {
199
+ const searchInputElement =
200
+ document.getElementById('search-input');
201
+ const searchInputVal = normalizeSearchInput(
202
+ searchInputElement.value,
203
+ );
204
+
205
+ setSearchInput(searchInputVal);
206
+ scrollToElement('search-input');
207
+ centerAndResetMapZoom({ map, ol });
208
+ }}
209
+ onKeyDown={() => {}}
210
+ tabIndex="0"
211
+ >
212
+ <svg viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg">
213
+ <path d="M37.3757 34.3789L30.2003 27.2246C32.5154 24.2751 33.7716 20.633 33.7669 16.8835C33.7669 13.5442 32.7767 10.28 30.9215 7.50351C29.0663 4.72705 26.4295 2.56305 23.3445 1.28518C20.2594 0.00731515 16.8647 -0.327033 13.5897 0.324418C10.3146 0.97587 7.30625 2.58386 4.94506 4.94506C2.58386 7.30625 0.97587 10.3146 0.324418 13.5897C-0.327033 16.8647 0.00731528 20.2594 1.28518 23.3445C2.56305 26.4295 4.72705 29.0664 7.50351 30.9215C10.28 32.7767 13.5442 33.7669 16.8835 33.7669C20.633 33.7716 24.2751 32.5154 27.2246 30.2003L34.3789 37.3757C34.5751 37.5735 34.8085 37.7306 35.0657 37.8377C35.3229 37.9448 35.5987 38 35.8773 38C36.1559 38 36.4318 37.9448 36.689 37.8377C36.9461 37.7306 37.1795 37.5735 37.3757 37.3757C37.5735 37.1795 37.7305 36.9461 37.8377 36.689C37.9448 36.4318 38 36.1559 38 35.8773C38 35.5987 37.9448 35.3229 37.8377 35.0657C37.7305 34.8085 37.5735 34.5751 37.3757 34.3789ZM4.22087 16.8835C4.22087 14.379 4.96352 11.9309 6.3549 9.8485C7.74628 7.76615 9.72391 6.14315 12.0377 5.18475C14.3515 4.22635 16.8975 3.97559 19.3538 4.46418C21.8101 4.95277 24.0664 6.15876 25.8373 7.92966C27.6081 9.70055 28.8141 11.9568 29.3027 14.4131C29.7913 16.8694 29.5406 19.4154 28.5822 21.7292C27.6238 24.043 26.0008 26.0206 23.9184 27.412C21.8361 28.8034 19.3879 29.546 16.8835 29.546C13.5251 29.546 10.3043 28.2119 7.92966 25.8373C5.55496 23.4626 4.22087 20.2418 4.22087 16.8835Z" />
214
+ </svg>
215
+ </div>
216
+ </div>
217
+ </div>
218
+ </div>
219
+ </div>
220
+ </div>
221
+ );
222
+ }
223
+
224
+ function ActiveFiltersComponent(props) {
225
+ const { filters, activeFilters, setActiveFilters } = props;
226
+ const hasActiveFilters = Object.entries(activeFilters).some(
227
+ ([filterName, filterList]) => {
228
+ if (filterList.length > 0) {
229
+ return true;
230
+ }
231
+ return false;
232
+ },
233
+ );
234
+
235
+ const clearFilters = () => {
236
+ const filterInputs = document.querySelectorAll(
237
+ '#cse-filter .filter-input input',
238
+ );
239
+ for (let i = 0; i < filterInputs.length; i++) {
240
+ filterInputs[i].checked = false;
241
+ }
242
+ setActiveFilters({ measures_implemented: [], typology_of_measures: [] });
243
+ scrollToElement('search-input');
244
+ };
245
+
246
+ const removeFilter = (filterName, filterCode) => {
247
+ const temp = JSON.parse(JSON.stringify(activeFilters));
248
+ temp[filterName] = temp[filterName].filter((value) => {
249
+ if (value !== filterCode) return value;
250
+ return null;
251
+ });
252
+
253
+ const filterInputs = document.querySelectorAll(
254
+ '#cse-filter .filter-input input',
255
+ );
256
+
257
+ for (let i = 0; i < filterInputs.length; i++) {
258
+ if (filterInputs[i].value === filterCode) {
259
+ filterInputs[i].checked = false;
260
+ }
261
+ }
262
+
263
+ setActiveFilters(temp);
264
+ };
265
+
266
+ return hasActiveFilters ? (
267
+ <div className="ui segment active-filter-list">
268
+ <div className="filter-list-header">
269
+ <h4 className="filter-list-title">Active filters</h4>
270
+ <button
271
+ onClick={clearFilters}
272
+ className="ui mini basic compact button clear-btn"
273
+ >
274
+ clear all
275
+ </button>
276
+ </div>
277
+ <div className="filter-list-content">
278
+ <div className="filter">
279
+ {activeFilters.measures_implemented.length > 0 ? (
280
+ <div className="filter-wrapper">
281
+ <div className="filter-label">Measures implemented:</div>
282
+ {activeFilters.measures_implemented.map((filterCode) => {
283
+ const filterLabel = filters.measures_implemented[filterCode];
284
+ return (
285
+ <div className="ui basic label filter-value">
286
+ <span>{filterLabel}</span>
287
+ <i
288
+ tabIndex="0"
289
+ onKeyPress={() => {}}
290
+ onClick={() => {
291
+ removeFilter('measures_implemented', filterCode);
292
+ scrollToElement('search-input');
293
+ }}
294
+ role="button"
295
+ className="close icon"
296
+ ></i>
297
+ </div>
298
+ );
299
+ })}
300
+ </div>
301
+ ) : (
302
+ ''
303
+ )}
304
+ {activeFilters.typology_of_measures.length > 0 ? (
305
+ <div className="filter-wrapper">
306
+ <div className="filter-label">Typology of measures:</div>
307
+ {activeFilters.typology_of_measures.map((filterCode) => {
308
+ const filterLabel = filters.typology_of_measures[filterCode];
309
+ return (
310
+ <div className="ui basic label filter-value">
311
+ <span>{filterLabel}</span>
312
+ <i
313
+ tabIndex="0"
314
+ onKeyPress={() => {}}
315
+ onClick={() => {
316
+ removeFilter('typology_of_measures', filterCode);
317
+ scrollToElement('search-input');
318
+ }}
319
+ role="button"
320
+ className="close icon"
321
+ ></i>
322
+ </div>
323
+ );
324
+ })}
325
+ </div>
326
+ ) : (
327
+ ''
328
+ )}
329
+ </div>
330
+ </div>
331
+ </div>
332
+ ) : (
333
+ ''
334
+ );
335
+ }
336
+
337
+ export const CaseStudyFilters = withOpenLayers(CaseStudyFiltersComponent);
338
+ export const SearchBox = withOpenLayers(SearchBoxComponent);
339
+ export const ActiveFilters = withOpenLayers(ActiveFiltersComponent);
@@ -0,0 +1,111 @@
1
+ import './mockJsdom';
2
+ import React from 'react';
3
+ import '@testing-library/jest-dom/extend-expect';
4
+ import { render } from '@testing-library/react';
5
+
6
+ import {
7
+ CaseStudyFilters,
8
+ ActiveFilters,
9
+ SearchBox,
10
+ CaseStudyFilter,
11
+ } from './CaseStudyFilters';
12
+
13
+ jest.mock('@eeacms/volto-openlayers-map', () => ({
14
+ openlayers: {
15
+ proj: {
16
+ transform: jest.fn().mockReturnValue([0, 0]),
17
+ },
18
+ },
19
+ withOpenLayers: (Component) => (props) => (
20
+ <Component
21
+ {...props}
22
+ ol={{
23
+ proj: {
24
+ transform: jest.fn().mockReturnValue([0, 0]),
25
+ },
26
+ }}
27
+ />
28
+ ),
29
+ }));
30
+
31
+ describe('CaseStudyFilters', () => {
32
+ const mockSetActiveFilters = jest.fn();
33
+ window.URL.createObjectURL = function () {};
34
+ global.URL.createObjectURL = jest.fn();
35
+
36
+ const mockFilters = {
37
+ typology_of_measures: { sector1: 'Sector 1', sector2: 'Sector 2' },
38
+ };
39
+
40
+ it('renders without crashing', () => {
41
+ const { container } = render(
42
+ <CaseStudyFilters
43
+ filters={mockFilters}
44
+ activeFilters={{ typology_of_measures: [] }}
45
+ setActiveFilters={mockSetActiveFilters}
46
+ />,
47
+ );
48
+
49
+ // CaseStudyFilters component returns empty content (commented out filters)
50
+ // Just verify it renders without error
51
+ expect(container).toBeTruthy();
52
+ });
53
+ });
54
+
55
+ describe('ActiveFilters', () => {
56
+ const mockSetActiveFilters = jest.fn();
57
+ const mockFilters = {
58
+ typology_of_measures: { sector1: 'Sector 1', sector2: 'Sector 2' },
59
+ };
60
+
61
+ it('renders without crashing', () => {
62
+ render(
63
+ <ActiveFilters
64
+ filters={mockFilters}
65
+ activeFilters={{ typology_of_measures: [] }}
66
+ setActiveFilters={mockSetActiveFilters}
67
+ />,
68
+ );
69
+ });
70
+ });
71
+
72
+ describe('SearchBox', () => {
73
+ const mockSetActiveFilters = jest.fn();
74
+ const mockFilters = {
75
+ typology_of_measures: { sector1: 'Sector 1', sector2: 'Sector 2' },
76
+ };
77
+
78
+ const mockSetSearchInput = jest.fn();
79
+ const mockSearchInput = 'bise';
80
+
81
+ it('renders without crashing', () => {
82
+ render(
83
+ <SearchBox
84
+ filters={mockFilters}
85
+ activeFilters={{ typology_of_measures: [] }}
86
+ setActiveFilters={mockSetActiveFilters}
87
+ searchInput={mockSearchInput}
88
+ setSearchInput={mockSetSearchInput}
89
+ />,
90
+ );
91
+ });
92
+ });
93
+
94
+ describe('CaseStudyFilter', () => {
95
+ const mockSetActiveFilters = jest.fn();
96
+ const mockFilters = {
97
+ typology_of_measures: { sector1: 'Sector 1', sector2: 'Sector 2' },
98
+ };
99
+
100
+ it('renders without crashing', () => {
101
+ render(
102
+ <CaseStudyFilter
103
+ filterTitle={'Case study filter'}
104
+ filters={mockFilters}
105
+ activeFilters={{ typology_of_measures: [] }}
106
+ setActiveFilters={mockSetActiveFilters}
107
+ filterName={'Filter name'}
108
+ />,
109
+ );
110
+ });
111
+ });