grafana/public/app/plugins/datasource/loki/configuration/ConfigEditor.tsx
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

66 lines
1.9 KiB
TypeScript

import React from 'react';
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
import { AlertingSettings, DataSourceHttpSettings } from '@grafana/ui';
import { getAllAlertmanagerDataSources } from 'app/features/alerting/unified/utils/alertmanager';
import { LokiOptions } from '../types';
import { DerivedFields } from './DerivedFields';
import { MaxLinesField } from './MaxLinesField';
export type Props = DataSourcePluginOptionsEditorProps<LokiOptions>;
const makeJsonUpdater =
<T extends any>(field: keyof LokiOptions) =>
(options: DataSourceSettings<LokiOptions>, value: T): DataSourceSettings<LokiOptions> => {
return {
...options,
jsonData: {
...options.jsonData,
[field]: value,
},
};
};
const setMaxLines = makeJsonUpdater('maxLines');
const setDerivedFields = makeJsonUpdater('derivedFields');
export const ConfigEditor = (props: Props) => {
const { options, onOptionsChange } = props;
const alertmanagers = getAllAlertmanagerDataSources();
return (
<>
<DataSourceHttpSettings
defaultUrl={'http://localhost:3100'}
dataSourceConfig={options}
showAccessOptions={false}
onChange={onOptionsChange}
/>
<AlertingSettings<LokiOptions>
alertmanagerDataSources={alertmanagers}
options={options}
onOptionsChange={onOptionsChange}
/>
<div className="gf-form-group">
<div className="gf-form-inline">
<div className="gf-form">
<MaxLinesField
value={options.jsonData.maxLines || ''}
onChange={(value) => onOptionsChange(setMaxLines(options, value))}
/>
</div>
</div>
</div>
<DerivedFields
value={options.jsonData.derivedFields}
onChange={(value) => onOptionsChange(setDerivedFields(options, value))}
/>
</>
);
};