Skip to content

Commit

Permalink
do not render empty accordion on View, unless it have single content
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Nov 6, 2020
1 parent 21fd274 commit eca7c7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/manage/Blocks/Accordion/View.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { RenderBlocks } from '@eeacms/volto-blocks-form/components';
import { getColumns } from './util';
import { getColumns, GroupblockHasValue } from './util';
import AccordionEdit from './AccordionEdit';
const View = (props) => {
const {
Expand All @@ -11,11 +11,11 @@ const View = (props) => {
return (
<div>
{columnList.map(([id, column], index) => {
return (
return GroupblockHasValue(column) ? (
<AccordionEdit data={data}>
<RenderBlocks {...props} metadata={metadata} content={column} />
</AccordionEdit>
);
) : null;
})}
</div>
);
Expand Down
16 changes: 16 additions & 0 deletions src/components/manage/Blocks/Accordion/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { v4 as uuid } from 'uuid';
import { emptyBlocksForm } from '@eeacms/volto-blocks-form/helpers';
import { settings } from '~/config';
import { map } from 'lodash';
import {
getBlocksFieldname,
getBlocksLayoutFieldname,
blockHasValue,
} from '@plone/volto/helpers';

export const empty = (count) => {
const blocks = {};
Expand All @@ -25,3 +31,13 @@ export const getColumns = (data) => {
data.blocks?.[id],
]);
};

export const GroupblockHasValue = (content) => {
const blocksFieldname = getBlocksFieldname(content);
const blocksLayoutFieldname = getBlocksLayoutFieldname(content);
const blockValue = map(content[blocksLayoutFieldname].items, (block) => {
const blockData = content[blocksFieldname]?.[block];
return blockHasValue(blockData);
});
return blockValue.length === 1 ? blockValue[0] : true;
};

0 comments on commit eca7c7e

Please sign in to comment.