Skip to content

Commit b8046c7

Browse files
[Canvas] Refactor Canvas to no longer use componentWillReceiveProps (#52129)
* Removing componentWillReceiveProps from time filter * Changing expression form to componentDidUpdate * Updating expression to be key-driven updates and arg_types to use compomentDidUpdate * temporary * Revert "temporary" This reverts commit 255525d. * typo fix Co-authored-by: Elastic Machine <[email protected]>
1 parent 6765def commit b8046c7

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

x-pack/legacy/plugins/canvas/canvas_plugin_src/renderers/time_filter/components/datetime_input/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ export const DatetimeInput = compose<ComponentProps, Props>(
2121
moment ? moment.format('YYYY-MM-DD HH:mm:ss') : ''
2222
),
2323
lifecycle<Props & ComponentProps, {}>({
24-
// TODO: Refactor to no longer use componentWillReceiveProps since it is being deprecated
25-
componentWillReceiveProps({ moment, setStrValue, setValid }) {
26-
if (!moment) return;
24+
componentDidUpdate(prevProps) {
25+
const prevMoment = prevProps.moment;
2726

28-
if (this.props.moment && this.props.moment.isSame(moment)) {
27+
// If we don't have a current moment, do nothing
28+
if (!this.props.moment) return;
29+
30+
// If we previously had a moment and it's the same as the current moment, do nothing
31+
if (prevMoment && prevMoment.isSame(this.props.moment)) {
2932
return;
3033
}
31-
setStrValue(moment.format('YYYY-MM-DD HH:mm:ss'));
32-
setValid(true);
34+
35+
// Set the string value of the current moment and mark as valid
36+
this.props.setStrValue(this.props.moment.format('YYYY-MM-DD HH:mm:ss'));
37+
this.props.setValid(true);
3338
},
3439
})
3540
)(Component);

x-pack/legacy/plugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_picker/time_picker.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ export class TimePicker extends Component<Props, State> {
4747
isDirty: false,
4848
};
4949

50-
// TODO: Refactor to no longer use componentWillReceiveProps since it is being deprecated
51-
UNSAFE_componentWillReceiveProps({ from, to }: Props) {
52-
if (from !== this.props.from || to !== this.props.to) {
50+
componentDidUpdate(prevProps: Props) {
51+
const { to, from } = this.props;
52+
53+
if (prevProps.from !== from || prevProps.to !== to) {
5354
this.setState({
5455
range: { from, to },
5556
isDirty: false,

x-pack/legacy/plugins/canvas/public/components/expression/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
5555
};
5656

5757
const expressionLifecycle = lifecycle({
58-
componentWillReceiveProps({ formState, setFormState, expression }) {
59-
if (this.props.expression !== expression && expression !== formState.expression) {
60-
setFormState({
61-
expression,
62-
dirty: false,
63-
});
64-
}
65-
},
6658
componentDidMount() {
6759
const { functionDefinitionsPromise, setFunctionDefinitions } = this.props;
6860
functionDefinitionsPromise.then(defs => setFunctionDefinitions(defs));

x-pack/legacy/plugins/canvas/public/components/toolbar/toolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const Toolbar = (props: Props) => {
9797

9898
const trays = {
9999
pageManager: <PageManager previousPage={previousPage} />,
100-
expression: !elementIsSelected ? null : <Expression done={done} />,
100+
expression: !elementIsSelected ? null : <Expression key={selectedElement.id} done={done} />,
101101
};
102102

103103
return (

x-pack/legacy/plugins/canvas/public/expression_types/arg_types/series_style/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ const EnhancedExtendedTemplate = compose<ExtendedTemplateProps, Props>(
3737
this.props.setLabel(formatLabel(label, this.props));
3838
}
3939
},
40-
componentWillReceiveProps(newProps) {
41-
const newLabel = get(newProps.argValue, 'chain.0.arguments.label.0', '');
42-
if (newLabel && this.props.label !== formatLabel(newLabel, this.props)) {
40+
componentDidUpdate(prevProps) {
41+
const newLabel = get(this.props.argValue, 'chain.0.arguments.label.0', '');
42+
if (newLabel && prevProps.label !== formatLabel(newLabel, this.props)) {
4343
this.props.setLabel(formatLabel(newLabel, this.props));
4444
}
4545
},

0 commit comments

Comments
 (0)