-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAssetConfigEditor.tsx
More file actions
62 lines (59 loc) · 2.52 KB
/
AssetConfigEditor.tsx
File metadata and controls
62 lines (59 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* AssetConfigEditor is a React component that implements the UI for editing the asset
* datasource configuration options.
*/
import React, { ChangeEvent, useCallback } from 'react';
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { DataSourceHttpSettings, InlineField, InlineSegmentGroup, InlineSwitch, Tag, Text } from '@grafana/ui';
import { FeatureToggleDataSourceOptions, FeatureTogglesDefaults } from 'core/feature-toggle';
interface Props extends DataSourcePluginOptionsEditorProps<FeatureToggleDataSourceOptions> { }
export const AssetConfigEditor: React.FC<Props> = ({ options, onOptionsChange }) => {
const handleFeatureChange = useCallback((featureKey: string) => (event: ChangeEvent<HTMLInputElement>) => {
const jsonData = {
...options.jsonData,
...{ featureToggles: { ...options.jsonData.featureToggles, [featureKey]: event.target.checked } }
};
onOptionsChange({ ...options, jsonData });
}, [options, onOptionsChange]);
return (
<>
<DataSourceHttpSettings
defaultUrl=""
dataSourceConfig={options}
showAccessOptions={false}
onChange={onOptionsChange}
/>
<>
<div style={{ paddingBottom: "10px" }}>
<Text element="h6">
Features
</Text>
</div>
<InlineSegmentGroup>
<InlineField label="Asset list" labelWidth={25}>
<InlineSwitch
value={options.jsonData?.featureToggles?.assetList ?? FeatureTogglesDefaults.assetList.enabledByDefault}
onChange={handleFeatureChange('assetList')} />
</InlineField>
<Tag name='Beta' colorIndex={5} />
</InlineSegmentGroup>
<InlineSegmentGroup>
<InlineField label="Calibration forecast" labelWidth={25}>
<InlineSwitch
value={options.jsonData?.featureToggles?.calibrationForecast ?? FeatureTogglesDefaults.calibrationForecast.enabledByDefault}
onChange={handleFeatureChange('calibrationForecast')} />
</InlineField>
<Tag name='Beta' colorIndex={5} />
</InlineSegmentGroup>
<InlineSegmentGroup>
<InlineField label="Asset summary" labelWidth={25}>
<InlineSwitch
value={options.jsonData?.featureToggles?.assetSummary ?? FeatureTogglesDefaults.assetSummary.enabledByDefault}
onChange={handleFeatureChange('assetSummary')} />
</InlineField>
<Tag name='Beta' colorIndex={5} />
</InlineSegmentGroup>
</>
</>
);
}