@@ -2,7 +2,7 @@ import { IconMore16, colors } from '@dhis2/ui'
22import { useIsMutating } from '@tanstack/react-query'
33import cx from 'classnames'
44import PropTypes from 'prop-types'
5- import React , { useEffect } from 'react'
5+ import React from 'react'
66import { useField } from 'react-final-form'
77import {
88 mutationKeys as dataValueMutationKeys ,
@@ -50,8 +50,6 @@ export function InnerWrapper({
5050 fieldname,
5151 deId,
5252 cocId,
53- syncStatus,
54- setSyncStatus,
5553} ) {
5654 const hasComment = useValueStore ( ( state ) =>
5755 state . hasComment ( {
@@ -63,34 +61,17 @@ export function InnerWrapper({
6361 const highlighted = item && deId === item . de . id && cocId === item . coc . id
6462 const {
6563 input : { value } ,
66- meta : { invalid, active, dirty } ,
64+ meta : { invalid, active, data } ,
6765 } = useField ( fieldname , {
6866 subscription : {
6967 value : true ,
7068 invalid : true ,
7169 active : true ,
7270 dirty : true ,
71+ data : true ,
7372 } ,
7473 } )
75- useEffect (
76- ( ) =>
77- setSyncStatus ( ( prev ) => ( {
78- ...prev ,
79- lastSyncedValue : value ,
80- } ) ) ,
81- // eslint-disable-next-line react-hooks/exhaustive-deps
82- [ setSyncStatus ]
83- )
84- // clear sync-status when field changes
85- useEffect ( ( ) => {
86- const { synced, lastSyncedValue } = syncStatus
87- if ( synced && lastSyncedValue !== value ) {
88- setSyncStatus ( ( prev ) => ( { ...prev , synced : false } ) )
89- } else if ( ! synced && dirty && lastSyncedValue === value ) {
90- setSyncStatus ( ( prev ) => ( { ...prev , synced : true } ) )
91- }
92- } , [ value , syncStatus , setSyncStatus , dirty ] )
93-
74+ const synced = data . lastSyncedValue === value
9475 // Detect if this field is sending data
9576 const dataValueParams = useDataValueParams ( { deId, cocId } )
9677 const activeMutations = useIsMutating ( {
@@ -101,7 +82,7 @@ export function InnerWrapper({
10182 // see https://dhis2.atlassian.net/browse/TECH-1316
10283 const cellStateClassName = invalid
10384 ? styles . invalid
104- : activeMutations === 0 && syncStatus . synced
85+ : activeMutations === 0 && synced
10586 ? styles . synced
10687 : null
10788
@@ -117,7 +98,7 @@ export function InnerWrapper({
11798 { children }
11899 < SyncStatusIndicator
119100 isLoading = { activeMutations > 0 }
120- isSynced = { syncStatus . synced }
101+ isSynced = { synced }
121102 />
122103 < CommentIndicator hasComment = { hasComment } />
123104 </ div >
@@ -130,9 +111,4 @@ InnerWrapper.propTypes = {
130111 disabled : PropTypes . bool ,
131112 fieldname : PropTypes . string ,
132113 locked : PropTypes . bool ,
133- setSyncStatus : PropTypes . func ,
134- syncStatus : PropTypes . shape ( {
135- lastSyncedValue : PropTypes . any ,
136- synced : PropTypes . bool ,
137- } ) ,
138114}
0 commit comments