@grafana/runtime
Version:
Grafana Runtime Library
1 lines • 3.1 kB
Source Map (JSON)
{"version":3,"file":"SidecarContext_EXPERIMENTAL.mjs","sources":["../../../src/services/SidecarContext_EXPERIMENTAL.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport { useObservable } from 'react-use';\n\nimport { SidecarService_EXPERIMENTAL, sidecarServiceSingleton_EXPERIMENTAL } from './SidecarService_EXPERIMENTAL';\n\nexport const SidecarContext_EXPERIMENTAL = createContext<SidecarService_EXPERIMENTAL>(\n sidecarServiceSingleton_EXPERIMENTAL\n);\n\n/**\n * This is the main way to interact with the sidecar service inside a react context. It provides a wrapper around the\n * service props so that even though they are observables we just pass actual values to the components.\n *\n * @experimental\n */\nexport function useSidecar_EXPERIMENTAL() {\n // As the sidecar service functionality is behind feature flag this does not need to be for now\n const service = useContext(SidecarContext_EXPERIMENTAL);\n\n if (!service) {\n throw new Error('No SidecarContext found');\n }\n\n const initialContext = useObservable(service.initialContextObservable, service.initialContext);\n const activePluginId = useObservable(service.activePluginIdObservable, service.activePluginId);\n const locationService = service.getLocationService();\n\n return {\n activePluginId,\n initialContext,\n locationService,\n // TODO: currently this allows anybody to open any app, in the future we should probably scope this to the\n // current app but that means we will need to incorporate this better into the plugin platform APIs which\n // we will do once the functionality is reasonably stable\n openApp: (pluginId: string, context?: unknown) => {\n return service.openApp(pluginId, context);\n },\n openAppV2: (pluginId: string, path?: string) => {\n return service.openAppV2(pluginId, path);\n },\n openAppV3: (options: { pluginId: string; path?: string; follow?: boolean }) => {\n return service.openAppV3(options);\n },\n closeApp: () => service.closeApp(),\n isAppOpened: (pluginId: string) => {\n return service.isAppOpened(pluginId);\n },\n };\n}\n"],"names":[],"mappings":";;;;AAKO,MAAM,2BAA8B,GAAA,aAAA;AAAA,EACzC;AACF;AAQO,SAAS,uBAA0B,GAAA;AAExC,EAAM,MAAA,OAAA,GAAU,WAAW,2BAA2B,CAAA;AAEtD,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,yBAAyB,CAAA;AAAA;AAG3C,EAAA,MAAM,cAAiB,GAAA,aAAA,CAAc,OAAQ,CAAA,wBAAA,EAA0B,QAAQ,cAAc,CAAA;AAC7F,EAAA,MAAM,cAAiB,GAAA,aAAA,CAAc,OAAQ,CAAA,wBAAA,EAA0B,QAAQ,cAAc,CAAA;AAC7F,EAAM,MAAA,eAAA,GAAkB,QAAQ,kBAAmB,EAAA;AAEnD,EAAO,OAAA;AAAA,IACL,cAAA;AAAA,IACA,cAAA;AAAA,IACA,eAAA;AAAA;AAAA;AAAA;AAAA,IAIA,OAAA,EAAS,CAAC,QAAA,EAAkB,OAAsB,KAAA;AAChD,MAAO,OAAA,OAAA,CAAQ,OAAQ,CAAA,QAAA,EAAU,OAAO,CAAA;AAAA,KAC1C;AAAA,IACA,SAAA,EAAW,CAAC,QAAA,EAAkB,IAAkB,KAAA;AAC9C,MAAO,OAAA,OAAA,CAAQ,SAAU,CAAA,QAAA,EAAU,IAAI,CAAA;AAAA,KACzC;AAAA,IACA,SAAA,EAAW,CAAC,OAAmE,KAAA;AAC7E,MAAO,OAAA,OAAA,CAAQ,UAAU,OAAO,CAAA;AAAA,KAClC;AAAA,IACA,QAAA,EAAU,MAAM,OAAA,CAAQ,QAAS,EAAA;AAAA,IACjC,WAAA,EAAa,CAAC,QAAqB,KAAA;AACjC,MAAO,OAAA,OAAA,CAAQ,YAAY,QAAQ,CAAA;AAAA;AACrC,GACF;AACF;;;;"}