mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Navigation: add event tracking for dashboard save as events (#62568)
* add event tracking for dashboard save as events * emit a grafana_dashboard_copied event instead
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { selectors } from '@grafana/e2e-selectors';
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
|
import { reportInteraction } from '@grafana/runtime';
|
||||||
import { Button, ButtonVariant, ComponentSize, ModalsController } from '@grafana/ui';
|
import { Button, ButtonVariant, ComponentSize, ModalsController } from '@grafana/ui';
|
||||||
import { DashboardModel } from 'app/features/dashboard/state';
|
import { DashboardModel } from 'app/features/dashboard/state';
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ export const SaveDashboardAsButton: React.FC<SaveDashboardButtonProps & { varian
|
|||||||
<Button
|
<Button
|
||||||
size={size}
|
size={size}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
reportInteraction('grafana_dashboard_save_as_clicked');
|
||||||
showModal(SaveDashboardDrawer, {
|
showModal(SaveDashboardDrawer, {
|
||||||
dashboard,
|
dashboard,
|
||||||
onSaveSuccess,
|
onSaveSuccess,
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export const SaveDashboardDrawer = ({ dashboard, onDismiss, onSaveSuccess, isCop
|
|||||||
}, [dashboard, previous.value, options, isNew]);
|
}, [dashboard, previous.value, options, isNew]);
|
||||||
|
|
||||||
const [showDiff, setShowDiff] = useState(false);
|
const [showDiff, setShowDiff] = useState(false);
|
||||||
const { state, onDashboardSave } = useDashboardSave(dashboard);
|
const { state, onDashboardSave } = useDashboardSave(dashboard, isCopy);
|
||||||
const onSuccess = onSaveSuccess
|
const onSuccess = onSaveSuccess
|
||||||
? () => {
|
? () => {
|
||||||
onDismiss();
|
onDismiss();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const saveDashboard = async (saveModel: any, options: SaveDashboardOptions, dash
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useDashboardSave = (dashboard: DashboardModel) => {
|
export const useDashboardSave = (dashboard: DashboardModel, isCopy = false) => {
|
||||||
const [state, onDashboardSave] = useAsyncFn(
|
const [state, onDashboardSave] = useAsyncFn(
|
||||||
async (clone: any, options: SaveDashboardOptions, dashboard: DashboardModel) =>
|
async (clone: any, options: SaveDashboardOptions, dashboard: DashboardModel) =>
|
||||||
await saveDashboard(clone, options, dashboard),
|
await saveDashboard(clone, options, dashboard),
|
||||||
@@ -46,10 +46,17 @@ export const useDashboardSave = (dashboard: DashboardModel) => {
|
|||||||
// important that these happen before location redirect below
|
// important that these happen before location redirect below
|
||||||
appEvents.publish(new DashboardSavedEvent());
|
appEvents.publish(new DashboardSavedEvent());
|
||||||
notifyApp.success('Dashboard saved');
|
notifyApp.success('Dashboard saved');
|
||||||
reportInteraction(`grafana_dashboard_${dashboard.id ? 'saved' : 'created'}`, {
|
if (isCopy) {
|
||||||
name: dashboard.title,
|
reportInteraction('grafana_dashboard_copied', {
|
||||||
url: state.value.url,
|
name: dashboard.title,
|
||||||
});
|
url: state.value.url,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
reportInteraction(`grafana_dashboard_${dashboard.id ? 'saved' : 'created'}`, {
|
||||||
|
name: dashboard.title,
|
||||||
|
url: state.value.url,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const currentPath = locationService.getLocation().pathname;
|
const currentPath = locationService.getLocation().pathname;
|
||||||
const newUrl = locationUtil.stripBaseFromUrl(state.value.url);
|
const newUrl = locationUtil.stripBaseFromUrl(state.value.url);
|
||||||
@@ -67,7 +74,7 @@ export const useDashboardSave = (dashboard: DashboardModel) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [dashboard, state, notifyApp, dispatch]);
|
}, [dashboard, isCopy, state, notifyApp, dispatch]);
|
||||||
|
|
||||||
return { state, onDashboardSave };
|
return { state, onDashboardSave };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user