@plone/volto 16.31.0 → 16.31.2

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,7 @@
1
- ## 16.31.0 (2024-02-26)
1
+ ## 16.31.2 (2024-03-05)
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 translation error message. @robgietema [#5835](https://github.com/plone/volto/issues/5835)
7
6
 
8
7
 
Binary file
package/CHANGELOG.md CHANGED
@@ -8,6 +8,19 @@
8
8
 
9
9
  <!-- towncrier release notes start -->
10
10
 
11
+ ## 16.31.2 (2024-03-05)
12
+
13
+ ### Bugfix
14
+
15
+ - Fix translation error message. @robgietema [#5835](https://github.com/plone/volto/issues/5835)
16
+
17
+ ## 16.31.1 (2024-02-28)
18
+
19
+ ### Bugfix
20
+
21
+ - 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)
22
+ - 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)
23
+
11
24
  ## 16.31.0 (2024-02-26)
12
25
 
13
26
  ### 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.2",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git@github.com:plone/volto.git"
@@ -368,7 +368,7 @@
368
368
  "react-simple-code-editor": "0.7.1",
369
369
  "react-sortable-hoc": "2.0.0",
370
370
  "react-test-renderer": "17.0.2",
371
- "react-toastify": "5.4.1",
371
+ "react-toastify": "5.5.0",
372
372
  "react-transition-group": "4.4.5",
373
373
  "react-virtualized": "9.22.3",
374
374
  "redraft": "0.10.2",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plone/volto-slate",
3
- "version": "16.31.0",
3
+ "version": "16.31.2",
4
4
  "description": "Slate.js integration with Volto",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -37,6 +37,7 @@ import {
37
37
  } from '@plone/volto/helpers';
38
38
 
39
39
  import { preloadLazyLibs } from '@plone/volto/helpers/Loadable';
40
+ import { tryParseJSON } from '@plone/volto/helpers';
40
41
 
41
42
  import config from '@plone/volto/registry';
42
43
 
@@ -178,13 +179,29 @@ class Add extends Component {
178
179
  new DOMParser().parseFromString(message, 'text/html')?.all[0]
179
180
  ?.textContent || message;
180
181
 
181
- this.setState({ error: error });
182
+ const errorsList = tryParseJSON(error);
183
+ let erroMessage;
184
+ if (Array.isArray(errorsList)) {
185
+ const invariantErrors = errorsList
186
+ .filter((errorItem) => !('field' in errorItem))
187
+ .map((errorItem) => errorItem['message']);
188
+ if (invariantErrors.length > 0) {
189
+ // Plone invariant validation message.
190
+ erroMessage = invariantErrors.join(' - ');
191
+ } else {
192
+ // Error in specific field.
193
+ erroMessage = this.props.intl.formatMessage(messages.someErrors);
194
+ }
195
+ } else {
196
+ erroMessage = errorsList.error?.message || error;
197
+ }
182
198
 
199
+ this.setState({ error: error });
183
200
  toast.error(
184
201
  <Toast
185
202
  error
186
203
  title={this.props.intl.formatMessage(messages.error)}
187
- content={`${nextProps.createRequest.error.status}: ${error}`}
204
+ content={erroMessage}
188
205
  />,
189
206
  );
190
207
  }
@@ -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
+ });
@@ -156,7 +156,7 @@ const widgetValidation = {
156
156
  * The string that comes my not be a valid JSON
157
157
  * @param {string} requestItem
158
158
  */
159
- const tryParseJSON = (requestItem) => {
159
+ export const tryParseJSON = (requestItem) => {
160
160
  let resultObj = null;
161
161
  try {
162
162
  resultObj = JSON.parse(requestItem);
@@ -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';
@@ -74,6 +75,7 @@ export { default as langmap } from './LanguageMap/LanguageMap';
74
75
  export { default as Helmet } from './Helmet/Helmet';
75
76
  export { default as FormValidation } from './FormValidation/FormValidation';
76
77
  export { validateFileUploadSize } from './FormValidation/FormValidation';
78
+ export { tryParseJSON } from './FormValidation/FormValidation';
77
79
  export {
78
80
  difference,
79
81
  getColor,
@@ -91,6 +93,7 @@ export {
91
93
  replaceItemOfArray,
92
94
  cloneDeepSchema,
93
95
  reorderArray,
96
+ slugify,
94
97
  } from '@plone/volto/helpers/Utils/Utils';
95
98
  export { messages } from './MessageLabels/MessageLabels';
96
99
  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: {