From 498f0ca219ed7e9aff497042ce34744b7b7461f3 Mon Sep 17 00:00:00 2001 From: Konstantin Schaper Date: Thu, 10 Sep 2020 10:48:37 +0200 Subject: [PATCH 1/3] update filter value on props change --- scm-ui/ui-components/src/forms/FilterInput.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scm-ui/ui-components/src/forms/FilterInput.tsx b/scm-ui/ui-components/src/forms/FilterInput.tsx index 9c77f50d0f..c891ffd786 100644 --- a/scm-ui/ui-components/src/forms/FilterInput.tsx +++ b/scm-ui/ui-components/src/forms/FilterInput.tsx @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -import React, { ChangeEvent, FormEvent } from "react"; -import { WithTranslation, withTranslation } from "react-i18next"; +import React, {ChangeEvent, FormEvent} from "react"; +import {WithTranslation, withTranslation} from "react-i18next"; import styled from "styled-components"; -import { createAttributesForTesting } from "../devBuild"; +import {createAttributesForTesting} from "../devBuild"; type Props = WithTranslation & { filter: (p: string) => void; @@ -59,6 +59,16 @@ class FilterInput extends React.Component { event.preventDefault(); }; + componentDidUpdate = (prevProps: Props) => { + const { value } = this.props; + const { value: stateValue } = this.state; + if (prevProps.value !== value && value !== stateValue) { + this.setState({ + value: value || "" + }); + } + }; + render() { const { t, testId } = this.props; return ( From 4c274bdc592806f3d311527aa435d3fe9ccada02 Mon Sep 17 00:00:00 2001 From: Konstantin Schaper Date: Thu, 10 Sep 2020 10:53:18 +0200 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c862e998c5..35553a8c8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Redirection to requested page after login in anonymous mode +- Update filter state on property change ([#1327](https://github.com/scm-manager/scm-manager/pull/1327)) ## [2.4.1] - 2020-09-01 ### Added From d32a2f14909b3f1c01afc685d1d4ad8eb81879e3 Mon Sep 17 00:00:00 2001 From: Konstantin Schaper Date: Thu, 10 Sep 2020 11:26:47 +0200 Subject: [PATCH 3/3] clarify variable naming --- scm-ui/ui-components/src/forms/FilterInput.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scm-ui/ui-components/src/forms/FilterInput.tsx b/scm-ui/ui-components/src/forms/FilterInput.tsx index c891ffd786..fad1611c00 100644 --- a/scm-ui/ui-components/src/forms/FilterInput.tsx +++ b/scm-ui/ui-components/src/forms/FilterInput.tsx @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -import React, {ChangeEvent, FormEvent} from "react"; -import {WithTranslation, withTranslation} from "react-i18next"; +import React, { ChangeEvent, FormEvent } from "react"; +import { WithTranslation, withTranslation } from "react-i18next"; import styled from "styled-components"; -import {createAttributesForTesting} from "../devBuild"; +import { createAttributesForTesting } from "../devBuild"; type Props = WithTranslation & { filter: (p: string) => void; @@ -59,12 +59,12 @@ class FilterInput extends React.Component { event.preventDefault(); }; - componentDidUpdate = (prevProps: Props) => { - const { value } = this.props; + componentDidUpdate = ({ value: oldValue }: Props) => { + const { value: newValue } = this.props; const { value: stateValue } = this.state; - if (prevProps.value !== value && value !== stateValue) { + if (oldValue !== newValue && newValue !== stateValue) { this.setState({ - value: value || "" + value: newValue || "" }); } };