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 2 commits 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 @@
Fixed Order blocks in sidebar doesn't respect layout restrictions by setting appropriate handlers in `Item.jsx`. @alihamza1221
Copy link
Collaborator

@stevepiercy stevepiercy Nov 22, 2024

Choose a reason for hiding this comment

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

A good change log entry explicitly states what problem you fixed, not how you fixed it. The original message essentially said, "Fixed _____ by writing code in a specific file". See https://6.docs.plone.org/contributing/index.html#change-log-entry after the Important admonition for details.

Suggested change
Fixed Order blocks in sidebar doesn't respect layout restrictions by setting appropriate handlers in `Item.jsx`. @alihamza1221
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`. 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) => {
onDeleteBlock={onDeleteBlock}
onSelectBlock={onSelectBlock}
removable
editable={editable}
errors={blocksErrors}
/>
</div>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
buildStyleObjectFromData,
buildStyleClassNamesExtenders,
} from '@plone/volto/helpers';
import { hideHandler } from '@plone/volto/helpers/Blocks/Blocks';
import dragSVG from '@plone/volto/icons/drag.svg';
import { Button } from 'semantic-ui-react';
import includes from 'lodash/includes';
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
13 changes: 12 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';
import isBoolean from 'lodash/isBoolean';
import cx from 'classnames';
import { Icon } from '@plone/volto/components';
import { setUIState } from '@plone/volto/actions';
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 @@ -91,6 +99,9 @@ export const Item = forwardRef(
<button
ref={ref}
{...handleProps}
style={{
visibility: visible ? 'visible' : 'hidden',
}}
className={classNames('action', 'drag')}
tabIndex={0}
data-cypress="draggable-handle"
Expand All @@ -112,7 +123,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 @@ -17,6 +17,7 @@ export function Order({
dndKitCore,
dndKitSortable,
dndKitUtilities,
editable,
errors,
}) {
const [activeId, setActiveId] = useState(null);
Expand Down Expand Up @@ -147,6 +148,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
14 changes: 14 additions & 0 deletions packages/volto/src/helpers/Blocks/Blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ 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
Expand Down
Loading