2019-10-25 09:43:20 -05:00
|
|
|
import React from 'react';
|
2019-10-31 04:48:05 -05:00
|
|
|
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
|
2019-11-06 09:15:08 -06:00
|
|
|
import { DataSourceHttpSettings } from '@grafana/ui';
|
2019-10-25 09:43:20 -05:00
|
|
|
import { LokiOptions } from '../types';
|
2019-11-06 09:15:08 -06:00
|
|
|
import { MaxLinesField } from './MaxLinesField';
|
|
|
|
import { DerivedFields } from './DerivedFields';
|
2019-10-25 09:43:20 -05:00
|
|
|
|
|
|
|
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');
|
2019-11-06 09:15:08 -06:00
|
|
|
const setDerivedFields = makeJsonUpdater('derivedFields');
|
2019-10-25 09:43:20 -05:00
|
|
|
|
|
|
|
export const ConfigEditor = (props: Props) => {
|
|
|
|
const { options, onOptionsChange } = props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DataSourceHttpSettings
|
|
|
|
defaultUrl={'http://localhost:3100'}
|
|
|
|
dataSourceConfig={options}
|
|
|
|
showAccessOptions={false}
|
|
|
|
onChange={onOptionsChange}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div className="gf-form-group">
|
|
|
|
<div className="gf-form-inline">
|
|
|
|
<div className="gf-form">
|
|
|
|
<MaxLinesField
|
2020-04-20 08:48:38 -05:00
|
|
|
value={options.jsonData.maxLines || ''}
|
2021-01-20 00:59:48 -06:00
|
|
|
onChange={(value) => onOptionsChange(setMaxLines(options, value))}
|
2019-10-25 09:43:20 -05:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2019-11-06 09:15:08 -06:00
|
|
|
<DerivedFields
|
|
|
|
value={options.jsonData.derivedFields}
|
2021-01-20 00:59:48 -06:00
|
|
|
onChange={(value) => onOptionsChange(setDerivedFields(options, value))}
|
2019-11-06 09:15:08 -06:00
|
|
|
/>
|
|
|
|
</>
|
2019-10-25 09:43:20 -05:00
|
|
|
);
|
|
|
|
};
|