@plone/volto 16.30.0 → 16.30.1

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.draft CHANGED
@@ -1,7 +1,9 @@
1
- ## 16.30.0 (2023-12-13)
1
+ ## 16.30.1 (2024-01-10)
2
2
 
3
- ### Feature
3
+ ### Bugfix
4
4
 
5
- - Added `navRoot` and `contentType` to `restricted` key in blocks configuration. @sneridagh [#5517](https://github.com/plone/volto/issues/5517)
5
+ - Fix autopopulated value of facet when settings the value for another one. @iFlameing [#5432](https://github.com/plone/volto/issues/5432)
6
+ - Replace createRef with useRef in SidebarPopup
7
+ [razvanMiu] [#5519](https://github.com/plone/volto/issues/5519)
6
8
 
7
9
 
Binary file
package/CHANGELOG.md CHANGED
@@ -8,6 +8,14 @@
8
8
 
9
9
  <!-- towncrier release notes start -->
10
10
 
11
+ ## 16.30.1 (2024-01-10)
12
+
13
+ ### Bugfix
14
+
15
+ - Fix autopopulated value of facet when settings the value for another one. @iFlameing [#5432](https://github.com/plone/volto/issues/5432)
16
+ - Replace createRef with useRef in SidebarPopup
17
+ [razvanMiu] [#5519](https://github.com/plone/volto/issues/5519)
18
+
11
19
  ## 16.30.0 (2023-12-13)
12
20
 
13
21
  ### Feature
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "16.30.0",
12
+ "version": "16.30.1",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git@github.com:plone/volto.git"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plone/volto-slate",
3
- "version": "16.30.0",
3
+ "version": "16.30.1",
4
4
  "description": "Slate.js integration with Volto",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -91,9 +91,21 @@ function normalizeState({
91
91
  types: facetWidgetTypes,
92
92
  } = config.blocks.blocksConfig.search.extensions.facetWidgets;
93
93
 
94
+ // Here, we are removing the QueryString of the Listing ones, which is present in the Facet
95
+ // because we already initialize the facet with those values.
96
+ const configuredFacets = facetSettings
97
+ ? facetSettings.map((facet) => facet?.field?.value)
98
+ : [];
99
+
100
+ let copyOfQuery = query.query ? [...query.query] : [];
101
+
102
+ const queryWithoutFacet = copyOfQuery.filter((query) => {
103
+ return !configuredFacets.includes(query.i);
104
+ });
105
+
94
106
  const params = {
95
107
  query: [
96
- ...(query.query || []),
108
+ ...(queryWithoutFacet || []),
97
109
  ...(facetSettings || []).map((facet) => {
98
110
  if (!facet?.field) return null;
99
111
 
@@ -252,14 +264,64 @@ const withSearch = (options) => (WrappedComponent) => {
252
264
  const [searchText, setSearchText] = React.useState(urlSearchText);
253
265
  const configuredFacets =
254
266
  data.facets?.map((facet) => facet?.field?.value) || [];
267
+
268
+ // Here we are getting the initial value of the facet if Listing Query contains the same criteria as
269
+ // facet.
270
+ const queryData = data?.query?.query
271
+ ? deserializeQuery(JSON.stringify(data?.query?.query))
272
+ : [];
273
+
274
+ let intializeFacetWithQueryValue = [];
275
+
276
+ for (let value of configuredFacets) {
277
+ const queryString = queryData.find((item) => item.i === value);
278
+ if (queryString) {
279
+ intializeFacetWithQueryValue = [
280
+ ...intializeFacetWithQueryValue,
281
+ { [queryString.i]: queryString.v },
282
+ ];
283
+ }
284
+ }
285
+
255
286
  const multiFacets = data.facets
256
287
  ?.filter((facet) => facet?.multiple)
257
288
  .map((facet) => facet?.field?.value);
258
- const [facets, setFacets] = React.useState({});
289
+ const [facets, setFacets] = React.useState(
290
+ Object.assign(
291
+ {},
292
+ ...urlQuery.map(({ i, v }) => ({ [i]: v })),
293
+ // TODO: the 'o' should be kept. This would be a major refactoring of the facets
294
+ ...intializeFacetWithQueryValue,
295
+ // support for simple filters like ?Subject=something
296
+ // TODO: since the move to hash params this is no longer working.
297
+ // We'd have to treat the location.search and manage it just like the
298
+ // hash, to support it. We can read it, but we'd have to reset it as
299
+ // well, so at that point what's the difference to the hash?
300
+ ...configuredFacets.map((f) =>
301
+ locationSearchData[f]
302
+ ? {
303
+ [f]:
304
+ multiFacets.indexOf(f) > -1
305
+ ? [locationSearchData[f]]
306
+ : locationSearchData[f],
307
+ }
308
+ : {},
309
+ ),
310
+ ),
311
+ );
259
312
  const previousUrlQuery = usePrevious(urlQuery);
260
313
 
314
+ // During first render the previousUrlQuery is undefined and urlQuery
315
+ // is empty so it ressetting the facet when you are navigating but during reload we have urlQuery and we need
316
+ // to set the facet at first render.
317
+ const preventOverrideOfFacetState =
318
+ previousUrlQuery === undefined && urlQuery.length === 0;
319
+
261
320
  React.useEffect(() => {
262
- if (!isEqual(urlQuery, previousUrlQuery)) {
321
+ if (
322
+ !isEqual(urlQuery, previousUrlQuery) &&
323
+ !preventOverrideOfFacetState
324
+ ) {
263
325
  setFacets(
264
326
  Object.assign(
265
327
  {},
@@ -289,6 +351,7 @@ const withSearch = (options) => (WrappedComponent) => {
289
351
  locationSearchData,
290
352
  multiFacets,
291
353
  previousUrlQuery,
354
+ preventOverrideOfFacetState,
292
355
  ]);
293
356
 
294
357
  const [sortOn, setSortOn] = React.useState(data?.query?.sort_on);
@@ -9,7 +9,7 @@ const DEFAULT_TIMEOUT = 500;
9
9
  const SidebarPopup = (props) => {
10
10
  const { children, open, onClose, overlay } = props;
11
11
 
12
- const asideElement = React.createRef();
12
+ const asideElement = React.useRef();
13
13
 
14
14
  const handleClickOutside = (e) => {
15
15
  if (asideElement && doesNodeContainClick(asideElement.current, e)) return;