Skip to content

Commit

Permalink
Merge pull request #252 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea authored Aug 5, 2024
2 parents fec0105 + e3f24aa commit 0046715
Show file tree
Hide file tree
Showing 9 changed files with 1,270 additions and 4 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

### [2.1.4](https://github.com/eea/volto-eea-website-theme/compare/2.1.3...2.1.4) - 30 July 2024
### [2.1.5](https://github.com/eea/volto-eea-website-theme/compare/2.1.4...2.1.5) - 5 August 2024

#### :bug: Bug Fixes
#### :rocket: New Features

- feat: Customization Pass errors blocksform - refs 269086 [dobri1408 - [`9e11656`](https://github.com/eea/volto-eea-website-theme/commit/9e116563111b4e741678db21e7edf72ca6f163c6)]

#### :hammer_and_wrench: Others

- fix(slate): don't customize slate li element, ref #269872 [Miu Razvan - [`945afa5`](https://github.com/eea/volto-eea-website-theme/commit/945afa5c1076de4779d46f602300a61adf41937d)]
- Add more info to customized components [alin - [`1dc85ab`](https://github.com/eea/volto-eea-website-theme/commit/1dc85ab3d5b3c9de788cd9dbce90284a503adddf)]
### [2.1.4](https://github.com/eea/volto-eea-website-theme/compare/2.1.3...2.1.4) - 1 August 2024

### [2.1.3](https://github.com/eea/volto-eea-website-theme/compare/2.1.2...2.1.3) - 22 July 2024

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ See [Storybook](https://eea.github.io/eea-storybook/).
**!!IMPORTANT**: This change requires volto@^16.26.1

- `volto/components/manage/Sidebar/SidebarPopup` -> https://github.com/plone/volto/pull/5520
- `volto/components/manage/Form/Form.jsx` -> Pass errors of metadata validation to BlocksForm
- `volto/components/manage/Blocks/Block/BlocksForm.jsx` -> Pass errors of metadata validation to blocks.

## Getting started

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-eea-website-theme",
"version": "2.1.4",
"version": "2.1.5",
"description": "@eeacms/volto-eea-website-theme: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
3c3
< import EditBlock from './Edit';
---
> import EditBlock from '@plone/volto/components/manage/Blocks/Block/Edit.jsx';
20c20
< import EditBlockWrapper from './EditBlockWrapper';
---
> import EditBlockWrapper from '@plone/volto/components/manage/Blocks/Block/EditBlockWrapper.jsx';
41a42
> errors,
261a263
> errors,
289 changes: 289 additions & 0 deletions src/customizations/volto/components/manage/Blocks/Block/BlocksForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
import React from 'react';
import { useIntl } from 'react-intl';
import EditBlock from '@plone/volto/components/manage/Blocks/Block/Edit.jsx';
import { DragDropList } from '@plone/volto/components';
import {
getBlocks,
getBlocksFieldname,
applyBlockDefaults,
} from '@plone/volto/helpers';
import {
addBlock,
insertBlock,
changeBlock,
deleteBlock,
moveBlock,
mutateBlock,
nextBlockId,
previousBlockId,
} from '@plone/volto/helpers';
import EditBlockWrapper from '@plone/volto/components/manage/Blocks/Block/EditBlockWrapper.jsx';
import { setSidebarTab } from '@plone/volto/actions';
import { useDispatch } from 'react-redux';
import { useDetectClickOutside, useEvent } from '@plone/volto/helpers';
import config from '@plone/volto/registry';

const BlocksForm = (props) => {
const {
pathname,
onChangeField,
properties,
type,
navRoot,
onChangeFormData,
selectedBlock,
multiSelected,
onSelectBlock,
allowedBlocks,
showRestricted,
title,
description,
metadata,
errors,
manage,
children,
isMainForm = true,
isContainer,
stopPropagation,
disableAddBlockOnEnterKey,
blocksConfig = config.blocks.blocksConfig,
editable = true,
direction = 'vertical',
} = props;

const blockList = getBlocks(properties);

const dispatch = useDispatch();
const intl = useIntl();

const ClickOutsideListener = () => {
onSelectBlock(null);
dispatch(setSidebarTab(0));
};

const ref = useDetectClickOutside({
onTriggered: ClickOutsideListener,
triggerKeys: ['Escape'],
// Disabled feature for now https://github.com/plone/volto/pull/2389#issuecomment-830027413
disableClick: true,
disableKeys: !isMainForm,
});

const handleKeyDown = (
e,
index,
block,
node,
{
disableEnter = false,
disableArrowUp = false,
disableArrowDown = false,
} = {},
) => {
const isMultipleSelection = e.shiftKey;
if (e.key === 'ArrowUp' && !disableArrowUp) {
onFocusPreviousBlock(block, node, isMultipleSelection);
e.preventDefault();
}
if (e.key === 'ArrowDown' && !disableArrowDown) {
onFocusNextBlock(block, node, isMultipleSelection);
e.preventDefault();
}
if (e.key === 'Enter' && !disableEnter) {
if (!disableAddBlockOnEnterKey) {
onSelectBlock(onAddBlock(config.settings.defaultBlockType, index + 1));
}
e.preventDefault();
}
};

const onFocusPreviousBlock = (
currentBlock,
blockNode,
isMultipleSelection,
) => {
const prev = previousBlockId(properties, currentBlock);
if (prev === null) return;

blockNode.blur();

onSelectBlock(prev, isMultipleSelection);
};

const onFocusNextBlock = (currentBlock, blockNode, isMultipleSelection) => {
const next = nextBlockId(properties, currentBlock);
if (next === null) return;

blockNode.blur();

onSelectBlock(next, isMultipleSelection);
};

const onMutateBlock = (id, value) => {
const newFormData = mutateBlock(properties, id, value);
onChangeFormData(newFormData);
};

const onInsertBlock = (id, value, current) => {
const [newId, newFormData] = insertBlock(
properties,
id,
value,
current,
config.experimental.addBlockButton.enabled ? 1 : 0,
);

const blocksFieldname = getBlocksFieldname(newFormData);
const blockData = newFormData[blocksFieldname][newId];
newFormData[blocksFieldname][newId] = applyBlockDefaults({
data: blockData,
intl,
metadata,
properties,
});

onChangeFormData(newFormData);
return newId;
};

const onAddBlock = (type, index) => {
if (editable) {
const [id, newFormData] = addBlock(properties, type, index);
const blocksFieldname = getBlocksFieldname(newFormData);
const blockData = newFormData[blocksFieldname][id];
newFormData[blocksFieldname][id] = applyBlockDefaults({
data: blockData,
intl,
metadata,
properties,
});
onChangeFormData(newFormData);
return id;
}
};

const onChangeBlock = (id, value) => {
const newFormData = changeBlock(properties, id, value);
onChangeFormData(newFormData);
};

const onDeleteBlock = (id, selectPrev) => {
const previous = previousBlockId(properties, id);

const newFormData = deleteBlock(properties, id);
onChangeFormData(newFormData);

onSelectBlock(selectPrev ? previous : null);
};

const onMoveBlock = (dragIndex, hoverIndex) => {
const newFormData = moveBlock(properties, dragIndex, hoverIndex);
onChangeFormData(newFormData);
};

const defaultBlockWrapper = ({ draginfo }, editBlock, blockProps) => (
<EditBlockWrapper draginfo={draginfo} blockProps={blockProps}>
{editBlock}
</EditBlockWrapper>
);

const editBlockWrapper = children || defaultBlockWrapper;

// Remove invalid blocks on saving
// Note they are alreaady filtered by DragDropList, but we also want them
// to be removed when the user saves the page next. Otherwise the invalid
// blocks would linger for ever.
for (const [n, v] of blockList) {
if (!v) {
const newFormData = deleteBlock(properties, n);
onChangeFormData(newFormData);
}
}

useEvent('voltoClickBelowContent', () => {
if (!config.experimental.addBlockButton.enabled || !isMainForm) return;
onSelectBlock(
onAddBlock(config.settings.defaultBlockType, blockList.length),
);
});

return (
<div
className="blocks-form"
role="presentation"
ref={ref}
onKeyDown={(e) => {
if (stopPropagation) {
e.stopPropagation();
}
}}
>
<fieldset className="invisible" disabled={!editable}>
<DragDropList
childList={blockList}
onMoveItem={(result) => {
const { source, destination } = result;
if (!destination) {
return;
}
const newFormData = moveBlock(
properties,
source.index,
destination.index,
);
onChangeFormData(newFormData);
return true;
}}
direction={direction}
>
{(dragProps) => {
const { child, childId, index } = dragProps;
const blockProps = {
allowedBlocks,
showRestricted,
block: childId,
data: child,
handleKeyDown,
id: childId,
formTitle: title,
formDescription: description,
index,
manage,
onAddBlock,
onInsertBlock,
onChangeBlock,
onChangeField,
onChangeFormData,
onDeleteBlock,
onFocusNextBlock,
onFocusPreviousBlock,
onMoveBlock,
onMutateBlock,
onSelectBlock,
errors,
pathname,
metadata,
properties,
contentType: type,
navRoot,
blocksConfig,
selected: selectedBlock === childId,
multiSelected: multiSelected?.includes(childId),
type: child['@type'],
editable,
showBlockChooser: selectedBlock === childId,
detached: isContainer,
};
return editBlockWrapper(
dragProps,
<EditBlock key={childId} {...blockProps} />,
blockProps,
);
}}
</DragDropList>
</fieldset>
</div>
);
};

export default BlocksForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Customize from @plone/volto 17.18.2 - refs https://taskman.eionet.europa.eu/issues/269086
Should be safe to remove with @plone/volto 18.x - https://github.com/plone/volto/pull/6181
2 changes: 2 additions & 0 deletions src/customizations/volto/components/manage/Form/Form.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
697a698
> errors={this.state.errors}
Loading

0 comments on commit 0046715

Please sign in to comment.