From 216ec7cbdfb90e71e3ff88fa10be1a276dd3e421 Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Tue, 25 Jun 2024 11:18:30 +0200 Subject: [PATCH] Scopes: Fix free text input crash (#89652) --- .betterer.results | 3 +++ .../scene/Scopes/ScopesInput.tsx | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.betterer.results b/.betterer.results index 842d1803312..6ad6560471f 100644 --- a/.betterer.results +++ b/.betterer.results @@ -2904,6 +2904,9 @@ exports[`better eslint`] = { "public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], + "public/app/features/dashboard-scene/scene/Scopes/ScopesInput.tsx:5381": [ + [0, 0, 0, "Do not use any type assertions.", "0"] + ], "public/app/features/dashboard-scene/scene/row-actions/RowActions.tsx:5381": [ [0, 0, 0, "No untranslated strings. Wrap text with ", "0"], [0, 0, 0, "No untranslated strings. Wrap text with ", "1"], diff --git a/public/app/features/dashboard-scene/scene/Scopes/ScopesInput.tsx b/public/app/features/dashboard-scene/scene/Scopes/ScopesInput.tsx index b44d0ee4d11..edaf6219b5b 100644 --- a/public/app/features/dashboard-scene/scene/Scopes/ScopesInput.tsx +++ b/public/app/features/dashboard-scene/scene/Scopes/ScopesInput.tsx @@ -35,13 +35,20 @@ export function ScopesInput({ let titles: string[]; if (path.length > 0) { - titles = path.map((nodeName) => { - const { title, nodes } = currentLevel[nodeName]; + titles = path + .map((nodeName) => { + const cl = currentLevel[nodeName]; + if (!cl) { + return null; + } - currentLevel = nodes; + const { title, nodes } = cl; - return title; - }); + currentLevel = nodes; + + return title; + }) + .filter((title) => title !== null) as string[]; if (titles[0] === '') { titles.splice(0, 1);