Skip to content

Commit

Permalink
fixed error adding geometry extra prop to category item
Browse files Browse the repository at this point in the history
  • Loading branch information
SteRiccio committed Dec 1, 2024
1 parent a8bff39 commit 7515768
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,32 @@ import * as Validation from '@core/validation/validation'
import { FormItem, Input, NumberFormats } from '@webapp/components/form/Input'
import SrsDropdown from '@webapp/components/survey/SrsDropdown'
import { useI18n } from '@webapp/store/system'
import { useSurveySrsIndex } from '@webapp/store/survey'

const numericFields = ['x', 'y']

const parsePoint = ({ value, srsIndex }) => {
const srssArray = Object.values(srsIndex)
const surveyUniqueSrs = srssArray.length === 1 ? srssArray[0] : null
const surveyUniqueSrsCode = surveyUniqueSrs?.code
const point = Points.parse(value) ?? {}
// assing unique srs as default, if any
point.srs = point.srs ?? surveyUniqueSrsCode
return point
}

const GeometryPointExtraPropEditor = (props) => {
const { extraPropKey, item, readOnly, updateProp, validation } = props

const srsIndex = useSurveySrsIndex()

const value = CategoryItem.getExtraProp(extraPropKey)(item)

const point = Points.parse(value) || {}
const point = parsePoint({ value, srsIndex })
const { x, y, srs } = point

const onFieldChange = (field) => (value) => {
const pointUpdated = { ...point, [field]: ['x', 'y'].includes(field) ? Number(value) : value }
const pointUpdated = { ...point, [field]: numericFields.includes(field) ? Number(value) : value }
const extra = A.pipe(CategoryItem.getExtra, A.assoc(extraPropKey, pointUpdated))(item)
updateProp({ key: CategoryItem.keysProps.extra, value: extra })
}
Expand Down

0 comments on commit 7515768

Please sign in to comment.