import { ReactElement , FunctionComponent } from 'react' ; import type { LayerDescriptor } from '../../../../common/descriptor_types' ; import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants' ; export type LayerWizard = { title : string ; categories : LAYER_WIZARD_CATEGORY [ ] ; order : number ; description : string ; icon : string | FunctionComponent < any > ; renderWizard ( renderWizardArguments ) : ReactElement < any > ; prerequisiteSteps ? : Array < { id : string ; label : string ; } > ; disabledReason ? : string ; getIsDisabled ? : ( ) => Promise < boolean > | boolean ; isBeta ? : boolean ; checkVisibility ? : ( ) => Promise < boolean > ; showFeatureEditTools ? : boolean ; } ; export type RenderWizardArguments = { previewLayers : ( layerDescriptors : LayerDescriptor [ ] ) => void ; mapColors : string [ ] ; currentStepId : string | null ; isOnFinalStep : boolean ; enableNextBtn : ( ) => void ; disableNextBtn : ( ) => void ; startStepLoading : ( ) => void ; stopStepLoading : ( ) => void ; advanceToNextStep : ( ) => void ; } ; export type LayerWizardWithMeta = LayerWizard & { isVisible : boolean ; isDisabled : boolean ; } ; const registry = [ ] ; export function registerLayerWizardInternal ( layerWizard ) { registry . push ( { checkVisibility : async ( ) => { return true ; } , getIsDisabled : async ( ) => { return false ; } , isBeta : false , ... layerWizard , } ) ; } export function registerLayerWizardExternal ( layerWizard ) { if ( layerWizard . order < 100 ) { throw new Error ( `layerWizard.order should be greater than or equal to '100'` ) ; } registerLayerWizardInternal ( layerWizard ) ; } export async function getLayerWizards ( ) { const promises = registry . map ( async ( layerWizard ) => { return { ... layerWizard , isVisible : await layerWizard . checkVisibility ! ( ) , isDisabled : await layerWizard . getIsDisabled ! ( ) , } ; } ) ; return ( await Promise . all ( promises ) ) . filter ( ( { isVisible } ) => { return isVisible ; } ) . sort ( ( wizard1 , wizard2 ) => { return wizard1 . order - wizard2 . order ; } ) ; }