Don't update the card if the property or description didn't change (#1092)
* Not updating card when property or discription is not changed * Added tests Co-authored-by: Hossein <hahmadia@users.noreply.github.com>
This commit is contained in:
parent
b58497e2ea
commit
609b69ec53
3 changed files with 45 additions and 1 deletions
|
@ -25,7 +25,9 @@ const TextElement = React.memo((props: Props): JSX.Element => {
|
|||
text={block.title}
|
||||
placeholderText={intl.formatMessage({id: 'ContentBlock.editText', defaultMessage: 'Edit text...'})}
|
||||
onBlur={(text) => {
|
||||
mutator.changeTitle(block.id, block.title, text, intl.formatMessage({id: 'ContentBlock.editCardText', defaultMessage: 'edit card text'}))
|
||||
if (text !== block.title) {
|
||||
mutator.changeTitle(block.id, block.title, text, intl.formatMessage({id: 'ContentBlock.editCardText', defaultMessage: 'edit card text'}))
|
||||
}
|
||||
}}
|
||||
readonly={readonly}
|
||||
/>
|
||||
|
|
35
webapp/src/mutator.test.ts
Normal file
35
webapp/src/mutator.test.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import mutator from './mutator'
|
||||
import {TestBlockFactory} from './test/testBlockFactory'
|
||||
import 'isomorphic-fetch'
|
||||
import {FetchMock} from './test/fetchMock'
|
||||
import {mockDOM} from './testUtils'
|
||||
|
||||
global.fetch = FetchMock.fn
|
||||
|
||||
beforeEach(() => {
|
||||
FetchMock.fn.mockReset()
|
||||
})
|
||||
|
||||
beforeAll(() => {
|
||||
mockDOM()
|
||||
})
|
||||
|
||||
describe('Mutator', () => {
|
||||
test('changePropertyValue', async () => {
|
||||
const card = TestBlockFactory.createCard()
|
||||
card.fields.properties.property_1 = 'hello'
|
||||
|
||||
await mutator.changePropertyValue(card, 'property_1', 'hello')
|
||||
|
||||
// No API call should be made as property value DIDN'T CHANGE
|
||||
expect(FetchMock.fn).toBeCalledTimes(0)
|
||||
|
||||
await mutator.changePropertyValue(card, 'property_1', 'hello world')
|
||||
|
||||
// 1 API call should be made as property value DID CHANGE
|
||||
expect(FetchMock.fn).toBeCalledTimes(1)
|
||||
})
|
||||
})
|
|
@ -367,6 +367,13 @@ class Mutator {
|
|||
}
|
||||
|
||||
async changePropertyValue(card: Card, propertyId: string, value?: string | string[], description = 'change property') {
|
||||
const oldValue = card.fields.properties[propertyId]
|
||||
|
||||
// dont save anything if property value was not changed.
|
||||
if (oldValue === value) {
|
||||
return
|
||||
}
|
||||
|
||||
const newCard = createCard(card)
|
||||
if (value) {
|
||||
newCard.fields.properties[propertyId] = value
|
||||
|
|
Loading…
Reference in a new issue