From 1bde2307ed753dc93ff7236d070fef8a3aac2987 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 8 Dec 2021 08:42:45 -0800 Subject: [PATCH] Dashlist: options cleanup (#42850) --- .../app/plugins/panel/dashlist/DashList.tsx | 55 ++++++++++--------- public/app/plugins/panel/dashlist/module.tsx | 20 +++---- public/app/plugins/panel/dashlist/types.ts | 10 ---- 3 files changed, 40 insertions(+), 45 deletions(-) delete mode 100644 public/app/plugins/panel/dashlist/types.ts diff --git a/public/app/plugins/panel/dashlist/DashList.tsx b/public/app/plugins/panel/dashlist/DashList.tsx index aedaa53a8a3..861fa0f42a6 100644 --- a/public/app/plugins/panel/dashlist/DashList.tsx +++ b/public/app/plugins/panel/dashlist/DashList.tsx @@ -10,8 +10,8 @@ import { getBackendSrv } from 'app/core/services/backend_srv'; import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; import impressionSrv from 'app/core/services/impression_srv'; import { DashboardSearchHit } from 'app/features/search/types'; -import { DashListOptions } from './types'; import { getStyles } from './styles'; +import { PanelOptions } from './models.gen'; type Dashboard = DashboardSearchHit & { isSearchResult?: boolean; isRecent?: boolean }; @@ -21,7 +21,7 @@ interface DashboardGroup { dashboards: Dashboard[]; } -async function fetchDashboards(options: DashListOptions, replaceVars: InterpolateFunction) { +async function fetchDashboards(options: PanelOptions, replaceVars: InterpolateFunction) { let starredDashboards: Promise = Promise.resolve([]); if (options.showStarred) { const params = { limit: options.maxItems, starred: 'true' }; @@ -78,7 +78,7 @@ async function fetchDashboards(options: DashListOptions, replaceVars: Interpolat return dashMap; } -export function DashList(props: PanelProps) { +export function DashList(props: PanelProps) { const [dashboards, setDashboards] = useState(new Map()); useEffect(() => { fetchDashboards(props.options, props.replaceVariables).then((dashes) => { @@ -126,6 +126,32 @@ export function DashList(props: PanelProps) { ]; const css = useStyles2(getStyles); + + const renderList = (dashboards: Dashboard[]) => ( +
    + {dashboards.map((dash) => ( +
  • +
    +
    + + {dash.title} + + {dash.folderTitle &&
    {dash.folderTitle}
    } +
    + toggleDashboardStar(e, dash)} + /> +
    +
  • + ))} +
+ ); + return ( {dashboardGroups.map( @@ -133,28 +159,7 @@ export function DashList(props: PanelProps) { show && (
{showHeadings &&
{header}
} -
    - {dashboards.map((dash) => ( -
  • -
    -
    - - {dash.title} - - {dash.folderTitle &&
    {dash.folderTitle}
    } -
    - toggleDashboardStar(e, dash)} - /> -
    -
  • - ))} -
+ {renderList(dashboards)}
) )} diff --git a/public/app/plugins/panel/dashlist/module.tsx b/public/app/plugins/panel/dashlist/module.tsx index f57f224f948..12f935edd5b 100644 --- a/public/app/plugins/panel/dashlist/module.tsx +++ b/public/app/plugins/panel/dashlist/module.tsx @@ -1,6 +1,5 @@ import { PanelModel, PanelPlugin } from '@grafana/data'; import { DashList } from './DashList'; -import { DashListOptions } from './types'; import React from 'react'; import { TagsInput } from '@grafana/ui'; import { @@ -8,39 +7,40 @@ import { GENERAL_FOLDER, ReadonlyFolderPicker, } from '../../../core/components/Select/ReadonlyFolderPicker/ReadonlyFolderPicker'; +import { defaultPanelOptions, PanelOptions } from './models.gen'; -export const plugin = new PanelPlugin(DashList) +export const plugin = new PanelPlugin(DashList) .setPanelOptions((builder) => { builder .addBooleanSwitch({ path: 'showStarred', name: 'Starred', - defaultValue: true, + defaultValue: defaultPanelOptions.showStarred, }) .addBooleanSwitch({ path: 'showRecentlyViewed', name: 'Recently viewed', - defaultValue: false, + defaultValue: defaultPanelOptions.showRecentlyViewed, }) .addBooleanSwitch({ path: 'showSearch', name: 'Search', - defaultValue: false, + defaultValue: defaultPanelOptions.showSearch, }) .addBooleanSwitch({ path: 'showHeadings', name: 'Show headings', - defaultValue: true, + defaultValue: defaultPanelOptions.showHeadings, }) .addNumberInput({ path: 'maxItems', name: 'Max items', - defaultValue: 10, + defaultValue: defaultPanelOptions.maxItems, }) .addTextInput({ path: 'query', name: 'Query', - defaultValue: '', + defaultValue: defaultPanelOptions.query, }) .addCustomEditor({ path: 'folderId', @@ -62,13 +62,13 @@ export const plugin = new PanelPlugin(DashList) path: 'tags', name: 'Tags', description: '', - defaultValue: [], + defaultValue: defaultPanelOptions.tags, editor(props) { return ; }, }); }) - .setMigrationHandler((panel: PanelModel & Record) => { + .setMigrationHandler((panel: PanelModel & Record) => { const newOptions = { showStarred: panel.options.showStarred ?? panel.starred, showRecentlyViewed: panel.options.showRecentlyViewed ?? panel.recent, diff --git a/public/app/plugins/panel/dashlist/types.ts b/public/app/plugins/panel/dashlist/types.ts deleted file mode 100644 index 7456b335869..00000000000 --- a/public/app/plugins/panel/dashlist/types.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface DashListOptions { - showStarred: boolean; - showRecentlyViewed: boolean; - showSearch: boolean; - showHeadings: boolean; - maxItems: number; - query: string; - folderId: number; - tags: string[]; -}