Skip to content

Commit

Permalink
Cleanup Image widget and pass down onSelectItem prop if any (#6132)
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh authored Jun 28, 2024
1 parent c50c1b3 commit e4b1b22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 38 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/6132.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cleanup Image widget and pass down onSelectItem prop if any @sneridagh
29 changes: 1 addition & 28 deletions packages/volto/src/components/manage/Blocks/Image/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
*/

import React from 'react';
import { connect } from 'react-redux';
import { compose } from 'redux';

import { injectIntl } from 'react-intl';
import cx from 'classnames';
import { ImageSidebar, SidebarPortal } from '@plone/volto/components';
import { createContent } from '@plone/volto/actions';

import {
flattenToAppURL,
Expand All @@ -21,18 +16,6 @@ import config from '@plone/volto/registry';

import { ImageInput } from '@plone/volto/components/manage/Widgets/ImageWidget';

/**
* Edit image block function.
* @function Edit
*/

// const messages = defineMessages({
// notImage: {
// id: 'The provided link does not lead to an image.',
// defaultMessage: 'The provided link does not lead to an image.',
// },
// });

function Edit(props) {
const { data } = props;
const Image = config.getComponent({ name: 'Image' }).component;
Expand Down Expand Up @@ -120,14 +103,4 @@ function Edit(props) {
);
}

export default compose(
injectIntl,
withBlockExtensions,
connect(
(state, ownProps) => ({
request: state.content.subrequests[ownProps.block] || {},
content: state.content.subrequests[ownProps.block]?.data,
}),
{ createContent },
),
)(Edit);
export default withBlockExtensions(Edit);
20 changes: 10 additions & 10 deletions packages/volto/src/components/manage/Widgets/ImageWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const UnconnectedImageInput = (props) => {
objectBrowserPickerType = 'image',
description,
placeholderLinkInput = '',
onSelectItem,
} = props;

const intl = useIntl();
Expand Down Expand Up @@ -204,16 +205,15 @@ const UnconnectedImageInput = (props) => {
e.preventDefault();
openObjectBrowser({
mode: objectBrowserPickerType,
onSelectItem: (
url,
{ title, image_field, image_scales },
) => {
onChange(props.id, flattenToAppURL(url), {
title,
image_field,
image_scales,
});
},
onSelectItem: onSelectItem
? onSelectItem
: (url, { title, image_field, image_scales }) => {
onChange(props.id, flattenToAppURL(url), {
title,
image_field,
image_scales,
});
},
currentPath: contextUrl,
});
}}
Expand Down

0 comments on commit e4b1b22

Please sign in to comment.