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

[Canvas] Refactor Canvas to no longer use componentWillReceiveProps #52129

Merged
merged 8 commits into from
Dec 30, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ export const DatetimeInput = compose<ComponentProps, Props>(
moment ? moment.format('YYYY-MM-DD HH:mm:ss') : ''
),
lifecycle<Props & ComponentProps, {}>({
// TODO: Refactor to no longer use componentWillReceiveProps since it is being deprecated
componentWillReceiveProps({ moment, setStrValue, setValid }) {
if (!moment) return;
componentDidUpdate(prevProps) {
const prevMoment = prevProps.moment;

if (this.props.moment && this.props.moment.isSame(moment)) {
// If we don't have a current moment, do nothing
if (!this.props.moment) return;

// If we previously had a moment and it's the same as the current moment, do nothing
if (prevMoment && prevMoment.isSame(this.props.moment)) {
return;
}
setStrValue(moment.format('YYYY-MM-DD HH:mm:ss'));
setValid(true);

// Set the string value of the current moment and mark as valid
this.props.setStrValue(this.props.moment.format('YYYY-MM-DD HH:mm:ss'));
this.props.setValid(true);
},
})
)(Component);
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ export class TimePicker extends Component<Props, State> {
isDirty: false,
};

// TODO: Refactor to no longer use componentWillReceiveProps since it is being deprecated
UNSAFE_componentWillReceiveProps({ from, to }: Props) {
if (from !== this.props.from || to !== this.props.to) {
componentDidUpdate(prevProps: Props) {
const { to, from } = this.props;

if (prevProps.from !== from || prevProps.to !== to) {
this.setState({
range: { from, to },
isDirty: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
};

const expressionLifecycle = lifecycle({
componentWillReceiveProps({ formState, setFormState, expression }) {
if (this.props.expression !== expression && expression !== formState.expression) {
setFormState({
expression,
dirty: false,
});
}
},
componentDidMount() {
const { functionDefinitionsPromise, setFunctionDefinitions } = this.props;
functionDefinitionsPromise.then(defs => setFunctionDefinitions(defs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const Toolbar = (props: Props) => {

const trays = {
pageManager: <PageManager previousPage={previousPage} />,
expression: !elementIsSelected ? null : <Expression done={done} />,
expression: !elementIsSelected ? null : <Expression key={selectedElement.id} done={done} />,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const EnhancedExtendedTemplate = compose<ExtendedTemplateProps, Props>(
this.props.setLabel(formatLabel(label, this.props));
}
},
componentWillReceiveProps(newProps) {
const newLabel = get(newProps.argValue, 'chain.0.arguments.label.0', '');
if (newLabel && this.props.label !== formatLabel(newLabel, this.props)) {
componentDidUpdate(prevProps) {
const newLabel = get(this.props.argValue, 'chain.0.arguments.label.0', '');
if (newLabel && prevProps.label !== formatLabel(newLabel, this.props)) {
this.props.setLabel(formatLabel(newLabel, this.props));
}
},
Expand Down