Skip to content

Commit

Permalink
Fixed error cloning survey with missing node defs in layout prop (#3173)
Browse files Browse the repository at this point in the history
* node defs fetch: filter out invalid node defs

* use latest arena-core version

* layout adjustments

---------

Co-authored-by: Stefano Ricci <[email protected]>
  • Loading branch information
SteRiccio and SteRiccio authored Dec 1, 2023
1 parent 43efc9f commit d637c11
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"@mui/material": "^5.14.18",
"@mui/x-data-grid": "^6.18.1",
"@mui/x-date-pickers": "^6.18.1",
"@openforis/arena-core": "^0.0.177",
"@openforis/arena-core": "^0.0.178",
"@openforis/arena-server": "^0.1.31",
"@sendgrid/mail": "^7.7.0",
"@shopify/draggable": "^1.1.3",
Expand Down
15 changes: 14 additions & 1 deletion server/modules/nodeDef/manager/nodeDefManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ export const insertNodeDef = async (

export { fetchNodeDefByUuid } from '../repository/nodeDefRepository'

const _filterOutInvalidNodeDefs = (nodeDefsByUuid) => {
Object.values(nodeDefsByUuid).forEach((nodeDef) => {
const parentUuid = NodeDef.getParentUuid(nodeDef)
// invalid parent UUID
if (parentUuid && !nodeDefsByUuid[parentUuid]) {
delete nodeDefsByUuid[NodeDef.getUuid(nodeDef)]
}
})
return nodeDefsByUuid
}

export const fetchNodeDefsBySurveyId = async (
{
surveyId,
Expand All @@ -140,7 +151,9 @@ export const fetchNodeDefsBySurveyId = async (
{ surveyId, cycle, draft, advanced, includeDeleted, backup, includeAnalysis },
client
)
return ObjectUtils.toUuidIndexedObj(nodeDefsDb)
const nodeDefsByUuid = ObjectUtils.toUuidIndexedObj(nodeDefsDb)

return _filterOutInvalidNodeDefs(nodeDefsByUuid)
}

// ======= UPDATE
Expand Down
2 changes: 2 additions & 0 deletions webapp/components/survey/SurveyCreate/SurveyCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ const SurveyCreate = (props) => {
{cloneFrom?.cycles?.length > 1 && (
<FormItem label={i18n.t('common.cycle')}>
<Dropdown
className="cycle-dropdown"
items={cloneFrom.cycles}
itemValue={(cycleKey) => cycleKey}
itemLabel={RecordCycle.getLabel}
onChange={(cycleKey) => onUpdate({ name: 'cloneFromCycle', value: cycleKey })}
selection={cloneFromCycle}
validation={Validation.getFieldValidation('cloneFromCycle')(validation)}
/>
</FormItem>
)}
Expand Down
4 changes: 4 additions & 0 deletions webapp/components/survey/SurveyCreate/SurveyCreate.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
.options-fieldset {
height: fit-content;
}

.cycle-dropdown {
width: 10rem;
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2619,10 +2619,10 @@
proj4 "^2.9.0"
uuid "^9.0.1"

"@openforis/arena-core@^0.0.177":
version "0.0.177"
resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.177/776236259e85e04c101880f05cb5764dcb00cc45#776236259e85e04c101880f05cb5764dcb00cc45"
integrity sha512-E72BndII2IhnQ7hsGSkehTeO0qKN1lw+v6sYB8NvZx29vKtTGLnIx/lMtNVc8TpKLPhYJhb7kVOOQMyYIt3vGw==
"@openforis/arena-core@^0.0.178":
version "0.0.178"
resolved "https://npm.pkg.github.com/download/@openforis/arena-core/0.0.178/b11db96e34c406cb3e47663d93d8bc3e0d3245fd#b11db96e34c406cb3e47663d93d8bc3e0d3245fd"
integrity sha512-7nOuJfvm3IozpevBo1nYaG0FyNjZmBq/mphI+/qT7XjRNEDjd+2eBbijBalBsdnl3OXtk0MRPiPQQLSqEf8BVQ==
dependencies:
"@jsep-plugin/regex" "^1.0.3"
bignumber.js "^9.1.2"
Expand Down

0 comments on commit d637c11

Please sign in to comment.