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

Refactored Blocks/ToC/Edits.jsx to functional component #6167

Merged
merged 11 commits into from
Aug 10, 2024
1 change: 1 addition & 0 deletions packages/volto/news/6167.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor the table of contents block component from a class component to a functional component. @Prince0906
57 changes: 28 additions & 29 deletions packages/volto/src/components/manage/Blocks/ToC/Edit.jsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import React, { Component } from 'react';
import React from 'react';

import { SidebarPortal } from '@plone/volto/components';
import { BlockDataForm } from '@plone/volto/components/manage/Form';

import TableOfContentsSchema from './Schema';
import View from './View';

class Edit extends Component {
render() {
const schema = TableOfContentsSchema(this.props);
const Edit = (props) => {
const { onChangeBlock, data, block, selected, navRoot, contentType, blocksErrors } = props;

Check failure on line 10 in packages/volto/src/components/manage/Blocks/ToC/Edit.jsx

View workflow job for this annotation

GitHub Actions / ESlint

Replace `·onChangeBlock,·data,·block,·selected,·navRoot,·contentType,·blocksErrors` with `⏎····onChangeBlock,⏎····data,⏎····block,⏎····selected,⏎····navRoot,⏎····contentType,⏎····blocksErrors,⏎·`
davisagli marked this conversation as resolved.
Show resolved Hide resolved
const schema = TableOfContentsSchema(props);

return (
<>
<View {...this.props} mode="edit" />
return (
<>
<View {...props} mode="edit" />

<SidebarPortal selected={this.props.selected}>
<BlockDataForm
schema={schema}
title={schema.title}
onChangeField={(id, value) => {
this.props.onChangeBlock(this.props.block, {
...this.props.data,
[id]: value,
});
}}
onChangeBlock={this.props.onChangeBlock}
formData={this.props.data}
block={this.props.block}
navRoot={this.props.navRoot}
contentType={this.props.contentType}
errors={this.props.blocksErrors}
/>
</SidebarPortal>
</>
);
}
}
<SidebarPortal selected={selected}>
<BlockDataForm
schema={schema}
title={schema.title}
onChangeField={(id, value) => {
onChangeBlock(block, {
...data,
[id]: value,
});
}}
onChangeBlock={onChangeBlock}
formData={data}
block={block}
navRoot={navRoot}
contentType={contentType}
errors={blocksErrors}
/>
</SidebarPortal>
</>
);
};

export default Edit;
Loading