import IDynamicDataService from "./IDynamicDataService" ; import { DynamicDataProvider } from "@microsoft/sp-component-base" ; import { IDynamicDataSource } from "@microsoft/sp-dynamic-data" ; import IDataSourceProperty from "../../models/dynamicData/IDynamicDataSourceProperty" ; import { ServiceScope , ServiceKey } from "@microsoft/sp-core-library" ; const DynamicDataService_ServiceKey = 'PnPModernSearchDynamicDataService' ; export class DynamicDataService implements IDynamicDataService { public static ServiceKey : ServiceKey < IDynamicDataService > = ServiceKey . create ( DynamicDataService_ServiceKey , DynamicDataService ) ; private _dynamicDataProvider : DynamicDataProvider ; get dynamicDataProvider ( ) : DynamicDataProvider { return this . _dynamicDataProvider ; } set dynamicDataProvider ( value ) { this . _dynamicDataProvider = value ; } constructor ( serviceScope ) { } param propertyId public async getAvailableDataSourcesByType ( propertyId ) { let propertyOptions = [ ] ; if ( ! this . dynamicDataProvider . isDisposed ) { this . _dynamicDataProvider . getAvailableSources ( ) . forEach ( async ( sourceInfo ) => { const source = this . _dynamicDataProvider . tryGetSource ( sourceInfo . id ) ; if ( source ) { const properties = await source . getPropertyDefinitionsAsync ( ) ; properties . forEach ( prop => { if ( prop . id === propertyId ) { propertyOptions . push ( { key : `${ source . id }:${ prop . id }` , text : prop . title } ) ; } } ) ; } } ) ; } return propertyOptions ; } }