import { getProp } from "@esri/hub-common" ; import { ICard } from "./types" ; function getPaths ( componentName ) { switch ( componentName ) { case "webmap-card" : return [ "component.settings.webmap" ] ; case "survey-card" : return [ "component.settings.surveyId" ] ; case "app-card" : return [ "component.settings.itemId" ] ; case "summary-statistic-card" : return [ "component.settings.itemId" ] ; case "items/gallery-card" : return [ "component.settings.ids" ] ; default : return [ ] ; } } param { ICard } card export function getCardDependencies ( card ) { const componentName = getProp ( card , "component.name" ) ; const paths = getPaths ( componentName ) ; return paths . reduce ( collectAndFlattenPropertyValues ( card ) , [ ] ) ; } function collectAndFlattenPropertyValues ( card ) { return ( acc , path ) => { const propertyValue = getProp ( card , path ) ; if ( ! propertyValue ) { return acc ; } if ( Array . isArray ( propertyValue ) ) { return acc . concat ( propertyValue ) ; } else { return acc . concat ( [ propertyValue ] ) ; } } ; }