grafana/public/app/plugins/datasource/graphite/configuration/MappingsConfiguration.tsx
Piotr Jamróz 04a85b1a2a
Explore: Map Graphite queries to Loki (#33405)
* Create basic prototype for Loki integration

* Simplify importing queries

* Code clean-up

* Add test coverage and info box

* Remove test data script

* Update help

* Use less space for mappings info

* Make help screen dismissable

* Make mappings help more generic

* Convert learn more to a link

* Remove unused param

* Use a link Button for help section

* Add an extra line for better formatting

* Update public/app/plugins/datasource/graphite/configuration/MappingsHelp.tsx

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Update public/app/plugins/datasource/graphite/configuration/MappingsHelp.tsx

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Re-arrange lines

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
2021-05-06 09:26:26 +02:00

76 lines
2.2 KiB
TypeScript

import React, { ChangeEvent, useState } from 'react';
import { Button, Icon, InlineField, InlineFieldRow, Input } from '@grafana/ui';
import MappingsHelp from './MappingsHelp';
type Props = {
mappings: string[];
onChange: (mappings: string[]) => void;
onDismiss: () => void;
onRestoreHelp: () => void;
showHelp: boolean;
};
export const MappingsConfiguration = (props: Props): JSX.Element => {
const [mappings, setMappings] = useState(props.mappings || []);
return (
<div>
<h3 className="page-heading">Label mappings</h3>
{!props.showHelp && (
<p>
<Button variant="link" onClick={props.onRestoreHelp}>
Learn how label mappings work
</Button>
</p>
)}
{props.showHelp && <MappingsHelp onDismiss={props.onDismiss} />}
<div className="gf-form-group">
{mappings.map((mapping, i) => (
<InlineFieldRow key={i}>
<InlineField label={`Mapping (${i + 1})`}>
<Input
width={50}
onChange={(changeEvent: ChangeEvent<HTMLInputElement>) => {
let newMappings = mappings.concat();
newMappings[i] = changeEvent.target.value;
setMappings(newMappings);
}}
onBlur={() => {
props.onChange(mappings);
}}
placeholder="e.g. test.metric.(labelName).*"
value={mapping}
/>
</InlineField>
<Button
type="button"
aria-label="Remove header"
variant="secondary"
size="xs"
onClick={(_) => {
let newMappings = mappings.concat();
newMappings.splice(i, 1);
setMappings(newMappings);
props.onChange(newMappings);
}}
>
<Icon name="trash-alt" />
</Button>
</InlineFieldRow>
))}
<Button
variant="secondary"
icon="plus"
type="button"
onClick={() => {
setMappings([...mappings, '']);
}}
>
Add label mapping
</Button>
</div>
</div>
);
};