Provisioning: Fix updating a PR from the UI (#103571)
Co-authored-by: Clarity-89 <homes89@ukr.net>
This commit is contained in:
co-authored by
Clarity-89
parent
56b4e5670d
commit
18a3913782
@@ -105,8 +105,10 @@ type PullRequestJobOptions struct {
|
||||
Ref string `json:"ref,omitempty"`
|
||||
|
||||
// Pull request number (when appropriate)
|
||||
PR int `json:"pr,omitempty"`
|
||||
Hash string `json:"hash,omitempty"` // used in PR code... not sure it is necessary
|
||||
PR int `json:"pr,omitempty"`
|
||||
|
||||
// The specific commit hash that triggered this notice
|
||||
Hash string `json:"hash,omitempty"`
|
||||
|
||||
// URL to the originator (eg, PR URL)
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
@@ -937,8 +937,9 @@ func schema_pkg_apis_provisioning_v0alpha1_PullRequestJobOptions(ref common.Refe
|
||||
},
|
||||
"hash": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "The specific commit hash that triggered this notice",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"url": {
|
||||
|
||||
@@ -2989,6 +2989,7 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"hash": {
|
||||
"description": "The specific commit hash that triggered this notice",
|
||||
"type": "string"
|
||||
},
|
||||
"pr": {
|
||||
|
||||
@@ -729,6 +729,7 @@ export type MigrateJobOptions = {
|
||||
history?: boolean;
|
||||
};
|
||||
export type PullRequestJobOptions = {
|
||||
/** The specific commit hash that triggered this notice */
|
||||
hash?: string;
|
||||
/** Pull request number (when appropriate) */
|
||||
pr?: number;
|
||||
|
||||
@@ -19,7 +19,7 @@ export function SaveProvisionedDashboard({ drawer, changeInfo, dashboard }: Save
|
||||
const [params] = useUrlParams();
|
||||
const loadedFromRef = params.get('ref') ?? undefined;
|
||||
|
||||
const defaultValues = useDefaultValues({ meta, defaultTitle, defaultDescription });
|
||||
const defaultValues = useDefaultValues({ meta, defaultTitle, defaultDescription, loadedFromRef });
|
||||
|
||||
if (!defaultValues) {
|
||||
return null;
|
||||
|
||||
+3
-1
@@ -82,7 +82,9 @@ export function SaveProvisionedDashboardForm({
|
||||
if (request.isSuccess) {
|
||||
dashboard.setState({ isDirty: false });
|
||||
|
||||
if (workflow === 'branch' && ref !== '' && path !== '') {
|
||||
const { ref, path } = request.data;
|
||||
|
||||
if (workflow === 'branch' && ref && path) {
|
||||
dashboard.closeModal();
|
||||
panelEditor?.onDiscard();
|
||||
// Redirect to the provisioning preview pages
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { RepositoryView } from 'app/api/clients/provisioning';
|
||||
import { WorkflowOption } from 'app/features/provisioning/types';
|
||||
|
||||
export function getDefaultWorkflow(config?: RepositoryView) {
|
||||
export function getDefaultWorkflow(config?: RepositoryView, loadedFromRef?: string) {
|
||||
if (loadedFromRef && loadedFromRef !== config?.branch) {
|
||||
return 'write'; // use write when the value targets an explicit ref
|
||||
}
|
||||
return config?.workflows?.[0];
|
||||
}
|
||||
|
||||
@@ -19,11 +21,14 @@ export function getWorkflowOptions(config?: RepositoryView, ref?: string) {
|
||||
ref = config.branch;
|
||||
}
|
||||
|
||||
const availableOptions: Array<{ label: string; value: WorkflowOption }> = [
|
||||
{ label: ref ? `Push to ${ref}` : 'Save', value: 'write' },
|
||||
{ label: 'Push to different branch', value: 'branch' },
|
||||
];
|
||||
|
||||
// Filter options based on the workflows in the config
|
||||
return availableOptions.filter((option) => config.workflows?.includes(option.value));
|
||||
// Return the workflows in the configured order
|
||||
return config.workflows.map((value) => {
|
||||
switch (value) {
|
||||
case 'write':
|
||||
return { label: ref ? `Push to ${ref}` : 'Save', value };
|
||||
case 'branch':
|
||||
return { label: 'Push to a new branch', value };
|
||||
}
|
||||
return { label: value, value };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,9 +10,10 @@ interface UseDefaultValuesParams {
|
||||
meta: DashboardMeta;
|
||||
defaultTitle: string;
|
||||
defaultDescription?: string;
|
||||
loadedFromRef?: string;
|
||||
}
|
||||
|
||||
export function useDefaultValues({ meta, defaultTitle, defaultDescription }: UseDefaultValuesParams) {
|
||||
export function useDefaultValues({ meta, defaultTitle, defaultDescription, loadedFromRef }: UseDefaultValuesParams) {
|
||||
const annotations = meta.k8s?.annotations;
|
||||
const managerKind = annotations?.[AnnoKeyManagerKind];
|
||||
const managerIdentity = annotations?.[AnnoKeyManagerIdentity];
|
||||
@@ -48,7 +49,7 @@ export function useDefaultValues({ meta, defaultTitle, defaultDescription }: Use
|
||||
},
|
||||
title: defaultTitle,
|
||||
description: defaultDescription ?? '',
|
||||
workflow: getDefaultWorkflow(repository),
|
||||
workflow: getDefaultWorkflow(repository, loadedFromRef),
|
||||
},
|
||||
isNew: !meta.k8s?.name,
|
||||
isGitHub: repository?.type === 'github',
|
||||
|
||||
@@ -772,7 +772,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> impleme
|
||||
kind: 'Dashboard',
|
||||
metadata: {
|
||||
...meta.k8s,
|
||||
name: meta.uid, // ideally the name is preserved
|
||||
name: meta.uid ?? meta.k8s?.name,
|
||||
generateName: options.isNew ? 'd' : undefined,
|
||||
},
|
||||
spec,
|
||||
|
||||
@@ -94,8 +94,11 @@ export function WizardContent({
|
||||
const handleRepositoryDeletion = async (name: string) => {
|
||||
try {
|
||||
await deleteRepository({ name });
|
||||
// Wait before redirecting to ensure deletion is indexed
|
||||
setTimeout(() => navigate(PROVISIONING_URL), 1500);
|
||||
// Wait before redirecting to ensure deletion is processed
|
||||
setTimeout(() => {
|
||||
settingsQuery.refetch();
|
||||
navigate(PROVISIONING_URL);
|
||||
}, 1500);
|
||||
} catch (error) {
|
||||
setIsCancelling(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user