From d05587b2fdf4b1b12ebe55bd031469b001c31ef8 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:32:41 +0200 Subject: [PATCH] [v11.0.x] Dashboard: DashboardPageProxy - Use chaining operators to prevent runtime error (#86536) Dashboard: DashboardPageProxy - Use chaining operators to prevent runtime error (#86507) * Use chaining operators to prevent runtime error * Fix tests --------- Co-authored-by: Ivan Ortega (cherry picked from commit 7a147f2ce805c12fbeb388481782e401dbf37b92) Co-authored-by: Alexa V <239999+axelavargas@users.noreply.github.com> --- .../dashboard/containers/DashboardPageProxy.test.tsx | 11 +++++++++-- .../dashboard/containers/DashboardPageProxy.tsx | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard/containers/DashboardPageProxy.test.tsx b/public/app/features/dashboard/containers/DashboardPageProxy.test.tsx index 0972c777522..28df23c5a1c 100644 --- a/public/app/features/dashboard/containers/DashboardPageProxy.test.tsx +++ b/public/app/features/dashboard/containers/DashboardPageProxy.test.tsx @@ -147,7 +147,7 @@ describe('DashboardPageProxy', () => { act(() => { setup({ route: { routeName: DashboardRoutes.Home, component: () => null, path: '/' }, - match: { params: {}, isExact: true, path: '/', url: '/' }, + match: { params: { uid: '' }, isExact: true, path: '/', url: '/' }, }); }); @@ -176,7 +176,14 @@ describe('DashboardPageProxy', () => { act(() => { setup({ route: { routeName: DashboardRoutes.Home, component: () => null, path: '/' }, - match: { params: {}, isExact: true, path: '/', url: '/' }, + match: { + params: { + uid: '', + }, + isExact: true, + path: '/', + url: '/', + }, }); }); diff --git a/public/app/features/dashboard/containers/DashboardPageProxy.tsx b/public/app/features/dashboard/containers/DashboardPageProxy.tsx index b7b70b12f16..b4182e9f7ca 100644 --- a/public/app/features/dashboard/containers/DashboardPageProxy.tsx +++ b/public/app/features/dashboard/containers/DashboardPageProxy.tsx @@ -54,7 +54,7 @@ function DashboardPageProxy(props: DashboardPageProxyProps) { return null; } - if (dashboard.value && dashboard.value.dashboard.uid && dashboard.value.dashboard.uid !== props.match.params.uid) { + if (dashboard?.value?.dashboard?.uid !== props.match.params.uid) { return null; }