Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:Order blocks in sidebar doesn't respect layout restrictions: requ… #6489

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/volto/news/6481.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
While editing a block, and in the sidebar under the {guilabel}`Settings` tab, when an item has {guilabel}`Required` checked, then it can no longer be deleted under the {guilabel}`Order` tab. Similarly, when {guilabel}`Fixed position` is checked, the item's ordered position can no longer be changed. Previously neither option was honored. @alihamza1221
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ const BlocksForm = (props) => {
onMoveBlock={onMoveBlockEnhanced}
onDeleteBlock={onDeleteBlock}
onSelectBlock={onSelectBlock}
editable={editable}
removable
errors={blocksErrors}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { defineMessages, injectIntl } from 'react-intl';
import cx from 'classnames';
import config from '@plone/volto/registry';
import BlockChooserButton from '@plone/volto/components/manage/BlockChooser/BlockChooserButton';
import { hideHandler } from '@plone/volto/helpers/Blocks/Blocks';

import trashSVG from '@plone/volto/icons/delete.svg';

Expand All @@ -28,14 +29,6 @@ const messages = defineMessages({
});

const EditBlockWrapper = (props) => {
const hideHandler = (data) => {
return (
!!data.fixed ||
(!config.experimental.addBlockButton.enabled &&
!(blockHasValue(data) && props.blockProps.editable))
);
};

const { intl, blockProps, draginfo, children } = props;
const {
allowedBlocks,
Expand All @@ -59,7 +52,7 @@ const EditBlockWrapper = (props) => {

const data = applyBlockDefaults({ data: originalData, ...blockProps, intl });

const visible = selected && !hideHandler(data);
const visible = selected && !hideHandler(data, editable);

const required = isBoolean(data.required)
? data.required
Expand Down
14 changes: 13 additions & 1 deletion packages/volto/src/components/manage/Blocks/Block/Order/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import React, { forwardRef } from 'react';
import classNames from 'classnames';
import { useDispatch, useSelector } from 'react-redux';
import includes from 'lodash/includes';
import isBoolean from 'lodash/isBoolean';
import cx from 'classnames';
import Icon from '@plone/volto/components/theme/Icon/Icon';
import { setUIState } from '@plone/volto/actions/form/form';
import config from '@plone/volto/registry';
import { hideHandler } from '@plone/volto/helpers/Blocks/Blocks';

import deleteSVG from '@plone/volto/icons/delete.svg';
import dragSVG from '@plone/volto/icons/drag.svg';
Expand Down Expand Up @@ -39,6 +41,12 @@ export const Item = forwardRef(
const gridSelected = useSelector((state) => state.form.ui.gridSelected);
const dispatch = useDispatch();

const visible = !hideHandler(data, props?.editable);

const required = isBoolean(data?.required)
? data?.required
: includes(config.blocks.requiredBlocks, data?.['@type']);

return (
<li
className={classNames(
Expand Down Expand Up @@ -93,6 +101,10 @@ export const Item = forwardRef(
{...handleProps}
className={classNames('action', 'drag')}
tabIndex={0}
style={{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of having a visibility style it would make more sense to me to have the "disabled" property added and this way you also get a screen reader compatible information on why you can't interact with the button

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but there are other places were we have used visibilty style will update it today

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ichim-david I did added disabled property but removing visiblity style it's didn't seemed to respect the required functionality, If you would like to add more changes let me know

visibility: visible ? 'visible' : 'hidden',
}}
disabled={!visible}
data-cypress="draggable-handle"
>
<Icon name={dragSVG} size="16px" />
Expand All @@ -112,7 +124,7 @@ export const Item = forwardRef(
{data?.plaintext ||
config.blocks.blocksConfig[data?.['@type']]?.title}
</span>
{!clone && onRemove && (
{!clone && onRemove && !required && (
<button
onClick={onRemove}
className={classNames('action', 'delete')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function Order({
onSelectBlock,
indentationWidth = 25,
removable,
editable,
dndKitCore,
dndKitSortable,
dndKitUtilities,
Expand Down Expand Up @@ -148,6 +149,7 @@ export function Order({
indentationWidth={indentationWidth}
onRemove={removable ? () => handleRemove(id) : undefined}
onSelectBlock={onSelectBlock}
editable={editable}
errors={errors?.[id] || {}}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ exports[`Allow override of blocksConfig 1`] = `
class="action drag"
data-cypress="draggable-handle"
role="button"
style="visibility: visible;"
tabindex="0"
>
<svg
Expand Down Expand Up @@ -215,6 +216,7 @@ exports[`Allow override of blocksConfig 1`] = `
class="action drag"
data-cypress="draggable-handle"
role="button"
style="visibility: visible;"
tabindex="0"
>
<svg
Expand Down
15 changes: 15 additions & 0 deletions packages/volto/src/helpers/Blocks/Blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ export function blockHasValue(data) {
return check(data);
}

/**
* Pluggable method to test if a block has a set value (any non-empty value)
* @function hideHandler
* @param {Object} data Block data
* @param {boolean} editable Indicates if is editable
* @return {boolean} True if block is fixed
*/
export const hideHandler = (data, editable) => {
return (
!!data?.fixed ||
(!config.experimental.addBlockButton.enabled &&
!(data && blockHasValue(data) && !!editable))
);
};

/**
* Get block pairs of [id, block] from content properties
* @function getBlocks
Expand Down
Loading