From 269c145051eed3f235896b653e62e440b866da1b Mon Sep 17 00:00:00 2001 From: Yunwen Zheng Date: Wed, 29 Oct 2025 12:14:12 -0400 Subject: [PATCH] SaveProvisionedDashboardForm: Bug fix repo type incorrectly showing in preview banner (#113120) * SaveProvisionedDashboardForm: fix repo type incorrectly showing in preview banner --- .../Dashboards/SaveProvisionedDashboardForm.tsx | 9 +++++---- .../components/Folders/NewProvisionedFolderForm.tsx | 2 +- .../hooks/useProvisionedRequestHandler.test.ts | 7 +------ .../provisioning/hooks/useProvisionedRequestHandler.ts | 4 ++-- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.tsx b/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.tsx index 6af33a5cbea..bffaab79a73 100644 --- a/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.tsx +++ b/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.tsx @@ -86,7 +86,7 @@ export function SaveProvisionedDashboardForm({ ); const navigateToPreview = useCallback( - (ref: string, path: string, repoType: string) => { + (ref: string, path: string, repoType?: string) => { const url = buildResourceBranchRedirectUrl({ baseUrl: `${PROVISIONING_URL}/${defaultValues.repo}/dashboard/preview/${path}`, paramName: 'ref', @@ -110,7 +110,7 @@ export function SaveProvisionedDashboardForm({ }, [dashboard, defaultValues.folder?.uid, drawer, panelEditor, request?.data?.resource]); const onWriteSuccess = useCallback( - ({ repoType }: ProvisionedOperationInfo, upsert: Resource) => { + (upsert: Resource) => { handleDismiss(); if (isNew && upsert?.metadata.name) { handleNewDashboard(upsert); @@ -118,7 +118,7 @@ export function SaveProvisionedDashboardForm({ // if pushed to an existing but non-configured branch, navigate to preview page if (ref !== repository?.branch && ref) { - navigateToPreview(ref, path, repoType); + navigateToPreview(ref, path, repository?.type); return; } @@ -127,7 +127,7 @@ export function SaveProvisionedDashboardForm({ editPanel: null, }); }, - [isNew, path, ref, repository?.branch, handleDismiss, handleNewDashboard, navigateToPreview] + [isNew, path, ref, repository?.branch, repository?.type, handleDismiss, handleNewDashboard, navigateToPreview] ); const onBranchSuccess = useCallback( @@ -147,6 +147,7 @@ export function SaveProvisionedDashboardForm({ request, workflow, resourceType: 'dashboard', + repository, handlers: { onBranchSuccess: ({ ref, path }, info, resource) => onBranchSuccess(ref, path, info, resource), onWriteSuccess, diff --git a/public/app/features/provisioning/components/Folders/NewProvisionedFolderForm.tsx b/public/app/features/provisioning/components/Folders/NewProvisionedFolderForm.tsx index 3b9d62916a4..109277d38a7 100644 --- a/public/app/features/provisioning/components/Folders/NewProvisionedFolderForm.tsx +++ b/public/app/features/provisioning/components/Folders/NewProvisionedFolderForm.tsx @@ -92,7 +92,7 @@ function FormContent({ initialValues, repository, workflowOptions, folder, onDis handlers: { onDismiss, onBranchSuccess, - onWriteSuccess: (_, resource) => onWriteSuccess(resource), + onWriteSuccess, onError, }, }); diff --git a/public/app/features/provisioning/hooks/useProvisionedRequestHandler.test.ts b/public/app/features/provisioning/hooks/useProvisionedRequestHandler.test.ts index 0a0e48cf498..7e06b38eff1 100644 --- a/public/app/features/provisioning/hooks/useProvisionedRequestHandler.test.ts +++ b/public/app/features/provisioning/hooks/useProvisionedRequestHandler.test.ts @@ -153,12 +153,7 @@ describe('useProvisionedRequestHandler', () => { ); expect(handlers.onWriteSuccess).toHaveBeenCalledWith( - expect.objectContaining({ - resourceType: 'dashboard', - repoType: 'git', - workflow: 'write', - }), - expect.any(Object) + expect.objectContaining({ kind: 'Dashboard', metadata: expect.objectContaining({ name: 'test-dashboard' }) }) ); expect(handlers.onDismiss).toHaveBeenCalled(); }); diff --git a/public/app/features/provisioning/hooks/useProvisionedRequestHandler.ts b/public/app/features/provisioning/hooks/useProvisionedRequestHandler.ts index 7fc3bb052fe..188f6218950 100644 --- a/public/app/features/provisioning/hooks/useProvisionedRequestHandler.ts +++ b/public/app/features/provisioning/hooks/useProvisionedRequestHandler.ts @@ -29,7 +29,7 @@ interface RequestHandlers { info: ProvisionedOperationInfo, resource: Resource ) => void; - onWriteSuccess?: (info: ProvisionedOperationInfo, resource: Resource) => void; + onWriteSuccess?: (resource: Resource) => void; onError?: (error: unknown, info: ProvisionedOperationInfo) => void; onDismiss?: () => void; } @@ -116,7 +116,7 @@ export function useProvisionedRequestHandler({ // refetch folder items after success if folderUID is passed in dispatch(refetchChildren({ parentUID: folderUID || repository?.name, pageSize: PAGE_SIZE })); } - handlers.onWriteSuccess(info, resourceData); + handlers.onWriteSuccess(resourceData); } handlers.onDismiss?.();