Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/core/components/content-type.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { fromJS } from "immutable"
const noop = ()=>{}

export default class ContentType extends React.Component {

static propTypes = {
ariaControls: PropTypes.string,
contentTypes: PropTypes.oneOfType([ImPropTypes.list, ImPropTypes.set, ImPropTypes.seq]),
Expand All @@ -24,38 +23,51 @@ export default class ContentType extends React.Component {
}

componentDidMount() {
// Needed to populate the form, initially
if(this.props.contentTypes) {
this.props.onChange(this.props.contentTypes.first())
// Populate the form initially
const { contentTypes, onChange } = this.props
if (contentTypes && contentTypes.size) {
onChange(contentTypes.first())
}
}

UNSAFE_componentWillReceiveProps(nextProps) {
if(!nextProps.contentTypes || !nextProps.contentTypes.size) {
componentDidUpdate(prevProps) {
const { contentTypes, value, onChange } = this.props

if (!contentTypes || !contentTypes.size) {
return
}

if(!nextProps.contentTypes.includes(nextProps.value)) {
nextProps.onChange(nextProps.contentTypes.first())
if (contentTypes !== prevProps.contentTypes || !contentTypes.includes(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional condition seems to be causing infinite re-renders, at least when testing it locally, as contentTypes is not of a primitive type.

Suggested change
if (contentTypes !== prevProps.contentTypes || !contentTypes.includes(value)) {
if (!contentTypes.includes(value)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I've made the changes and think I've removed everything unrelated to the issue.

onChange(contentTypes.first())
}
}

onChangeWrapper = e => this.props.onChange(e.target.value)
onChangeWrapper = (e) => this.props.onChange(e.target.value)

render() {
let { ariaControls, ariaLabel, className, contentTypes, controlId, value } = this.props
const { ariaControls, ariaLabel, className, contentTypes, controlId, value } = this.props

if ( !contentTypes || !contentTypes.size )
if (!contentTypes || !contentTypes.size)
return null

return (
<div className={ "content-type-wrapper " + ( className || "" ) }>
<select aria-controls={ariaControls} aria-label={ariaLabel} className="content-type" id={controlId} onChange={this.onChangeWrapper} value={value || ""} >
{ contentTypes.map( (val) => {
return <option key={ val } value={ val }>{ val }</option>
}).toArray()}
<div className={`content-type-wrapper ${className || ""}`}>
<select
aria-controls={ariaControls}
aria-label={ariaLabel}
className="content-type"
id={controlId}
onChange={this.onChangeWrapper}
value={value || ""}
>
{contentTypes.map((val) => (
<option key={ val } value={ val }>
{ val }
</option>
)).toArray()}
</select>
</div>
)
}
}

}
12 changes: 6 additions & 6 deletions src/core/containers/OperationContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ export default class OperationContainer extends PureComponent {
}
}

UNSAFE_componentWillReceiveProps(nextProps) {
const { response, isShown } = nextProps
componentDidUpdate(prevProps) {
const { response, isShown } = this.props
const resolvedSubtree = this.getResolvedSubtree()

if(response !== this.props.response) {
if (response !== prevProps.response) {
this.setState({ executeInProgress: false })
}

if(isShown && resolvedSubtree === undefined) {
if (isShown && resolvedSubtree === undefined && !prevProps.isShown) {
this.requestResolvedSubtree()
}
}
Expand Down