|
@@ -185,6 +185,7 @@ function WidgetBuilder({
|
|
|
end,
|
|
|
statsPeriod,
|
|
|
onSave,
|
|
|
+ route,
|
|
|
router,
|
|
|
tags,
|
|
|
}: Props) {
|
|
@@ -231,6 +232,7 @@ function WidgetBuilder({
|
|
|
|
|
|
const api = useApi();
|
|
|
|
|
|
+ const [isSubmitting, setIsSubmitting] = useState(false);
|
|
|
const [state, setState] = useState<State>(() => {
|
|
|
const defaultState: State = {
|
|
|
title: defaultTitle ?? t('Custom Widget'),
|
|
@@ -401,6 +403,17 @@ function WidgetBuilder({
|
|
|
fetchOrgMembers(api, organization.slug, selection.projects?.map(String));
|
|
|
}, [selection.projects, api, organization.slug]);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ const onUnload = () => {
|
|
|
+ if (!isSubmitting && state.userHasModified) {
|
|
|
+ return t('You have unsaved changes, are you sure you want to leave?');
|
|
|
+ }
|
|
|
+ return undefined;
|
|
|
+ };
|
|
|
+
|
|
|
+ router.setRouteLeaveHook(route, onUnload);
|
|
|
+ }, [isSubmitting, state.userHasModified, route, router]);
|
|
|
+
|
|
|
const widgetType =
|
|
|
state.dataSet === DataSet.EVENTS
|
|
|
? WidgetType.DISCOVER
|
|
@@ -540,6 +553,7 @@ function WidgetBuilder({
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ set(newState, 'userHasModified', true);
|
|
|
return {...newState, errors: undefined};
|
|
|
});
|
|
|
}
|
|
@@ -577,6 +591,9 @@ function WidgetBuilder({
|
|
|
setState(prevState => {
|
|
|
const newState = cloneDeep(prevState);
|
|
|
set(newState, field, value);
|
|
|
+ if (field === 'title') {
|
|
|
+ set(newState, 'userHasModified', true);
|
|
|
+ }
|
|
|
return {...newState, errors: undefined};
|
|
|
});
|
|
|
|
|
@@ -856,6 +873,7 @@ function WidgetBuilder({
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ setIsSubmitting(true);
|
|
|
let nextWidgetList = [...dashboard.widgets];
|
|
|
const updateWidgetIndex = getUpdateWidgetIndex();
|
|
|
nextWidgetList.splice(updateWidgetIndex, 1);
|
|
@@ -900,6 +918,7 @@ function WidgetBuilder({
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ setIsSubmitting(true);
|
|
|
if (notDashboardsOrigin) {
|
|
|
submitFromSelectedDashboard(widgetData);
|
|
|
return;
|