Files
Ashley Harrison 47f8717149 React: Use new JSX transform (#88802)
* update eslint, tsconfig + esbuild to handle new jsx transform

* remove thing that breaks the new jsx transform

* remove react imports

* adjust grafana-icons build

* is this the correct syntax?

* try this

* well this was much easier than expected...

* change grafana-plugin-configs webpack config

* fixes

* fix lockfile

* fix 2 more violations

* use path.resolve instead of require.resolve

* remove react import

* fix react imports

* more fixes

* remove React import

* remove import React from docs

* remove another react import
2024-06-25 12:43:47 +01:00

78 lines
2.2 KiB
TypeScript

import { ChangeEvent, useState } from 'react';
import { Box, 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 fill="text" onClick={props.onRestoreHelp}>
Learn how label mappings work
</Button>
</p>
)}
{props.showHelp && <MappingsHelp onDismiss={props.onDismiss} />}
<Box marginBottom={5}>
{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>
</Box>
</div>
);
};