{"version":3,"file":"PanelContext.mjs","sources":["../../../../src/components/PanelChrome/PanelContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nimport {\n  type AnnotationEventUIModel,\n  type CoreApp,\n  type DashboardCursorSync,\n  type DataFrame,\n  type DataLinkPostProcessor,\n  type DataTransformerConfig,\n  type EventBus,\n  EventBusSrv,\n} from '@grafana/data';\n\nimport { type AdHocFilterItem } from '../Table/types';\n\nimport { type OnSelectRangeCallback, type SeriesVisibilityChangeMode } from './types';\n\n/** Runtime transformations supplied by a panel host, grouped by owner. @alpha */\nexport interface PanelRuntimeTransformations {\n  /** Returns the same immutable snapshot until this owner changes. */\n  get(owner: string): readonly DataTransformerConfig[];\n  /** Replaces one owner's transformations. An empty list removes the owner. */\n  set(owner: string, transformations: readonly DataTransformerConfig[]): void;\n  /** Returns data before this owner's transformations. */\n  getSourceSeries(owner: string): readonly DataFrame[];\n  /** Subscribes to changes for one owner. Returns an unsubscribe function. */\n  subscribe(owner: string, callback: () => void): () => void;\n}\n\n/** Reactive view of one owner's runtime transformations. @alpha */\nexport interface AdHocTransformationsState {\n  /** Transformations currently applied after the panel's saved transformations. */\n  transformations: readonly DataTransformerConfig[];\n\n  /** Data before this owner's transformations, including columns they hide. */\n  sourceSeries: readonly DataFrame[];\n\n  /** Replaces this owner's transformations. Pass `[]` to clear them. */\n  setTransformations(transformations: readonly DataTransformerConfig[]): void;\n}\n\n/** @alpha */\nexport interface PanelContext {\n  /** Identifier for the events scope */\n  eventsScope: string;\n  eventBus: EventBus;\n\n  /** Dashboard panels sync */\n  sync?: () => DashboardCursorSync;\n\n  /** Information on what the outer container is */\n  app?: CoreApp | 'string';\n\n  /**\n   * Called when a component wants to change the color for a series\n   *\n   * @alpha -- experimental\n   */\n  onSeriesColorChange?: (label: string, color: string) => void;\n\n  onToggleSeriesVisibility?: (label: string | string[] | null, mode: SeriesVisibilityChangeMode) => void;\n\n  canAddAnnotations?: () => boolean;\n  canEditAnnotations?: (dashboardUID?: string) => boolean;\n  canDeleteAnnotations?: (dashboardUID?: string) => boolean;\n  canExecuteActions?: () => boolean;\n  onAnnotationCreate?: (annotation: AnnotationEventUIModel) => void;\n  onAnnotationUpdate?: (annotation: AnnotationEventUIModel) => void;\n  onAnnotationDelete?: (id: string) => void;\n\n  /**\n   * Called when a user selects an area on the panel, if defined will override the default behavior of the panel,\n   * which is to update the time range\n   */\n  onSelectRange?: OnSelectRangeCallback;\n\n  /**\n   * Used from visualizations like Table to add ad-hoc filters from cell values\n   */\n  onAddAdHocFilter?: (item: AdHocFilterItem) => void;\n\n  /**\n   * Returns filters based on existing grouping or an empty array\n   */\n  getFiltersBasedOnGrouping?: (items: AdHocFilterItem[]) => AdHocFilterItem[];\n  /**\n   *\n   * Used to apply multiple filters at once\n   */\n  onAddAdHocFilters?: (items: AdHocFilterItem[]) => void;\n\n  /**\n   * Used by the panel header status popover to open the errors and notices view.\n   */\n  onOpenInspector?: () => void;\n\n  /**\n   * Used by the panel header status popover to trigger an AI-assisted investigation of the\n   * panel's query errors and notices.\n   */\n  onInvestigateErrors?: () => void;\n\n  /** For instance state that can be shared between panel & options UI  */\n  instanceState?: any;\n\n  /** Update instance state, this is only supported in dashboard panel context currently */\n  onInstanceStateChange?: (state: any) => void;\n\n  /**\n   * Called when a panel is changing the sort order of the legends.\n   */\n  onToggleLegendSort?: (sortBy: string) => void;\n\n  /**\n   * Optional, only some contexts support this. This action can be cancelled by user which will result\n   * in a the Promise resolving to a false value.\n   */\n  onUpdateData?: (frames: DataFrame[]) => Promise<boolean>;\n\n  /**\n   * Optional supplier for internal data links. If not provided a link pointing to Explore will be generated.\n   * @internal\n   * @deprecated Please use DataLinksContext instead. This property will be removed in next major.\n   */\n  dataLinkPostProcessor?: DataLinkPostProcessor;\n\n  /** Present when the panel host supports ad-hoc transformations. @alpha */\n  adHocTransformations?: PanelRuntimeTransformations;\n}\n\nexport const PanelContextRoot = createContext<PanelContext>({\n  eventsScope: 'global',\n  eventBus: new EventBusSrv(),\n});\n\n/**\n * @alpha\n */\nexport const PanelContextProvider = PanelContextRoot.Provider;\n\n/**\n * @alpha\n */\nexport const usePanelContext = () => useContext(PanelContextRoot);\n"],"names":[],"mappings":";;;;AAkIO,MAAM,mBAAmB,aAAA,CAA4B;AAAA,EAC1D,WAAA,EAAa,QAAA;AAAA,EACb,QAAA,EAAU,IAAI,WAAA;AAChB,CAAC;AAKM,MAAM,uBAAuB,gBAAA,CAAiB;AAK9C,MAAM,eAAA,GAAkB,MAAM,UAAA,CAAW,gBAAgB;;;;"}