@eeacms/volto-accordion-block
Advanced tools
Comparing version 3.4.2 to 3.4.3
@@ -7,4 +7,11 @@ ### Changelog | ||
#### [3.4.3](https://github.com/eea/volto-accordion-block/compare/3.4.2...3.4.3) | ||
- Fix schemaEnhancer support for default values on newly created accord… [`#24`](https://github.com/eea/volto-accordion-block/pull/24) | ||
#### [3.4.2](https://github.com/eea/volto-accordion-block/compare/3.4.1...3.4.2) | ||
> 16 September 2021 | ||
- Add infrastructure support for i18n and locales folder (#23) [`#25`](https://github.com/eea/volto-accordion-block/pull/25) | ||
- Add infrastructure support for i18n and locales folder [`#23`](https://github.com/eea/volto-accordion-block/pull/23) | ||
@@ -11,0 +18,0 @@ |
{ | ||
"name": "@eeacms/volto-accordion-block", | ||
"version": "3.4.2", | ||
"version": "3.4.3", | ||
"description": "volto-accordion-block: Volto accordion block", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -15,2 +15,4 @@ import { BlocksForm, Icon, SidebarPortal } from '@plone/volto/components'; | ||
import { emptyAccordion, getPanels } from './util'; | ||
import { cloneDeep } from 'lodash'; | ||
import config from '@plone/volto/registry'; | ||
@@ -35,2 +37,31 @@ const Edit = (props) => { | ||
const applySchemaEnhancer = (originalSchema) => { | ||
let schema, schemaEnhancer; | ||
const formData = data; | ||
const { blocks } = config; | ||
const blockType = formData['@type']; | ||
const variations = blocks?.blocksConfig[blockType]?.variations || []; | ||
if (variations.length === 0) { | ||
// No variations present but anyways | ||
// finalize the schema with a schemaEnhancer in the block config is present | ||
schemaEnhancer = blocks.blocksConfig?.[blockType]?.schemaEnhancer; | ||
if (schemaEnhancer) | ||
schema = schemaEnhancer({ schema: originalSchema, formData, intl }); | ||
} | ||
const activeItemName = formData?.variation; | ||
let activeItem = variations.find((item) => item.id === activeItemName); | ||
if (!activeItem) activeItem = variations.find((item) => item.isDefault); | ||
schemaEnhancer = activeItem?.['schemaEnhancer']; | ||
schema = schemaEnhancer | ||
? schemaEnhancer({ schema: cloneDeep(originalSchema), formData, intl }) | ||
: cloneDeep(originalSchema); | ||
return schema; | ||
}; | ||
/** | ||
@@ -41,3 +72,3 @@ * Will set field values from schema, by matching the default values | ||
const setInitialData = () => { | ||
const accordionSchema = accordionBlockSchema({ intl }); | ||
const accordionSchema = applySchemaEnhancer(accordionBlockSchema({ intl })); | ||
const defaultValues = Object.keys(accordionSchema.properties).reduce( | ||
@@ -44,0 +75,0 @@ (accumulator, currentVal) => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104159
1816