From e7eae179fe06dde3f50711891a3715528e5c83b6 Mon Sep 17 00:00:00 2001 From: Jaden Diefenbaugh <jaden.diefenbaugh@idiap.ch> Date: Tue, 24 Jul 2018 11:47:42 -0700 Subject: [PATCH] [js] refactor out usage of deprecated lifecycle funcs --- conda/js/src/components/CacheInput.jsx | 14 ++++++++------ conda/js/src/components/NewEntityModal.jsx | 12 +++++++----- conda/js/src/components/SearchBar.jsx | 6 ++++-- .../src/components/algorithm/AlgorithmEditor.jsx | 10 ++++++---- .../src/components/toolchain/InsertObjectModal.jsx | 6 ++++-- .../src/components/toolchain/RenameGroupModal.jsx | 6 ++++-- .../src/components/toolchain/ToolchainEditor.jsx | 9 --------- 7 files changed, 33 insertions(+), 30 deletions(-) diff --git a/conda/js/src/components/CacheInput.jsx b/conda/js/src/components/CacheInput.jsx index a0f216a7..5d174624 100644 --- a/conda/js/src/components/CacheInput.jsx +++ b/conda/js/src/components/CacheInput.jsx @@ -87,12 +87,14 @@ class CacheInput extends React.Component<Props, State>{ this.updateValidity(this.state.cache); } - // if the parent's model changes, reset input - componentWillReceiveProps (nextProps: any) { - this.setState({ - cache: (nextProps.value), - }); - this.clearTimer(); + // if the parent's model (the props) changes, reset input + componentDidUpdate = (prevProps: Props) => { + if(this.props.value !== prevProps.value){ + this.setState({ + cache: (this.props.value), + }); + this.clearTimer(); + } } // gets the validity info of an input string given a curr val diff --git a/conda/js/src/components/NewEntityModal.jsx b/conda/js/src/components/NewEntityModal.jsx index ab9cd7e7..a1ce167a 100644 --- a/conda/js/src/components/NewEntityModal.jsx +++ b/conda/js/src/components/NewEntityModal.jsx @@ -85,11 +85,13 @@ export class NewEntityModal extends React.Component<Props, State> { numSegs: nameSegmentsForEntity(this.props.entity), } - componentWillReceiveProps = (newProps: Props) => { - this.setState({ - nameSegs: getStartNameSegs(newProps.copyObj, newProps.data.map(d => d.name), newProps.entity, newProps.nameOrVersion), - numSegs: nameSegmentsForEntity(newProps.entity), - }); + componentDidUpdate = (prevProps: Props) => { + if(this.props !== prevProps){ + this.setState({ + nameSegs: getStartNameSegs(this.props.copyObj, this.props.data.map(d => d.name), this.props.entity, this.props.nameOrVersion), + numSegs: nameSegmentsForEntity(this.props.entity), + }); + } } titleStr = () => `New ${ this.props.entity }: "${ this.getNameString() }"`; diff --git a/conda/js/src/components/SearchBar.jsx b/conda/js/src/components/SearchBar.jsx index 38b11e73..dc8e433f 100644 --- a/conda/js/src/components/SearchBar.jsx +++ b/conda/js/src/components/SearchBar.jsx @@ -54,8 +54,10 @@ class SearchBar extends React.PureComponent<Props, State> { this.updateFuseInstance(); } - componentWillReceiveProps = (nextProps: Props) => { - this.updateFuseInstance(nextProps.data); + componentDidUpdate = (prevProps: Props) => { + if(this.props.data !== prevProps.data){ + this.updateFuseInstance(this.props.data); + } } updateFuseInstance = (data: BeatObject[] = this.props.data) => { diff --git a/conda/js/src/components/algorithm/AlgorithmEditor.jsx b/conda/js/src/components/algorithm/AlgorithmEditor.jsx index 4b783206..17f5cf72 100644 --- a/conda/js/src/components/algorithm/AlgorithmEditor.jsx +++ b/conda/js/src/components/algorithm/AlgorithmEditor.jsx @@ -82,10 +82,12 @@ export class AlgorithmEditor extends React.Component<Props, State> { } // if the data changes behind the scenes, update the editor with these changes - UNSAFE_componentWillReceiveProps (nextProps: Props) { - this.setState({ - validity: this.getValidity(nextProps.data, nextProps.algorithms), - }); + componentDidUpdate = (prevProps: Props) => { + if(this.props !== prevProps){ + this.setState({ + validity: this.getValidity(this.props.data, this.props.algorithms), + }); + } } // get the result types (analyzer result types are restricted to a subset of all available types) diff --git a/conda/js/src/components/toolchain/InsertObjectModal.jsx b/conda/js/src/components/toolchain/InsertObjectModal.jsx index 0c08497a..f0ae1cd4 100644 --- a/conda/js/src/components/toolchain/InsertObjectModal.jsx +++ b/conda/js/src/components/toolchain/InsertObjectModal.jsx @@ -87,8 +87,10 @@ class InsertObjectModal extends React.PureComponent<Props, State> { this.updateFuseInstance(); } - componentWillReceiveProps = (nextProps: Props) => { - this.updateFuseInstance(nextProps[this.state.searchFilter]); + componentDidUpdate = (prevProps: Props) => { + if(this.props[this.state.searchFilter] !== prevProps[this.state.searchFilter]){ + this.updateFuseInstance(this.props[this.state.searchFilter]); + } } updateFuseInstance = (data: any[] = this.props[this.state.searchFilter]) => { diff --git a/conda/js/src/components/toolchain/RenameGroupModal.jsx b/conda/js/src/components/toolchain/RenameGroupModal.jsx index dd0c26d2..bdee3cf3 100644 --- a/conda/js/src/components/toolchain/RenameGroupModal.jsx +++ b/conda/js/src/components/toolchain/RenameGroupModal.jsx @@ -34,8 +34,10 @@ class RenameGroupModal extends React.PureComponent<Props, State> { newName: this.props.currentName, } - componentWillReceiveProps = (nextProps: Props) => { - this.setState({ newName: nextProps.currentName }); + componentDidUpdate = (prevProps: Props) => { + if(this.props.currentName !== prevProps.currentName){ + this.setState({ newName: this.props.currentName }); + } } validateFunc = (str: string) => { diff --git a/conda/js/src/components/toolchain/ToolchainEditor.jsx b/conda/js/src/components/toolchain/ToolchainEditor.jsx index 3c313e87..e6c8b87f 100644 --- a/conda/js/src/components/toolchain/ToolchainEditor.jsx +++ b/conda/js/src/components/toolchain/ToolchainEditor.jsx @@ -134,15 +134,6 @@ export class ToolchainEditor extends React.PureComponent<Props, State> { }, } - // if the toolchain was updated, reset specific state fields - UNSAFE_componentWillReceiveProps = (nextProps: Props) => { - /* - this.setState({ - history: generateNewHistory(this.state), - }); - */ - } - // helper to set the contents (this.props.data.contents) object setContents = (newContents: any) => { this.setState((prevState, props) => ({ -- GitLab