Skip to content

Commit

Permalink
fixed error adding new geometry extra prop to category item (#3676)
Browse files Browse the repository at this point in the history
* fixed error adding geometry extra prop to category item

* code cleanup

* use latest arena-core

* code cleanup

---------

Co-authored-by: Stefano Ricci <[email protected]>
  • Loading branch information
SteRiccio and SteRiccio authored Dec 1, 2024
1 parent a8bff39 commit a9c7ffa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"@mui/x-data-grid": "^7.14.0",
"@mui/x-date-pickers": "^7.14.0",
"@mui/x-tree-view": "^7.7.1",
"@openforis/arena-core": "^1.0.4",
"@openforis/arena-core": "^1.0.6",
"@openforis/arena-server": "^0.1.36",
"@reduxjs/toolkit": "^2.2.5",
"@sendgrid/mail": "^8.1.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'

import { Points } from '@openforis/arena-core'
import { Numbers, Objects, Points } from '@openforis/arena-core'

import * as A from '@core/arena'
import { ExtraPropDef } from '@core/survey/extraPropDef'
Expand All @@ -10,17 +11,35 @@ 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 pointNumericFields = ['x', 'y']

const parsePoint = ({ value, srsIndex }) => {
const srssArray = Object.values(srsIndex)
const surveyDefaultSrs = srssArray.length > 0 ? srssArray[0] : null
const surveyDefaultSrsCode = surveyDefaultSrs?.code
const point = Points.parse(value) ?? {}
// assing default (first) srs if missing in parsed point
point.srs = point.srs ?? surveyDefaultSrsCode
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 }
let pointUpdated = { ...point, [field]: pointNumericFields.includes(field) ? Numbers.toNumber(value) : value }
if (Objects.isEmpty(pointUpdated.x) && Objects.isEmpty(pointUpdated.y)) {
pointUpdated = null
}
const extra = A.pipe(CategoryItem.getExtra, A.assoc(extraPropKey, pointUpdated))(item)
updateProp({ key: CategoryItem.keysProps.extra, value: extra })
}
Expand Down Expand Up @@ -58,6 +77,14 @@ const GeometryPointExtraPropEditor = (props) => {
)
}

GeometryPointExtraPropEditor.propTypes = {
extraPropKey: PropTypes.string.isRequired,
item: PropTypes.object,
readOnly: PropTypes.bool,
updateProp: PropTypes.func.isRequired,
validation: PropTypes.object,
}

export const ItemExtraPropsEditor = (props) => {
const { item, itemExtraDefs, readOnly, updateProp, validation } = props

Expand Down Expand Up @@ -94,3 +121,11 @@ export const ItemExtraPropsEditor = (props) => {
</fieldset>
)
}

ItemExtraPropsEditor.propTypes = {
item: PropTypes.object,
itemExtraDefs: PropTypes.object.isRequired,
readOnly: PropTypes.bool,
updateProp: PropTypes.func.isRequired,
validation: PropTypes.object,
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2777,10 +2777,10 @@
proj4 "^2.11.0"
uuid "^10.0.0"

"@openforis/arena-core@^1.0.4":
version "1.0.4"
resolved "https://npm.pkg.github.com/download/@openforis/arena-core/1.0.4/08109df89518dd545ff0d222b00d56ba7f10b256#08109df89518dd545ff0d222b00d56ba7f10b256"
integrity sha512-56GlwLn87xOhi7GGwNkDdsPGEbIHlhWU/oXbP/gsHWCUX7+CVTQEc4h+UEZbvSb0qzxIZhIn+dxD6QmieOTmCg==
"@openforis/arena-core@^1.0.6":
version "1.0.6"
resolved "https://npm.pkg.github.com/download/@openforis/arena-core/1.0.6/5c9eccfc9d5c378481aac3149de7215cb1f35541#5c9eccfc9d5c378481aac3149de7215cb1f35541"
integrity sha512-C+VfJUe0IdBkX/8j/7kQZTMZ0p9vlqsDqu3XdxW7cTfXuHjLmW6GWKf3p8P6LbZ9tLt8pNRWbNkFk2/w7Q97Yw==
dependencies:
"@jsep-plugin/regex" "^1.0.3"
bignumber.js "^9.1.2"
Expand Down

0 comments on commit a9c7ffa

Please sign in to comment.