mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Library Panels: Add library panel tab to share modal (#32953)
This commit is contained in:
parent
3c1e7a5f05
commit
2ca4f3ecae
@ -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 (
|
||||||
|
<div className="share-modal-body">
|
||||||
|
<div className="share-modal-header">
|
||||||
|
<div className="share-modal-content">
|
||||||
|
<p className="share-modal-info-text">Add this panel to the panel library.</p>
|
||||||
|
<AddLibraryPanelContents panel={panel} initialFolderId={initialFolderId} onDismiss={onDismiss!} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@ -1,12 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Modal, ModalTabsHeader, TabContent } from '@grafana/ui';
|
import { Modal, ModalTabsHeader, TabContent } from '@grafana/ui';
|
||||||
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
||||||
|
import { isPanelModelLibraryPanel } from 'app/features/library-panels/guard';
|
||||||
import { ShareLink } from './ShareLink';
|
import { ShareLink } from './ShareLink';
|
||||||
import { ShareSnapshot } from './ShareSnapshot';
|
import { ShareSnapshot } from './ShareSnapshot';
|
||||||
import { ShareExport } from './ShareExport';
|
import { ShareExport } from './ShareExport';
|
||||||
import { ShareEmbed } from './ShareEmbed';
|
import { ShareEmbed } from './ShareEmbed';
|
||||||
import { ShareModalTabModel } from './types';
|
import { ShareModalTabModel } from './types';
|
||||||
import { contextSrv } from 'app/core/core';
|
import { contextSrv } from 'app/core/core';
|
||||||
|
import { ShareGlobalPanel } from './ShareGlobalPanel';
|
||||||
|
|
||||||
const customDashboardTabs: ShareModalTabModel[] = [];
|
const customDashboardTabs: ShareModalTabModel[] = [];
|
||||||
const customPanelTabs: ShareModalTabModel[] = [];
|
const customPanelTabs: ShareModalTabModel[] = [];
|
||||||
@ -38,6 +40,10 @@ function getTabs(props: Props) {
|
|||||||
|
|
||||||
if (panel) {
|
if (panel) {
|
||||||
tabs.push({ label: 'Embed', value: 'embed', component: ShareEmbed });
|
tabs.push({ label: 'Embed', value: 'embed', component: ShareEmbed });
|
||||||
|
|
||||||
|
if (!isPanelModelLibraryPanel(panel)) {
|
||||||
|
tabs.push({ label: 'Global panel', value: 'global_panel', component: ShareGlobalPanel });
|
||||||
|
}
|
||||||
tabs.push(...customPanelTabs);
|
tabs.push(...customPanelTabs);
|
||||||
} else {
|
} else {
|
||||||
tabs.push({ label: 'Export', value: 'export', component: ShareExport });
|
tabs.push({ label: 'Export', value: 'export', component: ShareExport });
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { PanelModel } from '@grafana/data';
|
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 {
|
export interface ShareModalTabProps {
|
||||||
dashboard: DashboardModel;
|
dashboard: DashboardModel;
|
||||||
@ -8,7 +8,10 @@ export interface ShareModalTabProps {
|
|||||||
onDismiss?(): void;
|
onDismiss?(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ShareModalTab = React.ComponentType<ShareModalTabProps>;
|
type ShareModalTabPropsWithInternalModel = ShareModalTabProps & { panel?: InternalPanelModel };
|
||||||
|
export type ShareModalTab =
|
||||||
|
| React.ComponentType<ShareModalTabProps>
|
||||||
|
| React.ComponentType<ShareModalTabPropsWithInternalModel>;
|
||||||
|
|
||||||
export interface ShareModalTabModel {
|
export interface ShareModalTabModel {
|
||||||
label: string;
|
label: string;
|
||||||
|
@ -4,22 +4,20 @@ import { FolderPicker } from 'app/core/components/Select/FolderPicker';
|
|||||||
import { PanelModel } from '../../../dashboard/state';
|
import { PanelModel } from '../../../dashboard/state';
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { usePanelSave } from '../../utils/usePanelSave';
|
import { usePanelSave } from '../../utils/usePanelSave';
|
||||||
|
interface AddLibraryPanelContentsProps {
|
||||||
interface Props {
|
|
||||||
onDismiss: () => void;
|
onDismiss: () => void;
|
||||||
isOpen?: boolean;
|
|
||||||
panel: PanelModel;
|
panel: PanelModel;
|
||||||
initialFolderId?: number;
|
initialFolderId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AddLibraryPanelModal: React.FC<Props> = ({ isOpen = false, panel, initialFolderId, ...props }) => {
|
export const AddLibraryPanelContents = ({ panel, initialFolderId, onDismiss }: AddLibraryPanelContentsProps) => {
|
||||||
const styles = useStyles(getStyles);
|
const styles = useStyles(getStyles);
|
||||||
const [folderId, setFolderId] = useState(initialFolderId);
|
const [folderId, setFolderId] = useState(initialFolderId);
|
||||||
const [panelTitle, setPanelTitle] = useState(panel.title);
|
const [panelTitle, setPanelTitle] = useState(panel.title);
|
||||||
const { saveLibraryPanel } = usePanelSave();
|
const { saveLibraryPanel } = usePanelSave();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal title="Add this panel to the panel library" isOpen={isOpen} onDismiss={props.onDismiss}>
|
<>
|
||||||
<Field label="Library panel name">
|
<Field label="Library panel name">
|
||||||
<Input name="name" value={panelTitle} onChange={(e) => setPanelTitle(e.currentTarget.value)} />
|
<Input name="name" value={panelTitle} onChange={(e) => setPanelTitle(e.currentTarget.value)} />
|
||||||
</Field>
|
</Field>
|
||||||
@ -31,15 +29,27 @@ export const AddLibraryPanelModal: React.FC<Props> = ({ isOpen = false, panel, i
|
|||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
panel.title = panelTitle;
|
panel.title = panelTitle;
|
||||||
saveLibraryPanel(panel, folderId!).then(() => props.onDismiss());
|
saveLibraryPanel(panel, folderId!).then(() => onDismiss());
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Add panel to the panel library
|
Add panel to the panel library
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="secondary" onClick={props.onDismiss}>
|
<Button variant="secondary" onClick={onDismiss}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface Props extends AddLibraryPanelContentsProps {
|
||||||
|
isOpen?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AddLibraryPanelModal: React.FC<Props> = ({ isOpen = false, panel, initialFolderId, ...props }) => {
|
||||||
|
return (
|
||||||
|
<Modal title="Add this panel to the panel library" isOpen={isOpen} onDismiss={props.onDismiss}>
|
||||||
|
<AddLibraryPanelContents panel={panel} initialFolderId={initialFolderId} onDismiss={props.onDismiss} />
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user