Skip to content

Commit

Permalink
Add theme suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
asimonok committed Mar 14, 2024
1 parent f6e5cde commit 8b946b4
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/utils/code-parameters.ts
Original file line number Diff line number Diff line change
@@ -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 = <TObject extends object>(theme: TObject, detail: string): any => ({

Check warning on line 14 in src/utils/code-parameters.ts

View workflow job for this annotation

GitHub Actions / tests

Unexpected any. Specify a different type

Check warning on line 14 in src/utils/code-parameters.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

Check warning on line 14 in src/utils/code-parameters.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
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<typeof value>(key),
};
}, {}),
},
});

/**
* Base Code Parameters Config
*/
Expand All @@ -28,7 +52,7 @@ const baseParametersConfig = {
'Interpolate variables.',
CodeEditorSuggestionItemKind.Method
),
theme: new CodeParameterItem<GrafanaTheme2>('Location service.'),
theme: getThemeParams(getTheme(), 'Theme object'),
notifySuccess: new CodeParameterItem<(payload: AlertPayload) => void>(
'Display successful notification.',
CodeEditorSuggestionItemKind.Method
Expand Down

0 comments on commit 8b946b4

Please sign in to comment.