Skip to content

aBug/10212 refactor unsafe components #10373

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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)) {
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
2 changes: 1 addition & 1 deletion src/core/plugins/view/root-injects.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from "react"
import ReactDOM from "react-dom"
import ReactDOM from "react-dom/client"
import { compose } from "redux"
import { connect, Provider } from "react-redux"
import omit from "lodash/omit"
Expand Down