From 8b946b46517c5aa9db9f52e6e287edb27dc15cea Mon Sep 17 00:00:00 2001 From: asimonok Date: Thu, 14 Mar 2024 17:25:02 +0300 Subject: [PATCH] Add theme suggestions --- src/utils/code-parameters.ts | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/utils/code-parameters.ts b/src/utils/code-parameters.ts index 7da5e32..6d87cde 100644 --- a/src/utils/code-parameters.ts +++ b/src/utils/code-parameters.ts @@ -1,11 +1,35 @@ -import { AlertPayload, EventBus, GrafanaTheme2, InterpolateFunction, PanelData } from '@grafana/data'; +import { AlertPayload, EventBus, InterpolateFunction, PanelData } from '@grafana/data'; import { LocationService } from '@grafana/runtime'; -import { CodeEditorSuggestionItemKind } from '@grafana/ui'; +import { CodeEditorSuggestionItemKind, getTheme } from '@grafana/ui'; import { CodeParameterItem, CodeParametersBuilder } from '@volkovlabs/components'; import { ECharts } from 'echarts'; import { SeriesItem } from '../types'; +/** + * Get theme params + * @param theme + * @param detail + */ +const getThemeParams = (theme: TObject, detail: string): any => ({ + detail, + items: { + ...Object.entries(theme).reduce((acc, [key, value]) => { + if (typeof value === 'object' && !Array.isArray(value)) { + return { + ...acc, + [key]: getThemeParams(value, key), + }; + } + + return { + ...acc, + [key]: new CodeParameterItem(key), + }; + }, {}), + }, +}); + /** * Base Code Parameters Config */ @@ -28,7 +52,7 @@ const baseParametersConfig = { 'Interpolate variables.', CodeEditorSuggestionItemKind.Method ), - theme: new CodeParameterItem('Location service.'), + theme: getThemeParams(getTheme(), 'Theme object'), notifySuccess: new CodeParameterItem<(payload: AlertPayload) => void>( 'Display successful notification.', CodeEditorSuggestionItemKind.Method