@plone/volto 16.31.0 → 16.31.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,8 +1,8 @@
1
- ## 16.31.0 (2024-02-26)
1
+ ## 16.31.1 (2024-02-28)
2
2
 
3
- ### Feature
3
+ ### Bugfix
4
4
 
5
- - Allow editor to edit metadata during bulk upload. @iFlameing [#5549](https://github.com/plone/volto/issues/5549)
6
- - Add global form state. @robgietema [#5721](https://github.com/plone/volto/issues/5721)
5
+ - Fix the condition deciding on listing pagination format so it takes into account container blocks as well @sneridagh [#4978](https://github.com/plone/volto/issues/4978)
6
+ - Enhance findBlocks to check for blocks also in data for add-ons such as @eeacms/volto-tabs-block. @ichim-david [#5796](https://github.com/plone/volto/issues/5796)
7
7
 
8
8
 
package/CHANGELOG.md CHANGED
@@ -8,6 +8,13 @@
8
8
 
9
9
  <!-- towncrier release notes start -->
10
10
 
11
+ ## 16.31.1 (2024-02-28)
12
+
13
+ ### Bugfix
14
+
15
+ - Fix the condition deciding on listing pagination format so it takes into account container blocks as well @sneridagh [#4978](https://github.com/plone/volto/issues/4978)
16
+ - Enhance findBlocks to check for blocks also in data for add-ons such as @eeacms/volto-tabs-block. @ichim-david [#5796](https://github.com/plone/volto/issues/5796)
17
+
11
18
  ## 16.31.0 (2024-02-26)
12
19
 
13
20
  ### Feature
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "16.31.0",
12
+ "version": "16.31.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.31.0",
3
+ "version": "16.31.1",
4
4
  "description": "Slate.js integration with Volto",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -185,6 +185,7 @@ let config = {
185
185
  querystringSearchGet: false,
186
186
  blockSettingsTabFieldsetsInitialStateOpen: true,
187
187
  excludeLinksAndReferencesMenuItem: true,
188
+ containerBlockTypes: [],
188
189
  },
189
190
  experimental: {
190
191
  addBlockButton: {
@@ -533,3 +533,28 @@ export const getPreviousNextBlock = ({ content, block }) => {
533
533
 
534
534
  return [previousBlock, nextBlock];
535
535
  };
536
+
537
+ /**
538
+ * Given a `block` object and a list of block types, return a list of block ids matching the types
539
+ *
540
+ * @function findBlocks
541
+ * @param {Object} types A list with the list of types to be matched
542
+ * @return {Array} An array of block ids
543
+ */
544
+ export function findBlocks(blocks, types, result = []) {
545
+ const containerBlockTypes = config.settings.containerBlockTypes;
546
+
547
+ Object.keys(blocks).forEach((blockId) => {
548
+ const block = blocks[blockId];
549
+ // check blocks from data as well since some add-ons use that
550
+ // such as @eeacms/volto-tabs-block
551
+ const child_blocks = block.blocks || block.data?.blocks;
552
+ if (types.includes(block['@type'])) {
553
+ result.push(blockId);
554
+ } else if (containerBlockTypes.includes(block['@type']) || child_blocks) {
555
+ findBlocks(child_blocks, types, result);
556
+ }
557
+ });
558
+
559
+ return result;
560
+ }
@@ -19,6 +19,7 @@ import {
19
19
  buildStyleClassNamesFromData,
20
20
  buildStyleClassNamesExtenders,
21
21
  getPreviousNextBlock,
22
+ findBlocks,
22
23
  } from './Blocks';
23
24
 
24
25
  import config from '@plone/volto/registry';
@@ -1226,3 +1227,39 @@ describe('Blocks', () => {
1226
1227
  });
1227
1228
  });
1228
1229
  });
1230
+
1231
+ describe('findBlocks', () => {
1232
+ it('Get all blocks in the first level (main block container)', () => {
1233
+ const blocks = {
1234
+ '1': { title: 'title', '@type': 'title' },
1235
+ '2': { title: 'an image', '@type': 'image' },
1236
+ '3': { title: 'description', '@type': 'description' },
1237
+ '4': { title: 'a text', '@type': 'slate' },
1238
+ };
1239
+ const types = ['description'];
1240
+ expect(findBlocks(blocks, types)).toStrictEqual(['3']);
1241
+ });
1242
+
1243
+ it('Get all blocks in the first level (main block container) given a list', () => {
1244
+ const blocks = {
1245
+ '1': { title: 'title', '@type': 'title' },
1246
+ '2': { title: 'an image', '@type': 'image' },
1247
+ '3': { title: 'description', '@type': 'description' },
1248
+ '4': { title: 'a text', '@type': 'slate' },
1249
+ };
1250
+ const types = ['description', 'slate'];
1251
+ expect(findBlocks(blocks, types)).toStrictEqual(['3', '4']);
1252
+ });
1253
+
1254
+ it('Get all blocks in the first level (main block container) given a list', () => {
1255
+ const blocks = {
1256
+ '1': { title: 'title', '@type': 'title' },
1257
+ '2': { title: 'an image', '@type': 'image' },
1258
+ '3': { title: 'description', '@type': 'description' },
1259
+ '4': { title: 'a text', '@type': 'slate' },
1260
+ '5': { title: 'a text', '@type': 'slate' },
1261
+ };
1262
+ const types = ['description', 'slate'];
1263
+ expect(findBlocks(blocks, types)).toStrictEqual(['3', '4', '5']);
1264
+ });
1265
+ });
@@ -2,7 +2,7 @@ import React, { useRef, useEffect } from 'react';
2
2
  import { useHistory, useLocation } from 'react-router-dom';
3
3
  import qs from 'query-string';
4
4
  import { useSelector } from 'react-redux';
5
- import { slugify } from '@plone/volto/helpers/Utils/Utils';
5
+ import { findBlocks, slugify } from '@plone/volto/helpers';
6
6
 
7
7
  /**
8
8
  * @function useCreatePageQueryStringKey
@@ -12,13 +12,8 @@ import { slugify } from '@plone/volto/helpers/Utils/Utils';
12
12
  const useCreatePageQueryStringKey = (id) => {
13
13
  const blockTypesWithPagination = ['search', 'listing'];
14
14
  const blocks = useSelector((state) => state?.content?.data?.blocks) || [];
15
- const blocksLayout =
16
- useSelector((state) => state?.content?.data?.blocks_layout?.items) || [];
17
- const displayedBlocks = blocksLayout?.map((item) => blocks[item]);
18
15
  const hasMultiplePaginations =
19
- displayedBlocks.filter((item) =>
20
- blockTypesWithPagination.includes(item['@type']),
21
- ).length > 1 || false;
16
+ findBlocks(blocks, blockTypesWithPagination).length > 1;
22
17
 
23
18
  return hasMultiplePaginations ? slugify(`page-${id}`) : 'page';
24
19
  };
@@ -58,6 +58,7 @@ export {
58
58
  buildStyleClassNamesFromData,
59
59
  buildStyleClassNamesExtenders,
60
60
  getPreviousNextBlock,
61
+ findBlocks,
61
62
  } from '@plone/volto/helpers/Blocks/Blocks';
62
63
  export { default as BodyClass } from '@plone/volto/helpers/BodyClass/BodyClass';
63
64
  export { default as ScrollToTop } from '@plone/volto/helpers/ScrollToTop/ScrollToTop';
@@ -91,6 +92,7 @@ export {
91
92
  replaceItemOfArray,
92
93
  cloneDeepSchema,
93
94
  reorderArray,
95
+ slugify,
94
96
  } from '@plone/volto/helpers/Utils/Utils';
95
97
  export { messages } from './MessageLabels/MessageLabels';
96
98
  export {
@@ -82,6 +82,7 @@ config.set('settings', {
82
82
  viewableInBrowserObjects: [],
83
83
  styleClassNameConverters,
84
84
  styleClassNameExtenders,
85
+ containerBlockTypes: [],
85
86
  });
86
87
  config.set('blocks', {
87
88
  blocksConfig: {