import { ReactNode, useMemo } from 'react'; import { selectors } from '@grafana/e2e-selectors'; import { sceneGraph, SceneGridRow, VizPanel } from '@grafana/scenes'; import { Alert, Button, Input, TextLink } from '@grafana/ui'; import { t, Trans } from 'app/core/internationalization'; import { OptionsPaneCategoryDescriptor } from 'app/features/dashboard/components/PanelEditor/OptionsPaneCategoryDescriptor'; import { OptionsPaneItemDescriptor } from 'app/features/dashboard/components/PanelEditor/OptionsPaneItemDescriptor'; import { RepeatRowSelect2 } from 'app/features/dashboard/components/RepeatRowSelect/RepeatRowSelect'; import { SHARED_DASHBOARD_QUERY } from 'app/plugins/datasource/dashboard/constants'; import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource'; import { getDashboardSceneFor, getLayoutManagerFor, getQueryRunnerFor } from '../../utils/utils'; import { DashboardScene } from '../DashboardScene'; import { BulkActionElement } from '../types/BulkActionElement'; import { EditableDashboardElement, EditableDashboardElementInfo } from '../types/EditableDashboardElement'; import { DefaultGridLayoutManager } from './DefaultGridLayoutManager'; import { RowRepeaterBehavior } from './RowRepeaterBehavior'; export class SceneGridRowEditableElement implements EditableDashboardElement, BulkActionElement { public readonly isEditableDashboardElement = true; public constructor(private _row: SceneGridRow) {} public getEditableElementInfo(): EditableDashboardElementInfo { return { typeId: 'panel', icon: 'line-alt', name: sceneGraph.interpolate(this._row, this._row.state.title, undefined, 'text'), }; } public useEditPaneOptions(): OptionsPaneCategoryDescriptor[] { const row = this._row; const rowOptions = useMemo(() => { return new OptionsPaneCategoryDescriptor({ title: t('dashboard.default-layout.row-options.title', 'Row options'), id: 'row-options', isOpenDefault: true, }).addItem( new OptionsPaneItemDescriptor({ title: t('dashboard.default-layout.row-options.form.title', 'Title'), render: () => , }) ); }, [row]); const rowRepeatOptions = useMemo(() => { const dashboard = getDashboardSceneFor(row); return new OptionsPaneCategoryDescriptor({ title: t('dashboard.default-layout.row-options.repeat.title', 'Repeat options'), id: 'row-repeat-options', isOpenDefault: true, }).addItem( new OptionsPaneItemDescriptor({ title: t('dashboard.default-layout.row-options.repeat.variable.title', 'Variable'), render: () => , }) ); }, [row]); return [rowOptions, rowRepeatOptions]; } public onDelete() { const layoutManager = getLayoutManagerFor(this._row); if (layoutManager instanceof DefaultGridLayoutManager) { layoutManager.removeRow(this._row); } } public renderActions(): ReactNode { return ( <> this.onDelete()} icon="trash-alt" /> > ); } } function RowTitleInput({ row }: { row: SceneGridRow }) { const { title } = row.useState(); return row.setState({ title: e.currentTarget.value })} />; } function RowRepeatSelect({ row, dashboard }: { row: SceneGridRow; dashboard: DashboardScene }) { const { $behaviors, children } = row.useState(); let repeatBehavior = $behaviors?.find((b) => b instanceof RowRepeaterBehavior); const vizPanels = useMemo( () => children.reduce((acc, child) => [...acc, ...sceneGraph.findDescendents(child, VizPanel)], []), [children] ); const isAnyPanelUsingDashboardDS = vizPanels.some((vizPanel) => { const runner = getQueryRunnerFor(vizPanel); return ( runner?.state.datasource?.uid === SHARED_DASHBOARD_QUERY || (runner?.state.datasource?.uid === MIXED_DATASOURCE_NAME && runner?.state.queries.some((query) => query.datasource?.uid === SHARED_DASHBOARD_QUERY)) ); }); return ( <> { if (repeat) { repeatBehavior?.removeBehavior(); repeatBehavior = new RowRepeaterBehavior({ variableName: repeat }); row.setState({ $behaviors: [...(row.state.$behaviors ?? []), repeatBehavior] }); } else { repeatBehavior?.removeBehavior(); } }} /> {isAnyPanelUsingDashboardDS ? ( Panels in this row use the {{ SHARED_DASHBOARD_QUERY }} data source. These panels will reference the panel in the original row, not the ones in the repeated rows. Learn more ) : undefined} > ); }
Panels in this row use the {{ SHARED_DASHBOARD_QUERY }} data source. These panels will reference the panel in the original row, not the ones in the repeated rows.