From 5b1c53dffa7bb70fbaeb2fe6040a23df12706037 Mon Sep 17 00:00:00 2001 From: Benjamin Cooke Date: Wed, 22 Feb 2023 16:21:12 -0500 Subject: [PATCH 1/3] updating date when prop has changed --- webapp/src/properties/date/date.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/webapp/src/properties/date/date.tsx b/webapp/src/properties/date/date.tsx index 23d764a1b..e2c285b5e 100644 --- a/webapp/src/properties/date/date.tsx +++ b/webapp/src/properties/date/date.tsx @@ -1,6 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React, {useMemo, useState, useCallback} from 'react' +import React, {useMemo, useState, useCallback, useEffect} from 'react' import {useIntl} from 'react-intl' import {DateUtils} from 'react-day-picker' import MomentLocaleUtils from 'react-day-picker/moment' @@ -58,6 +58,12 @@ function DateRange(props: PropertyProps): JSX.Element { const [value, setValue] = useState(propertyValue) const intl = useIntl() + useEffect(() => { + if (value !== propertyValue) { + setValue(propertyValue) + } + }, [propertyValue, setValue]) + const onChange = useCallback((newValue) => { if (value !== newValue) { setValue(newValue) From ae44d6f2bfc78d36e9060a9c52ac8945695822c9 Mon Sep 17 00:00:00 2001 From: Benjamin Cooke Date: Thu, 23 Feb 2023 14:27:52 -0500 Subject: [PATCH 2/3] unit test --- .../date/__snapshots__/date.test.tsx.snap | 17 ++++++++++ webapp/src/properties/date/date.test.tsx | 32 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/webapp/src/properties/date/__snapshots__/date.test.tsx.snap b/webapp/src/properties/date/__snapshots__/date.test.tsx.snap index 861e203c5..231f47e8a 100644 --- a/webapp/src/properties/date/__snapshots__/date.test.tsx.snap +++ b/webapp/src/properties/date/__snapshots__/date.test.tsx.snap @@ -34,6 +34,23 @@ exports[`properties/dateRange handle clear 1`] = ` `; +exports[`properties/dateRange returns component with new date after prop change 1`] = ` +
+
+ +
+
+`; + exports[`properties/dateRange returns default correctly 1`] = `
{ expect(mockedMutator.changePropertyValue).toHaveBeenCalledWith(board.id, card, propertyTemplate.id, JSON.stringify({from: today})) }) + + test('returns component with new date after prop change', () => { + const component = wrapIntl( + , + ) + + const {container, rerender} = render(component) + + rerender( + wrapIntl( + + ) + ) + + expect(container).toMatchSnapshot() + }) }) From 30c9da952efa2aff4c2c1e817cdddcb2ba1bbc09 Mon Sep 17 00:00:00 2001 From: Benjamin Cooke Date: Thu, 23 Feb 2023 15:35:04 -0500 Subject: [PATCH 3/3] lint --- webapp/src/properties/date/date.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/src/properties/date/date.test.tsx b/webapp/src/properties/date/date.test.tsx index d1989425b..dfabdf706 100644 --- a/webapp/src/properties/date/date.test.tsx +++ b/webapp/src/properties/date/date.test.tsx @@ -315,7 +315,7 @@ describe('properties/dateRange', () => { expect(mockedMutator.changePropertyValue).toHaveBeenCalledWith(board.id, card, propertyTemplate.id, JSON.stringify({from: today})) }) - + test('returns component with new date after prop change', () => { const component = wrapIntl( { board={{...board}} card={{...card}} propertyTemplate={propertyTemplate} - /> - ) + />, + ), ) expect(container).toMatchSnapshot()