Skip to content

Commit

Permalink
fix: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Dec 3, 2024
1 parent 4fc7588 commit 33fb300
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/data-workspace/custom-form/replace-input-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const replaceInputNode = (domNode, metadata) => {
// TODO: This was already there when I started on this branch
// Need to check with Kai what his intentions were with it.
// const cellProps = getCellPropsByInputType(inputType)
// console.log(domNode)

if (inputType !== INPUT_TYPES.ENTRYFIELD) {
return undefined
}
Expand Down
9 changes: 8 additions & 1 deletion src/data-workspace/inputs/generic-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export const GenericInput = ({
}) => {
const [value, setValue] = useState(initialValue)
const [lastSyncedValue, setLastSyncedValue] = useState(initialValue)
const [syncTouched, setSyncTouched] = useState(false)

useEffect(() => {
if (syncTouched) {
setValueSynced(value === lastSyncedValue)
}
}, [value, lastSyncedValue, syncTouched])

const limits = useMinMaxLimits(deId, cocId)

Expand All @@ -75,14 +82,14 @@ export const GenericInput = ({
const { mutate } = useSetDataValueMutation({ deId, cocId })

const syncData = (newValue) => {
setSyncTouched(true)
// todo: Here's where an error state could be set: ('onError')
mutate(
// Empty values need an empty string
{ value: newValue || '' },
{
onSuccess: () => {
setLastSyncedValue(newValue)
setValueSynced(value === newValue)
},
}
)
Expand Down
11 changes: 9 additions & 2 deletions src/data-workspace/inputs/long-text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { useSetDataValueMutation } from '../../shared/index.js'
import styles from './inputs.module.css'
import { InputPropTypes } from './utils.js'
Expand All @@ -16,17 +16,24 @@ export const LongText = ({
}) => {
const [value, setValue] = useState(initialValue)
const [lastSyncedValue, setLastSyncedValue] = useState(initialValue)
const [syncTouched, setSyncTouched] = useState(false)

useEffect(() => {
if (syncTouched) {
setValueSynced(value === lastSyncedValue)
}
}, [value, lastSyncedValue, syncTouched])

const { mutate } = useSetDataValueMutation({ deId, cocId })
const syncData = (newValue) => {
setSyncTouched(true)
// todo: Here's where an error state could be set: ('onError')
mutate(
// Empty values need an empty string
{ value: newValue || '' },
{
onSuccess: () => {
setLastSyncedValue(newValue)
setValueSynced(value === newValue)
},
}
)
Expand Down
11 changes: 9 additions & 2 deletions src/data-workspace/inputs/true-only-checkbox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Checkbox } from '@dhis2/ui'
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { useSetDataValueMutation } from '../../shared/index.js'
import styles from './inputs.module.css'
import { convertBooleanValue, InputPropTypes } from './utils.js'
Expand All @@ -19,17 +19,24 @@ export const TrueOnlyCheckbox = ({
const [lastSyncedValue, setLastSyncedValue] = useState(() =>
convertBooleanValue(initialValue)
)
const [syncTouched, setSyncTouched] = useState(false)

useEffect(() => {
if (syncTouched) {
setValueSynced(value === lastSyncedValue)
}
}, [value, lastSyncedValue, syncTouched])

const { mutate } = useSetDataValueMutation({ deId, cocId })
const syncData = (newValue) => {
setSyncTouched(true)
// todo: Here's where an error state could be set: ('onError')
mutate(
// Empty values need an empty string
{ value: newValue || '' },
{
onSuccess: () => {
setLastSyncedValue(newValue)
setValueSynced(newValue === value)
},
}
)
Expand Down
3 changes: 2 additions & 1 deletion src/shared/use-blurred-field.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useRef } from 'react'
import { getFieldId } from '../data-workspace/get-field-id.js'
import { useHighlightedFieldStore } from './stores/highlighted-field-store.js'

export const useBlurredField = () => {
const previouslyActiveFieldRef = useRef(undefined)

const { dataElementId, categoryOptionComboId } =
useHighlightedFieldStore((state) => state.getHighlightedField()) || {}
const fieldId = `${dataElementId}.${categoryOptionComboId}`
const fieldId = getFieldId(dataElementId, categoryOptionComboId)

const blurredField = previouslyActiveFieldRef.current
previouslyActiveFieldRef.current = fieldId
Expand Down

0 comments on commit 33fb300

Please sign in to comment.