The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard-scene/sharing/ShareLibraryPanelTab.tsx

58 lines
2.0 KiB

import React from 'react';
import { SceneComponentProps, SceneGridItem, SceneObjectBase, SceneObjectRef, VizPanel } from '@grafana/scenes';
import { t } from 'app/core/internationalization';
import { ShareLibraryPanel } from 'app/features/dashboard/components/ShareModal/ShareLibraryPanel';
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
import { DashboardScene } from '../scene/DashboardScene';
import { PanelRepeaterGridItem } from '../scene/PanelRepeaterGridItem';
import { gridItemToPanel, transformSceneToSaveModel } from '../serialization/transformSceneToSaveModel';
import { SceneShareTabState } from './types';
export interface ShareLibraryPanelTabState extends SceneShareTabState {
panelRef?: SceneObjectRef<VizPanel>;
dashboardRef: SceneObjectRef<DashboardScene>;
}
export class ShareLibraryPanelTab extends SceneObjectBase<ShareLibraryPanelTabState> {
public tabId = 'Library panel';
static Component = ShareLibraryPanelTabRenderer;
public getTabLabel() {
return t('share-modal.tab-title.library-panel', 'Library panel');
}
}
function ShareLibraryPanelTabRenderer({ model }: SceneComponentProps<ShareLibraryPanelTab>) {
const { panelRef, dashboardRef, modalRef } = model.useState();
if (!panelRef) {
return null;
}
const vizPanel = panelRef.resolve();
if (vizPanel.parent instanceof SceneGridItem || vizPanel.parent instanceof PanelRepeaterGridItem) {
const dashboardScene = dashboardRef.resolve();
const panelJson = gridItemToPanel(vizPanel.parent);
const panelModel = new PanelModel(panelJson);
const dashboardJson = transformSceneToSaveModel(dashboardScene);
const dashboardModel = new DashboardModel(dashboardJson);
return (
<ShareLibraryPanel
initialFolderUid={dashboardScene.state.meta.folderUid}
dashboard={dashboardModel}
panel={panelModel}
onDismiss={() => {
modalRef?.resolve().onDismiss();
}}
/>
);
}
return null;
}