@eeacms/volto-clms-theme 1.1.288 → 1.1.290

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,42 +1,17 @@
1
1
  import React, { useState } from 'react';
2
2
  import { compose } from 'redux';
3
- import { useSelector, useDispatch } from 'react-redux';
4
3
  import VisibilitySensor from 'react-visibility-sensor';
5
- import {
6
- Placeholder,
7
- Dimmer,
8
- Loader,
9
- Button,
10
- Checkbox,
11
- } from 'semantic-ui-react';
4
+ import { Placeholder, Button, Checkbox } from 'semantic-ui-react';
12
5
  import { withCookies } from 'react-cookie';
13
6
  import { serializeNodes } from '@plone/volto-slate/editor/render';
14
- import { defineMessages, injectIntl } from 'react-intl';
15
- import { toast } from 'react-toastify';
7
+ import { injectIntl } from 'react-intl';
16
8
  import config from '@plone/volto/registry';
17
- import { getBaseUrl } from '@plone/volto/helpers';
18
- import { Toast } from '@plone/volto/components';
19
- import {
20
- getConnectedDataParametersForContext,
21
- getFilteredURL,
22
- } from '@eeacms/volto-datablocks/helpers';
23
9
 
24
10
  import { createImageUrl } from '@eeacms/volto-embed/PrivacyProtection/helpers';
25
11
  import { ProtectionSchema } from '@eeacms/volto-embed/PrivacyProtection/schema';
26
12
 
27
13
  import '@eeacms/volto-embed/PrivacyProtection/styles.less';
28
14
 
29
- const messages = defineMessages({
30
- success: {
31
- id: 'Success',
32
- defaultMessage: 'Success',
33
- },
34
- image: {
35
- id: 'Live image generated',
36
- defaultMessage: 'Live image generated',
37
- },
38
- });
39
-
40
15
  const key = (domain_key) => `accept-${domain_key}`;
41
16
 
42
17
  const getExpDays = () =>
@@ -76,16 +51,7 @@ const CookieWatcher = (domain_key, cookies, pollingRate = 250) => {
76
51
  };
77
52
 
78
53
  const PrivacyProtection = (props) => {
79
- const {
80
- children,
81
- data = {},
82
- id,
83
- editable,
84
- intl,
85
- path,
86
- cookies,
87
- height = '',
88
- } = props;
54
+ const { children, data = {}, id, editable, cookies, height = '' } = props;
89
55
  const {
90
56
  enabled = false,
91
57
  privacy_statement,
@@ -100,15 +66,7 @@ const PrivacyProtection = (props) => {
100
66
  const [remember, setRemember] = useState(
101
67
  cookieExist(privacy_cookie_key, cookies) ? defaultShow : true,
102
68
  );
103
- const dispatch = useDispatch();
104
69
  const checkExistance = CookieWatcher(privacy_cookie_key, cookies);
105
- const connected_data_parameters = useSelector((state) => {
106
- return getConnectedDataParametersForContext(
107
- state?.connected_data_parameters,
108
- state.router?.location?.pathname,
109
- );
110
- });
111
- const url = getFilteredURL(data.url, connected_data_parameters);
112
70
 
113
71
  React.useEffect(() => {
114
72
  if (bgImg) {
@@ -127,37 +85,6 @@ const PrivacyProtection = (props) => {
127
85
  [checkExistance],
128
86
  );
129
87
 
130
- //screenshot api
131
- React.useEffect(() => {
132
- if (enabled && !bgImg && !show && url) {
133
- fetch(
134
- `${getBaseUrl(
135
- '',
136
- )}/cors-proxy/https://screenshot.eea.europa.eu/api/v1/retrieve_image_for_url?url=${encodeURIComponent(
137
- url,
138
- )}&w=1920&waitfor=4000`,
139
- )
140
- .then((e) => e.blob())
141
- .then((blob) => {
142
- setImage(URL.createObjectURL(blob));
143
- if (editable) {
144
- toast.success(
145
- <Toast
146
- success
147
- title={intl.formatMessage(messages.success)}
148
- content={intl.formatMessage(messages.image)}
149
- />,
150
- );
151
- }
152
- })
153
- .catch(() => {
154
- if (__DEVELOPMENT__) {
155
- /* eslint-disable-next-line */
156
- console.log('Please enable your VPN!');
157
- }
158
- });
159
- }
160
- }, [enabled, url, path, dispatch, bgImg, show, intl, editable]);
161
88
  return (
162
89
  <VisibilitySensor
163
90
  onChange={(isVisible) => {
@@ -178,10 +105,6 @@ const PrivacyProtection = (props) => {
178
105
  >
179
106
  {!enabled || show ? (
180
107
  children
181
- ) : !__DEVELOPMENT__ && !image ? (
182
- <Dimmer active>
183
- <Loader />
184
- </Dimmer>
185
108
  ) : (
186
109
  <div
187
110
  className="privacy-protection"
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
 
3
3
  import ListingBody from '@plone/volto/components/manage/Blocks/Listing/ListingBody';
4
- import { withBlockExtensions } from '@plone/volto/helpers';
4
+ import { BodyClass, withBlockExtensions } from '@plone/volto/helpers';
5
5
 
6
6
  import config from '@plone/volto/registry';
7
+ import { usesGlobalSearchDesign } from '@eeacms/volto-clms-theme/components/Blocks/CustomTemplates/VoltoSearchBlock/searchDesign';
7
8
 
8
9
  import {
9
10
  withSearch,
@@ -63,7 +64,12 @@ const applyDefaults = (data, root) => {
63
64
  };
64
65
 
65
66
  const SearchBlockView = (props) => {
66
- const { data, searchData, mode = 'view', variation } = props;
67
+ const { data, searchData, mode = 'view', variation, location, path } = props;
68
+ const hasGlobalSearchDesign = usesGlobalSearchDesign({
69
+ data,
70
+ location,
71
+ path,
72
+ });
67
73
 
68
74
  const Layout = variation.view;
69
75
 
@@ -86,8 +92,17 @@ const SearchBlockView = (props) => {
86
92
  const { variations } = config.blocks.blocksConfig.listing;
87
93
  const listingBodyVariation = variations.find(({ id }) => id === selectedView);
88
94
 
89
- return (
90
- <div className="block search">
95
+ const searchBlock = (
96
+ <div
97
+ className={[
98
+ 'block search',
99
+ hasGlobalSearchDesign
100
+ ? 'global-search-block searchlib-block searchapp searchapp-clmsSearchTechnicalLibrary'
101
+ : '',
102
+ ]
103
+ .filter(Boolean)
104
+ .join(' ')}
105
+ >
91
106
  <Layout
92
107
  {...props}
93
108
  isEditMode={mode === 'edit'}
@@ -103,6 +118,14 @@ const SearchBlockView = (props) => {
103
118
  </Layout>
104
119
  </div>
105
120
  );
121
+
122
+ return hasGlobalSearchDesign ? (
123
+ <BodyClass className="global-search-page searchlib-page">
124
+ {searchBlock}
125
+ </BodyClass>
126
+ ) : (
127
+ searchBlock
128
+ );
106
129
  };
107
130
 
108
131
  export const SearchBlockViewComponent = compose(
@@ -35,6 +35,7 @@ function getInitialState(
35
35
  id,
36
36
  sortOnParam,
37
37
  sortOrderParam,
38
+ useDefaultSort = true,
38
39
  ) {
39
40
  const {
40
41
  types: facetWidgetTypes,
@@ -69,8 +70,18 @@ function getInitialState(
69
70
  ]
70
71
  : []),
71
72
  ],
72
- sort_on: sortOnParam || data.query?.sort_on,
73
- sort_order: sortOrderParam || data.query?.sort_order,
73
+ sort_on:
74
+ sortOnParam !== undefined
75
+ ? sortOnParam
76
+ : useDefaultSort
77
+ ? data.query?.sort_on
78
+ : undefined,
79
+ sort_order:
80
+ sortOrderParam !== undefined
81
+ ? sortOrderParam
82
+ : useDefaultSort
83
+ ? data.query?.sort_order
84
+ : undefined,
74
85
  b_size: data.query?.b_size,
75
86
  limit: data.query?.limit,
76
87
  block: id,
@@ -92,6 +103,7 @@ function normalizeState({
92
103
  sortOn,
93
104
  sortOrder,
94
105
  facetSettings, // data.facets extracted from block data
106
+ useDefaultSort = true,
95
107
  }) {
96
108
  const {
97
109
  types: facetWidgetTypes,
@@ -115,8 +127,18 @@ function normalizeState({
115
127
  return valueToQuery({ value, facet });
116
128
  }),
117
129
  ].filter((o) => !!o),
118
- sort_on: sortOn || query.sort_on,
119
- sort_order: sortOrder || query.sort_order,
130
+ sort_on:
131
+ sortOn !== undefined
132
+ ? sortOn
133
+ : useDefaultSort
134
+ ? query.sort_on
135
+ : undefined,
136
+ sort_order:
137
+ sortOrder !== undefined
138
+ ? sortOrder
139
+ : useDefaultSort
140
+ ? query.sort_order
141
+ : undefined,
120
142
  b_size: query.b_size,
121
143
  limit: query.limit,
122
144
  block: id,
@@ -196,6 +218,13 @@ const useHashState = () => {
196
218
  }
197
219
  });
198
220
 
221
+ SEARCH_ENDPOINT_FIELDS.forEach((k) => {
222
+ if (!searchData[k] && oldState[k]) {
223
+ delete newParams[k];
224
+ changed = true;
225
+ }
226
+ });
227
+
199
228
  if (changed) {
200
229
  history.push({
201
230
  search: qs.stringify(newParams),
@@ -240,6 +269,7 @@ const withSearch = (options) => (WrappedComponent) => {
240
269
 
241
270
  function WithSearch(props) {
242
271
  const { data, id, editable = false } = props;
272
+ const isGlobalSearch = data?.listingBodyTemplate === 'CclGlobalSearch';
243
273
 
244
274
  const [locationSearchData, setLocationSearchData] = useSearchBlockState(
245
275
  id,
@@ -323,11 +353,25 @@ const withSearch = (options) => (WrappedComponent) => {
323
353
  previousUrlQuery,
324
354
  ]);
325
355
 
326
- const [sortOn, setSortOn] = React.useState(data?.query?.sort_on);
327
- const [sortOrder, setSortOrder] = React.useState(data?.query?.sort_order);
356
+ const [sortOn, setSortOn] = React.useState(
357
+ locationSearchData.sort_on ||
358
+ (isGlobalSearch ? undefined : data?.query?.sort_on),
359
+ );
360
+ const [sortOrder, setSortOrder] = React.useState(
361
+ locationSearchData.sort_order ||
362
+ (isGlobalSearch ? undefined : data?.query?.sort_order),
363
+ );
328
364
 
329
365
  const [searchData, setSearchData] = React.useState(
330
- getInitialState(data, facets, urlSearchText, id),
366
+ getInitialState(
367
+ data,
368
+ facets,
369
+ urlSearchText,
370
+ id,
371
+ sortOn,
372
+ sortOrder,
373
+ !isGlobalSearch,
374
+ ),
331
375
  );
332
376
 
333
377
  const deepFacets = JSON.stringify(facets);
@@ -341,9 +385,18 @@ const withSearch = (options) => (WrappedComponent) => {
341
385
  id,
342
386
  sortOn,
343
387
  sortOrder,
388
+ !isGlobalSearch,
344
389
  ),
345
390
  );
346
- }, [deepData, deepFacets, urlSearchText, id, sortOn, sortOrder]);
391
+ }, [
392
+ deepData,
393
+ deepFacets,
394
+ urlSearchText,
395
+ id,
396
+ sortOn,
397
+ sortOrder,
398
+ isGlobalSearch,
399
+ ]);
347
400
 
348
401
  const timeoutRef = React.useRef();
349
402
  const facetSettings = data?.facets;
@@ -359,18 +412,32 @@ const withSearch = (options) => (WrappedComponent) => {
359
412
  if (timeoutRef.current) clearTimeout(timeoutRef.current);
360
413
  timeoutRef.current = setTimeout(
361
414
  () => {
415
+ const shouldClearSort = toSortOn === null;
416
+ const hasSortOnParam = toSortOn !== undefined;
417
+ const nextSortOn = shouldClearSort
418
+ ? undefined
419
+ : hasSortOnParam
420
+ ? toSortOn
421
+ : sortOn;
422
+ const nextSortOrder = shouldClearSort
423
+ ? undefined
424
+ : toSortOrder !== undefined
425
+ ? toSortOrder
426
+ : sortOrder;
362
427
  const newSearchData = normalizeState({
363
428
  id,
364
429
  query: data.query || {},
365
430
  facets: toSearchFacets || facets,
366
431
  searchText: toSearchText ? toSearchText.trim() : '',
367
- sortOn: toSortOn || sortOn,
368
- sortOrder: toSortOrder || sortOrder,
432
+ sortOn: nextSortOn,
433
+ sortOrder: nextSortOrder,
369
434
  facetSettings,
435
+ useDefaultSort: !isGlobalSearch,
370
436
  });
371
437
  if (toSearchFacets) setFacets(toSearchFacets);
372
- if (toSortOn) setSortOn(toSortOn);
373
- if (toSortOrder) setSortOrder(toSortOrder);
438
+ if (hasSortOnParam) setSortOn(toSortOn || undefined);
439
+ if (toSortOrder !== undefined)
440
+ setSortOrder(toSortOrder || undefined);
374
441
  setSearchData(newSearchData);
375
442
  setLocationSearchData(getSearchFields(newSearchData));
376
443
  },
@@ -388,6 +455,7 @@ const withSearch = (options) => (WrappedComponent) => {
388
455
  sortOn,
389
456
  sortOrder,
390
457
  facetSettings,
458
+ isGlobalSearch,
391
459
  ],
392
460
  );
393
461