Skip to content

Commit

Permalink
[form-builder] Always show edit button when hotspot tool is enabled (#…
Browse files Browse the repository at this point in the history
…498)

The edit button only appeared on image fields when there were one or more fields defined on the image type, even if hotspot: true was set.
  • Loading branch information
bjoerge committed Jan 28, 2018
1 parent 53d5554 commit ca90134
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions packages/@sanity/form-builder/src/inputs/Image/ImageInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,16 @@ export default class ImageInput extends React.PureComponent<Props, State> {
})
}

renderAdvancedEdit(fields: Array<FieldT>) {
const {value, level, onChange, type, materialize} = this.props
isImageToolEnabled() {
return get(this.props.type, 'options.hotspot') === true
}

const isImageToolEnabled = get(type, 'options.hotspot') === true
renderAdvancedEdit(fields: Array<FieldT>) {
const {value, level, onChange, materialize} = this.props

return (
<Dialog title="Edit details" onClose={this.handleStopAdvancedEdit} isOpen>
{isImageToolEnabled && value && value.asset && (
{this.isImageToolEnabled() && value && value.asset && (
<WithMaterializedReference materialize={materialize} reference={value.asset}>
{imageAsset => <ImageToolInput level={level} imageUrl={imageAsset.url} value={value} onChange={onChange} />}
</WithMaterializedReference>
Expand Down Expand Up @@ -308,6 +310,8 @@ export default class ImageInput extends React.PureComponent<Props, State> {

const hasAsset = value && value.asset

const showAdvancedEditButton = value && (otherFields.length > 0 || this.isImageToolEnabled())

return (
<UploadTargetFieldset
legend={type.title}
Expand Down Expand Up @@ -358,7 +362,7 @@ export default class ImageInput extends React.PureComponent<Props, State> {
<Button onClick={this.handleOpenSelectAsset} kind="simple">
Select from library
</Button>
{value && otherFields.length > 0 && (
{showAdvancedEditButton && (
<Button
icon={EditIcon}
kind="simple"
Expand Down
3 changes: 2 additions & 1 deletion packages/test-studio/schemas/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default {
{
name: 'image',
title: 'Image',
type: 'image'
type: 'image',
options: {hotspot: true}
},
{
name: 'awards',
Expand Down

0 comments on commit ca90134

Please sign in to comment.