import 'core-js/stable' ; import 'regenerator-runtime/runtime' ; import '../style/visual.less' ; import '../style/fabric-icons-inline.css' ; import 'jsoneditor/dist/jsoneditor.css' ; import powerbi from 'powerbi-visuals-api' ; import VisualConstructorOptions = powerbi . extensibility . visual . VisualConstructorOptions ; import VisualUpdateOptions = powerbi . extensibility . visual . VisualUpdateOptions ; import IVisual = powerbi . extensibility . visual . IVisual ; import EnumerateVisualObjectInstancesOptions = powerbi . EnumerateVisualObjectInstancesOptions ; import VisualObjectInstance = powerbi . VisualObjectInstance ; import DataView = powerbi . DataView ; import VisualObjectInstanceEnumerationObject = powerbi . VisualObjectInstanceEnumerationObject ; import IVisualHost = powerbi . extensibility . visual . IVisualHost ; import IVisualEventService = powerbi . extensibility . IVisualEventService ; import VisualUpdateType = powerbi . VisualUpdateType ; import VisualDataChangeOperationKind = powerbi . VisualDataChangeOperationKind ; import * as React from 'react' ; import * as ReactDOM from 'react-dom' ; import { loadTheme } from '@fluentui/react/lib/Styling' ; import App from './components/App' ; import VisualSettings from './properties/VisualSettings' ; import { getState } from './store' ; import { canFetchMore , getMappedDataset , handleDataFetch , validateDataViewMapping , validateDataViewRoles } from './core/data/dataView' ; import { theme } from './core/ui/fluent' ; import { parseActiveSpec } from './core/utils/specification' ; import { fillPatternServices , hostServices } from './core/services' ; import { initializeIcons } from './core/ui/fluent' ; import { getDataset , getTemplateFieldsFromMetadata } from './core/data/dataset' ; import { handlePropertyMigration } from './core/utils/versioning' ; const owner = 'Visual' ; export class Deneb implements IVisual { private settings : VisualSettings ; private container : HTMLElement ; private reactRoot : React . FunctionComponentElement < { } > ; private host : IVisualHost ; private events : IVisualEventService ; constructor ( options ) { try { loadTheme ( theme ) ; initializeIcons ( ) ; hostServices . bindHostServices ( options ) ; getState ( ) . initializeImportExport ( ) ; this . container = options . element ; this . host = options . host ; this . events = this . host . eventService ; this . reactRoot = React . createElement ( App ) ; ReactDOM . render ( this . reactRoot , this . container ) ; this . container . oncontextmenu = ( ev ) => { ev . preventDefault ( ) ; } ; fillPatternServices . setPatternContainer ( this . container ) ; } catch ( e ) { console ?. error ( 'Error' , e ) ; } } public update ( options ) { try { this . events . renderingStarted ( options ) ; this . settings = Deneb . parseSettings ( options && options . dataViews && options . dataViews [ 0 ] ) ; this . resolveUpdateOptions ( options ) ; return ; } catch ( e ) { hostServices . renderingFailed ( e . message ) ; } } private resolveUpdateOptions ( options ) { const settings = this . settings ; hostServices . visualUpdateOptions = options ; hostServices . resolveLocaleFromSettings ( settings . developer . locale ) ; const { setVisualUpdate , syncTemplateExportDataset , updateDataset , updateDatasetProcessingStage , updateDatasetViewFlags , updateDatasetViewInvalid } = getState ( ) ; setVisualUpdate ( { options , settings } ) ; handlePropertyMigration ( ) ; switch ( options . type ) { case VisualUpdateType . All : case VisualUpdateType . Data : { if ( options . operationKind === VisualDataChangeOperationKind . Create ) { updateDatasetProcessingStage ( { dataProcessingStage : 'Fetching' , canFetchMore : canFetchMore ( ) } ) ; const datasetViewHasValidMapping = validateDataViewMapping ( options . dataViews ) , datasetViewHasValidRoles = datasetViewHasValidMapping && validateDataViewRoles ( options . dataViews , [ 'dataset' ] ) , datasetViewIsValid = datasetViewHasValidMapping && datasetViewHasValidRoles ; updateDatasetViewFlags ( { datasetViewHasValidMapping , datasetViewHasValidRoles , datasetViewIsValid } ) ; } if ( ! getState ( ) . datasetViewHasValidMapping ) { updateDatasetViewInvalid ( ) ; break ; } handleDataFetch ( options ) ; if ( ! canFetchMore ( ) ) { updateDataset ( { categories : options . dataViews [ 0 ] ?. categorical ?. categories , dataset : getMappedDataset ( options . dataViews [ 0 ] ?. categorical ) } ) ; syncTemplateExportDataset ( getTemplateFieldsFromMetadata ( getDataset ( ) . metadata ) ) ; } break ; } default : { } } getState ( ) . datasetProcessingStage === 'Processed' && parseActiveSpec ( ) ; } private static parseSettings ( dataView ) { return VisualSettings . parse ( dataView ) ; } /**
     * This function gets called for each of the objects defined in the capabilities files and allows you to select which of the
     * objects and properties you want to expose to the users in the property pane.
     *
     */ public enumerateObjectInstances ( options ) { let instances = ( < VisualObjectInstanceEnumerationObject > ( VisualSettings . enumerateObjectInstances ( this . settings || VisualSettings . getDefault ( ) , options ) ) ) . instances , objectName = options . objectName , enumerationObject = { containers : [ ] , instances : instances } ; try { switch ( objectName ) { default : { if ( typeof this . settings [ `${ objectName }` ] . processEnumerationObject === 'function' ) { enumerationObject = this . settings [ `${ objectName }` ] . processEnumerationObject ( enumerationObject ) ; } } } } catch ( e ) { console . error ( 'Error' , e ) ; } finally { return enumerationObject ; } } }