From dacfdc0cde80c1724345c99866283be7846a215d Mon Sep 17 00:00:00 2001 From: Alex Khomenko Date: Thu, 19 May 2022 16:47:55 +0300 Subject: [PATCH] DashboardPickerByID: Add option to exclude dashboards (#49211) --- .../editors/DashboardPickerByID.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/public/app/core/components/editors/DashboardPickerByID.tsx b/public/app/core/components/editors/DashboardPickerByID.tsx index d4b2f709795..85d90167699 100644 --- a/public/app/core/components/editors/DashboardPickerByID.tsx +++ b/public/app/core/components/editors/DashboardPickerByID.tsx @@ -23,6 +23,8 @@ interface Props { disabled?: boolean; id?: string; optionLabel?: string; + /** List of dashboard UIDs to be excluded from the select options */ + excludedDashboards?: string[]; } /** @@ -37,8 +39,9 @@ export const DashboardPickerByID: FC = ({ disabled, id, optionLabel = 'label', + excludedDashboards, }) => { - const debouncedSearch = debounce((query: string) => getDashboards(query || '', optionLabel), 300); + const debouncedSearch = debounce((query: string) => getDashboards(query || '', optionLabel, excludedDashboards), 300); const option = value ? { value, [optionLabel]: value[optionLabel] } : undefined; const onChange = (item: SelectableValue) => { propsOnChange(item?.value); @@ -62,9 +65,13 @@ export const DashboardPickerByID: FC = ({ ); }; -async function getDashboards(query: string, label: string): Promise>> { +async function getDashboards( + query: string, + label: string, + excludedDashboards?: string[] +): Promise>> { const result = await backendSrv.search({ type: 'dash-db', query, limit: 100 }); - return result.map(({ id, uid = '', title, folderTitle }) => { + const dashboards = result.map(({ id, uid = '', title, folderTitle }) => { const value: DashboardPickerItem = { id, uid, @@ -73,4 +80,10 @@ async function getDashboards(query: string, label: string): Promise !excludedDashboards.includes(value.uid as string)); + } + + return dashboards; }