Files
grafana/public/app/plugins/datasource/loki/components/ConfigEditor.tsx
Dominik Prokop 9b7748ec13 Chore: Reorg packages (#20111)
Primarily- moving majority of the types and utils from @grafana/ui to @grafana/data

* Move types from grafana-ui to grafana-data

* Move valueFormats to grafana-data

* Move utils from grafana-ui to grafana-data

* Update imports in grafana-ui

* revert data's tsconfig change

* Update imports in grafana-runtime

* Fix import paths in grafana-ui

* Move rxjs to devDeps

* Core import updates batch 1

* Import updates batch 2

* Imports fix batch 3

* Imports fixes batch i don't know

* Fix imorts in grafana-toolkit

* Fix imports after master merge
2019-10-31 10:48:05 +01:00

81 lines
2.1 KiB
TypeScript

import React from 'react';
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
import { FormField, DataSourceHttpSettings } from '@grafana/ui';
import { LokiOptions } from '../types';
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');
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
value={options.jsonData.maxLines}
onChange={value => onOptionsChange(setMaxLines(options, value))}
/>
</div>
</div>
</div>
</>
);
};
type MaxLinesFieldProps = {
value: string;
onChange: (value: string) => void;
};
const MaxLinesField = (props: MaxLinesFieldProps) => {
const { value, onChange } = props;
return (
<FormField
label="Maximum lines"
labelWidth={11}
inputWidth={20}
inputEl={
<input
type="number"
className="gf-form-input width-8 gf-form-input--has-help-icon"
value={value}
onChange={event => onChange(event.currentTarget.value)}
spellCheck={false}
placeholder="1000"
/>
}
tooltip={
<>
Loki queries must contain a limit of the maximum number of lines returned (default: 1000). Increase this limit
to have a bigger result set for ad-hoc analysis. Decrease this limit if your browser becomes sluggish when
displaying the log results.
</>
}
/>
);
};