2020-03-03 08:22:26 +01:00
|
|
|
import React from 'react';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
2023-01-31 13:54:24 +00:00
|
|
|
import { reportInteraction } from '@grafana/runtime';
|
2022-09-12 15:45:14 +02:00
|
|
|
import { Button, ButtonVariant, ComponentSize, ModalsController } from '@grafana/ui';
|
2020-03-03 08:22:26 +01:00
|
|
|
import { DashboardModel } from 'app/features/dashboard/state';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2022-05-02 09:29:22 -07:00
|
|
|
import { SaveDashboardDrawer } from './SaveDashboardDrawer';
|
2020-03-03 08:22:26 +01:00
|
|
|
|
|
|
|
|
interface SaveDashboardButtonProps {
|
|
|
|
|
dashboard: DashboardModel;
|
|
|
|
|
onSaveSuccess?: () => void;
|
2022-09-12 15:45:14 +02:00
|
|
|
size?: ComponentSize;
|
2020-03-03 08:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-15 07:56:09 -07:00
|
|
|
export const SaveDashboardButton = ({ dashboard, onSaveSuccess, size }: SaveDashboardButtonProps) => {
|
2020-03-03 08:22:26 +01:00
|
|
|
return (
|
|
|
|
|
<ModalsController>
|
|
|
|
|
{({ showModal, hideModal }) => {
|
|
|
|
|
return (
|
2020-03-26 11:50:27 +01:00
|
|
|
<Button
|
2022-09-12 15:45:14 +02:00
|
|
|
size={size}
|
2020-03-03 08:22:26 +01:00
|
|
|
onClick={() => {
|
2022-05-02 09:29:22 -07:00
|
|
|
showModal(SaveDashboardDrawer, {
|
2021-01-19 13:19:01 +01:00
|
|
|
dashboard,
|
2020-03-03 08:22:26 +01:00
|
|
|
onSaveSuccess,
|
|
|
|
|
onDismiss: hideModal,
|
|
|
|
|
});
|
|
|
|
|
}}
|
2020-12-02 14:08:35 +01:00
|
|
|
aria-label={selectors.pages.Dashboard.Settings.General.saveDashBoard}
|
2020-03-03 08:22:26 +01:00
|
|
|
>
|
|
|
|
|
Save dashboard
|
2020-03-26 11:50:27 +01:00
|
|
|
</Button>
|
2020-03-03 08:22:26 +01:00
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
</ModalsController>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-15 07:56:09 -07:00
|
|
|
type Props = SaveDashboardButtonProps & { variant?: ButtonVariant };
|
|
|
|
|
|
|
|
|
|
export const SaveDashboardAsButton = ({ dashboard, onSaveSuccess, variant, size }: Props) => {
|
2020-03-03 08:22:26 +01:00
|
|
|
return (
|
|
|
|
|
<ModalsController>
|
|
|
|
|
{({ showModal, hideModal }) => {
|
|
|
|
|
return (
|
2022-08-24 18:05:12 +02:00
|
|
|
<Button
|
2022-09-12 15:45:14 +02:00
|
|
|
size={size}
|
2022-08-24 18:05:12 +02:00
|
|
|
onClick={() => {
|
2023-01-31 13:54:24 +00:00
|
|
|
reportInteraction('grafana_dashboard_save_as_clicked');
|
2022-08-24 18:05:12 +02:00
|
|
|
showModal(SaveDashboardDrawer, {
|
|
|
|
|
dashboard,
|
|
|
|
|
onSaveSuccess,
|
|
|
|
|
onDismiss: hideModal,
|
|
|
|
|
isCopy: true,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
variant={variant}
|
|
|
|
|
aria-label={selectors.pages.Dashboard.Settings.General.saveAsDashBoard}
|
|
|
|
|
>
|
2022-09-12 15:45:14 +02:00
|
|
|
Save as
|
2022-08-24 18:05:12 +02:00
|
|
|
</Button>
|
2020-03-03 08:22:26 +01:00
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
</ModalsController>
|
|
|
|
|
);
|
|
|
|
|
};
|