Skip to content

Commit

Permalink
use latest arena-core version (survey node defs index by name)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteRiccio committed Nov 19, 2024
1 parent 0b5cd31 commit 5f47ee9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
20 changes: 8 additions & 12 deletions core/survey/_survey/surveyNodeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ export const hasNodeDefChildrenEntities = (nodeDef) => (survey) => {
return R.pipe(getNodeDefChildren(nodeDef), R.any(NodeDef.isEntity))(survey)
}

export const getNodeDefChildByName = (nodeDef, childName) =>
R.pipe(
getNodeDefChildren(nodeDef),
R.find((childDef) => childName === NodeDef.getName(childDef))
)
export const getNodeDefChildByName = (nodeDef, childName) => (survey) =>
SurveyNodeDefsIndex.hasNodeDefsIndexByName(survey)
? Surveys.getNodeDefByName({ survey, name: childName })
: R.pipe(
getNodeDefChildren(nodeDef),
R.find((childDef) => childName === NodeDef.getName(childDef))
)(survey)

export const getNodeDefParent = (nodeDef) => (survey) => {
if (NodeDef.isRoot(nodeDef)) return null
Expand All @@ -154,11 +156,6 @@ export const getNodeDefAreaBasedEstimate = (nodeDef) => (survey) =>
export const getAreaBasedEstimatedOfNodeDef = (nodeDef) => (survey) =>
getNodeDefByUuid(NodeDef.getAreaBasedEstimatedOf(nodeDef))(survey)

export const getNodeDefSiblingByName = (nodeDef, name) => (survey) => {
const parentDef = getNodeDefParent(nodeDef)(survey)
return getNodeDefChildByName(parentDef, name)(survey)
}

const _nodeDefKeysFilter = (n) => NodeDef.isKey(n) && !NodeDef.isDeleted(n)

export const getNodeDefKeys = (nodeDef) => (survey) => getNodeDefChildren(nodeDef)(survey).filter(_nodeDefKeysFilter)
Expand All @@ -183,8 +180,7 @@ export const getNodeDefsRootUnique = (survey) => {
)
}

export const getNodeDefByName = (name) =>
R.pipe(getNodeDefsArray, R.find(R.pathEq([NodeDef.keys.props, NodeDef.propKeys.name], name)))
export const getNodeDefByName = (name) => (survey) => Surveys.getNodeDefByName({ survey, name })

export const getNodeDefsByCategoryUuid = (uuid) =>
R.pipe(getNodeDefsArray, R.filter(R.pathEq([NodeDef.keys.props, NodeDef.propKeys.categoryUuid], uuid)))
Expand Down
13 changes: 9 additions & 4 deletions core/survey/_survey/surveyNodeDefsIndex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Surveys } from '@openforis/arena-core'
import { Objects, Surveys } from '@openforis/arena-core'

// ==== READ

Expand All @@ -7,28 +7,33 @@ export const getNodeDefsIndex = (survey) => {
return nodeDefsIndex || {}
}

export const hasNodeDefsIndexByName = (survey) => {
const { nodeDefUuidByName } = getNodeDefsIndex(survey)
return Objects.isNotEmpty(nodeDefUuidByName)
}

export const assocNodeDefsIndex = ({ survey, nodeDefsIndex }) => ({ ...survey, nodeDefsIndex })

// ==== UPDATE

export const addNodeDefToIndex = ({ nodeDefsIndex, nodeDef }) => {
const surveyUpdated = Surveys.addNodeDefToIndex(nodeDef)({ nodeDefsIndex })
return surveyUpdated.nodeDefsIndex
return getNodeDefsIndex(surveyUpdated)
}

// ==== DELETE

export const deleteNodeDefIndex = ({ nodeDefsIndex, nodeDef }) => {
const survey = { nodeDefsIndex }
const surveyUpdated = Surveys.deleteNodeDefIndex(nodeDef)(survey)
return surveyUpdated.nodeDefsIndex
return getNodeDefsIndex(surveyUpdated)
}

// ==== CREATE

export const initNodeDefsIndex = (survey) => {
const surveyUpdated = Surveys.buildAndAssocNodeDefsIndex(survey)
return surveyUpdated.nodeDefsIndex
return getNodeDefsIndex(surveyUpdated)
}

export const initAndAssocNodeDefsIndex = (survey) => Surveys.buildAndAssocNodeDefsIndex(survey)
1 change: 0 additions & 1 deletion core/survey/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export const {
hasNodeDefChildrenEntities,
getNodeDefChildrenSorted,
getNodeDefChildByName,
getNodeDefSiblingByName,
getNodeDefByName,
getNodeDefsByCategoryUuid,
getNodeDefsByTaxonomyUuid,
Expand Down
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.1",
"@openforis/arena-core": "^1.0.3",
"@openforis/arena-server": "^0.1.36",
"@reduxjs/toolkit": "^2.2.5",
"@sendgrid/mail": "^8.1.3",
Expand Down
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.1":
version "1.0.1"
resolved "https://npm.pkg.github.com/download/@openforis/arena-core/1.0.1/06b493d0832c6ef31482cfd39bf35b191c5e361c#06b493d0832c6ef31482cfd39bf35b191c5e361c"
integrity sha512-qtJahu2theB1TFpIPhg3DmGwPGUTDJYxHij/tmHnPh8Mr3oqK9PrlyZ1hSoVlJ4Y6gMcTGaF2fsT8zLwGOCv1A==
"@openforis/arena-core@^1.0.3":
version "1.0.3"
resolved "https://npm.pkg.github.com/download/@openforis/arena-core/1.0.3/3efb6434dc87987ccc3c60546aa210f14f421b25#3efb6434dc87987ccc3c60546aa210f14f421b25"
integrity sha512-Gpr1gb8IoAFf742oO8Jli9aD7SQPlxii7sceyyDQedL06a1c9xaNkUEk61tXslbzYY+YqfYbkB7+XK28I2qlkw==
dependencies:
"@jsep-plugin/regex" "^1.0.3"
bignumber.js "^9.1.2"
Expand Down

0 comments on commit 5f47ee9

Please sign in to comment.