Skip to content

Commit

Permalink
fixed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alihamza1221 committed Nov 22, 2024
1 parent 747b5fd commit 10fb29c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
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
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 @@ -52,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
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export const Item = forwardRef(
const gridSelected = useSelector((state) => state.form.ui.gridSelected);
const dispatch = useDispatch();

const visible = !hideHandler(data);
const required = isBoolean(data.required)
? data.required
: includes(config.blocks.requiredBlocks, data.type);
const visible = !hideHandler(data, props?.editable);

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

return (
<li
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
9 changes: 5 additions & 4 deletions packages/volto/src/helpers/Blocks/Blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ export function blockHasValue(data) {
* Pluggable method to test if a block has a set value (any non-empty value)
* @function hideHandler
* @param {Object} data Block data
* @return {boolean} True if block has fixed attribute, or if the addBlockButton is disabled or block having value is not editable
* @param {boolean} editable Indicates if is editable
* @return {boolean} True if block is fixed
*/
export const hideHandler = (data) => {
export const hideHandler = (data, editable) => {
return (
!!data.fixed ||
!!data?.fixed ||
(!config.experimental.addBlockButton.enabled &&
!(blockHasValue(data) && data.editable))
!(data && blockHasValue(data) && !!editable))
);
};

Expand Down

0 comments on commit 10fb29c

Please sign in to comment.