diff --git a/public/app/features/dashboard-scene/saving/SaveProvisionedDashboard.tsx b/public/app/features/dashboard-scene/saving/SaveProvisionedDashboard.tsx
index 6de5ca4c4c2..1e3a6e862f6 100644
--- a/public/app/features/dashboard-scene/saving/SaveProvisionedDashboard.tsx
+++ b/public/app/features/dashboard-scene/saving/SaveProvisionedDashboard.tsx
@@ -1,13 +1,14 @@
import { useEffect } from 'react';
-import { useForm } from 'react-hook-form';
+import { Controller, useForm } from 'react-hook-form';
import { AppEvents } from '@grafana/data';
import { getAppEvents } from '@grafana/runtime';
-import { Button, Stack, TextArea, Field, Input, Alert, LinkButton } from '@grafana/ui';
+import { Alert, Button, Field, Input, LinkButton, RadioButtonGroup, Stack, TextArea } from '@grafana/ui';
import { AnnoKeyRepoName, AnnoKeyRepoPath } from 'app/features/apiserver/types';
import { DashboardMeta } from 'app/types';
import { useGetRepositoryQuery, useUpdateRepositoryFilesMutation } from '../../provisioning/api';
+import { WorkflowOption } from '../../provisioning/types';
import { createPRLink, validateBranchName } from '../../provisioning/utils/git';
import { DashboardScene } from '../scene/DashboardScene';
@@ -20,6 +21,7 @@ type FormData = {
path: string;
comment?: string;
repo: string;
+ workflow?: WorkflowOption;
};
function getDefaultValues(meta: DashboardMeta) {
@@ -32,7 +34,20 @@ function getDefaultValues(meta: DashboardMeta) {
ref = path.substring(idx + 1);
path = path.substring(0, idx);
}
- return { ref, path, repo, comment: '' };
+ return {
+ ref: ref || `dashboard/${Date.now()}`,
+ path,
+ repo,
+ comment: '',
+ workflow: WorkflowOption.Branch,
+ };
+}
+
+function getWorkflowOptions(branch = 'main') {
+ return [
+ { label: `Commit to ${branch}`, value: WorkflowOption.Branch },
+ { label: 'Create pull request', value: WorkflowOption.PullRequest },
+ ];
}
export interface Props {
@@ -50,12 +65,14 @@ export function SaveProvisionedDashboard({ meta, drawer, changeInfo, dashboard }
handleSubmit,
watch,
formState: { errors },
+ control,
} = useForm({ defaultValues });
const repositoryConfigQuery = useGetRepositoryQuery({ name: defaultValues.repo });
const repositoryConfig = repositoryConfigQuery?.data?.spec;
const isGitHub = repositoryConfig?.type === 'github';
- const [repo, ref] = watch(['repo', 'ref']);
+ const [repo, ref, workflow] = watch(['repo', 'ref', 'workflow']);
const href = createPRLink(repositoryConfig, repo, ref);
+ const { isDirty } = dashboard.state;
useEffect(() => {
const appEvents = getAppEvents();
@@ -65,8 +82,6 @@ export function SaveProvisionedDashboard({ meta, drawer, changeInfo, dashboard }
payload: ['Dashboard saved'],
});
dashboard.setState({ isDirty: false });
- // TODO Avoid full reload
- window.location.reload();
} else if (request.isError) {
appEvents.publish({
type: AppEvents.alertError.name,
@@ -98,18 +113,31 @@ export function SaveProvisionedDashboard({ meta, drawer, changeInfo, dashboard }
-
+
{isGitHub && (
- : ''}
- >
-
-
+ <>
+
+ (
+
+ )}
+ />
+
+ {workflow === WorkflowOption.PullRequest && (
+ : ''}
+ >
+
+
+ )}
+ >
)}
@@ -122,15 +150,28 @@ export function SaveProvisionedDashboard({ meta, drawer, changeInfo, dashboard }
/>
+ {workflow === WorkflowOption.PullRequest && isDirty && (
+
+ You have unsaved changes. Please save them before opening a pull request.
+
+ )}
+
-