import { getProp , cloneObject } from "@esri/hub-common" ; import { IInitiativeModel } from "@esri/hub-common" ; param model protected export function upgradeToTwoDotTwo ( model ) { const clone = cloneObject ( model ) as IInitiativeModel ; const steps = getProp ( clone , "data.steps" ) ; const templateIdsFromSteps = getTemplateIdsFromSteps ( steps ) ; const recommendedTemplates = getProp ( clone , "data.recommendedTemplates" ) || [ ] ; const allTemplateIds = templateIdsFromSteps . concat ( recommendedTemplates ) ; clone . data . recommendedTemplates = allTemplateIds . reduce ( ( acc , id ) => { if ( acc . indexOf ( id ) < 0 ) { acc . push ( id ) ; } return acc ; } , [ ] ) ; return clone ; } param steps function getTemplateIdsFromSteps ( steps ) { let templateIds = [ ] ; if ( Array . isArray ( steps ) ) { templateIds = steps . reduce ( ( acc , step ) => { if ( getProp ( step , "templateIds.length" ) ) { return acc . concat ( step . templateIds ) ; } return acc ; } , [ ] ) ; } return templateIds ; }