Skip to content

Commit

Permalink
Revert "Reset element (#60)" (#61)
Browse files Browse the repository at this point in the history
This reverts commit 6f09259.
  • Loading branch information
sneridagh committed Sep 30, 2022
1 parent 18c3a52 commit 1579fa1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 93 deletions.
1 change: 0 additions & 1 deletion cypress/integration/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ context('Blocks Acceptance Tests', () => {
cy.navigate('/document/edit');
cy.wait(500);
cy.get('.block.inner.__grid').click();
cy.get('.block.inner.__grid [aria-label="Reset grid element 1"]').click();
cy.get(
'.block.inner.__grid [aria-label="Remove grid element 1"]',
).click();
Expand Down
104 changes: 16 additions & 88 deletions src/components/Grid/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { v4 as uuid } from 'uuid';
import cx from 'classnames';
import { withRouter } from 'react-router-dom';
import { Icon, SidebarPortal } from '@plone/volto/components';
import { difference, withBlockExtensions } from '@plone/volto/helpers';
import { isEmpty } from 'lodash';
import { withBlockExtensions } from '@plone/volto/helpers';

import addSVG from '@plone/volto/icons/add.svg';
import clearSVG from '@plone/volto/icons/clear.svg';
Expand Down Expand Up @@ -92,18 +91,6 @@ class EditGrid extends Component {
});
};

onResetGridItem = (index, gridItemData) => {
this.props.onChangeBlock(this.props.block, {
...this.props.data,
columns: replaceItemOfArray(this.props.data.columns, index, {
'@type': this.props.data.columns[index]['@type'],
id: this.props.data.columns[index]['id'],
block: this.props.data.columns[index]['block'],
...gridItemData,
}),
});
};

/**
* Align block handler
* @method onAlignBlock
Expand Down Expand Up @@ -234,45 +221,6 @@ class EditGrid extends Component {
onChangeSelectedColumnItem = (index) =>
this.setState({ selectedColumnIndex: index });

hasResetBlockFn = (type) =>
type && typeof config.blocks.blocksConfig[type].resetBlock === 'function';

getBlockInitialData = (schema) => ({
...Object.keys(schema.properties).reduce((accumulator, currentField) => {
return schema.properties[currentField].default
? {
...accumulator,
[currentField]: schema.properties[currentField].default,
}
: accumulator;
}, {}),
});

isColumnResetable = (item) => {
let schema = config.blocks.blocksConfig?.[item['@type']]?.blockSchema;
if (typeof schema === 'function') {
schema = schema(this.props);
}

const itemKeys = Object.keys(item);
if (!schema && itemKeys.length > 3) {
return true;
}

if (schema && itemKeys.length > 3) {
const defaultValues = this.getBlockInitialData(schema);
const itemEssential = {
'@type': item['@type'],
id: item.id,
block: item.block,
};

return !isEmpty(difference(item, { ...itemEssential, ...defaultValues }));
}

return false;
};

node = React.createRef();

/**
Expand Down Expand Up @@ -427,41 +375,21 @@ class EditGrid extends Component {
this.onChangeSelectedColumnItem(index);
}}
>
{this.isColumnResetable(item) ? (
<Button
aria-label={`Reset grid element ${index}`}
basic
icon
onClick={(e) =>
this.onResetGridItem(index, {})
}
className="remove-block-button"
>
<Icon
name={clearSVG}
className="circled"
size="24px"
/>
</Button>
) : (
<Button
aria-label={`Remove grid element ${index}`}
basic
icon
onClick={(e) =>
this.removeColumn(e, index)
}
className="remove-block-button"
>
<Icon
name={clearSVG}
className="circled"
size="24px"
color="#e40166"
/>
</Button>
)}

<Button
aria-label={`Remove grid element ${index}`}
basic
icon
onClick={(e) =>
this.removeColumn(e, index)
}
className="remove-block-button"
>
<Icon
name={clearSVG}
className="circled"
size="24px"
/>
</Button>
{item['@type'] ? (
<BlockRenderer
{...this.props}
Expand Down
4 changes: 0 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import {
TeaserEditBlock,
TeaserBlockDefaultBody,
} from './components';

import { TeaserSchema } from './components/Teaser/schema';

import gridSVG from './icons/grid.svg';
import imagesSVG from '@plone/volto/icons/images.svg';

Expand Down Expand Up @@ -75,7 +72,6 @@ const customBlocks = {
restricted: false,
mostUsed: true,
sidebarTab: 1,
blockSchema: TeaserSchema,
variations: [
{
id: 'default',
Expand Down

0 comments on commit 1579fa1

Please sign in to comment.