Provisioning: better branch handling (#101188)

This commit is contained in:
Ryan McKinley
2025-02-24 12:31:36 +03:00
committed by GitHub
parent e137385a81
commit de8bb4ed6a
2 changed files with 10 additions and 4 deletions
@@ -47,6 +47,7 @@ export function SaveProvisionedDashboard({ drawer, changeInfo, dashboard }: Prop
const { meta, title: defaultTitle, description: defaultDescription } = dashboard.useState();
const navigate = useNavigate();
const [params] = useUrlParams();
const loadedFromRef = params.get('ref') ?? undefined;
const {
values: defaultValues,
@@ -120,13 +121,13 @@ export function SaveProvisionedDashboard({ drawer, changeInfo, dashboard }: Prop
});
if (workflow === 'write') {
ref = params.get('ref') ?? undefined; // the original ref from URL or undefined
ref = loadedFromRef; // the original ref from URL or undefined
}
action({ ref, name: repo, path, message: comment, body: saveModel });
};
const workflows = getWorkflowOptions(repositoryConfig, ref);
const workflows = getWorkflowOptions(repositoryConfig, loadedFromRef);
return (
<form onSubmit={handleSubmit(doSave)}>
@@ -1,3 +1,6 @@
import { Chance } from 'chance';
import { dateTime } from '@grafana/data';
import { AnnoKeyRepoName, AnnoKeyRepoPath } from 'app/features/apiserver/types';
import { useGetResourceRepository } from 'app/features/provisioning/hooks';
import { DashboardMeta } from 'app/types';
@@ -10,7 +13,7 @@ interface UseDefaultValuesParams {
defaultDescription?: string;
}
function generatePath(timestamp: number, pathFromAnnotation?: string, slug?: string) {
function generatePath(timestamp: string, pathFromAnnotation?: string, slug?: string) {
if (pathFromAnnotation) {
const hashIndex = pathFromAnnotation.indexOf('#');
return hashIndex > 0 ? pathFromAnnotation.substring(0, hashIndex) : pathFromAnnotation;
@@ -27,7 +30,9 @@ export function useDefaultValues({ meta, defaultTitle, defaultDescription }: Use
// Get config by resource name or folder UID for new resources
const repositoryConfig = useGetResourceRepository({ name: annoName, folderUid: meta.folderUid });
const repository = repositoryConfig?.spec;
const timestamp = Date.now();
const random = Chance(1);
const timestamp = `${dateTime().format('YYYY-MM-DD')}-${random.string({ length: 5, alpha: true })}`;
return {
values: {