From 2ca4f3ecae97b216c063206bd3d6ba8baaaa08af Mon Sep 17 00:00:00 2001
From: kay delaney <45561153+kaydelaney@users.noreply.github.com>
Date: Thu, 15 Apr 2021 08:29:34 +0100
Subject: [PATCH] Library Panels: Add library panel tab to share modal (#32953)
---
.../ShareModal/ShareGlobalPanel.tsx | 26 +++++++++++++++++++
.../components/ShareModal/ShareModal.tsx | 6 +++++
.../dashboard/components/ShareModal/types.ts | 7 +++--
.../AddLibraryPanelModal.tsx | 24 ++++++++++++-----
4 files changed, 54 insertions(+), 9 deletions(-)
create mode 100644 public/app/features/dashboard/components/ShareModal/ShareGlobalPanel.tsx
diff --git a/public/app/features/dashboard/components/ShareModal/ShareGlobalPanel.tsx b/public/app/features/dashboard/components/ShareModal/ShareGlobalPanel.tsx
new file mode 100644
index 00000000000..d4812516aa0
--- /dev/null
+++ b/public/app/features/dashboard/components/ShareModal/ShareGlobalPanel.tsx
@@ -0,0 +1,26 @@
+import React from 'react';
+import { PanelModel } from 'app/features/dashboard/state';
+import { AddLibraryPanelContents } from 'app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal';
+
+interface Props {
+ onDismiss?: () => void;
+ panel?: PanelModel;
+ initialFolderId?: number;
+}
+
+export const ShareGlobalPanel = ({ panel, initialFolderId, onDismiss }: Props) => {
+ if (!panel) {
+ return null;
+ }
+
+ return (
+
+
+
+
Add this panel to the panel library.
+
+
+
+
+ );
+};
diff --git a/public/app/features/dashboard/components/ShareModal/ShareModal.tsx b/public/app/features/dashboard/components/ShareModal/ShareModal.tsx
index 1de8c0c6d06..4846ecfa040 100644
--- a/public/app/features/dashboard/components/ShareModal/ShareModal.tsx
+++ b/public/app/features/dashboard/components/ShareModal/ShareModal.tsx
@@ -1,12 +1,14 @@
import React from 'react';
import { Modal, ModalTabsHeader, TabContent } from '@grafana/ui';
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
+import { isPanelModelLibraryPanel } from 'app/features/library-panels/guard';
import { ShareLink } from './ShareLink';
import { ShareSnapshot } from './ShareSnapshot';
import { ShareExport } from './ShareExport';
import { ShareEmbed } from './ShareEmbed';
import { ShareModalTabModel } from './types';
import { contextSrv } from 'app/core/core';
+import { ShareGlobalPanel } from './ShareGlobalPanel';
const customDashboardTabs: ShareModalTabModel[] = [];
const customPanelTabs: ShareModalTabModel[] = [];
@@ -38,6 +40,10 @@ function getTabs(props: Props) {
if (panel) {
tabs.push({ label: 'Embed', value: 'embed', component: ShareEmbed });
+
+ if (!isPanelModelLibraryPanel(panel)) {
+ tabs.push({ label: 'Global panel', value: 'global_panel', component: ShareGlobalPanel });
+ }
tabs.push(...customPanelTabs);
} else {
tabs.push({ label: 'Export', value: 'export', component: ShareExport });
diff --git a/public/app/features/dashboard/components/ShareModal/types.ts b/public/app/features/dashboard/components/ShareModal/types.ts
index 3627981b752..e7099062d44 100644
--- a/public/app/features/dashboard/components/ShareModal/types.ts
+++ b/public/app/features/dashboard/components/ShareModal/types.ts
@@ -1,6 +1,6 @@
import React from 'react';
import { PanelModel } from '@grafana/data';
-import { DashboardModel } from 'app/features/dashboard/state';
+import { DashboardModel, PanelModel as InternalPanelModel } from 'app/features/dashboard/state';
export interface ShareModalTabProps {
dashboard: DashboardModel;
@@ -8,7 +8,10 @@ export interface ShareModalTabProps {
onDismiss?(): void;
}
-export type ShareModalTab = React.ComponentType;
+type ShareModalTabPropsWithInternalModel = ShareModalTabProps & { panel?: InternalPanelModel };
+export type ShareModalTab =
+ | React.ComponentType
+ | React.ComponentType;
export interface ShareModalTabModel {
label: string;
diff --git a/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx b/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx
index 828c2685dee..1e64a76410a 100644
--- a/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx
+++ b/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx
@@ -4,22 +4,20 @@ import { FolderPicker } from 'app/core/components/Select/FolderPicker';
import { PanelModel } from '../../../dashboard/state';
import { css } from '@emotion/css';
import { usePanelSave } from '../../utils/usePanelSave';
-
-interface Props {
+interface AddLibraryPanelContentsProps {
onDismiss: () => void;
- isOpen?: boolean;
panel: PanelModel;
initialFolderId?: number;
}
-export const AddLibraryPanelModal: React.FC = ({ isOpen = false, panel, initialFolderId, ...props }) => {
+export const AddLibraryPanelContents = ({ panel, initialFolderId, onDismiss }: AddLibraryPanelContentsProps) => {
const styles = useStyles(getStyles);
const [folderId, setFolderId] = useState(initialFolderId);
const [panelTitle, setPanelTitle] = useState(panel.title);
const { saveLibraryPanel } = usePanelSave();
return (
-
+ <>
setPanelTitle(e.currentTarget.value)} />
@@ -31,15 +29,27 @@ export const AddLibraryPanelModal: React.FC = ({ isOpen = false, panel, i
-