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/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx

63 lines
2.0 KiB

import React, { useState } from 'react';
import { Button, Field, Input, Modal, useStyles } from '@grafana/ui';
import { FolderPicker } from 'app/core/components/Select/FolderPicker';
import { PanelModel } from '../../../dashboard/state';
import { css } from '@emotion/css';
import { usePanelSave } from '../../utils/usePanelSave';
interface AddLibraryPanelContentsProps {
onDismiss: () => void;
panel: PanelModel;
initialFolderId?: number;
}
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 (
<>
<Field label="Library panel name">
<Input name="name" value={panelTitle} onChange={(e) => setPanelTitle(e.currentTarget.value)} />
</Field>
<Field label="Save in folder" description="Library panel permissions are derived from the folder permissions">
<FolderPicker onChange={({ id }) => setFolderId(id)} initialFolderId={initialFolderId} />
</Field>
<div className={styles.buttons}>
<Button
onClick={() => {
panel.title = panelTitle;
saveLibraryPanel(panel, folderId!).then(() => onDismiss());
}}
>
Add panel to the panel library
</Button>
<Button variant="secondary" onClick={onDismiss}>
Cancel
</Button>
</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>
);
};
const getStyles = () => ({
buttons: css`
display: flex;
gap: 10px;
`,
});