setup form

This commit is contained in:
Nico Melone
2021-10-13 10:03:19 -05:00
parent a0a560a4df
commit 25e5592433
6 changed files with 3724 additions and 623 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -2,35 +2,62 @@ import React from 'react';
import { PanelProps } from '@grafana/data'; import { PanelProps } from '@grafana/data';
import { SimpleOptions } from 'types'; import { SimpleOptions } from 'types';
import { css, cx } from 'emotion'; import { css, cx } from 'emotion';
import { stylesFactory } from '@grafana/ui'; import { stylesFactory, Field, Input, Form, Button } from '@grafana/ui';
interface Props extends PanelProps<SimpleOptions> {} interface Props extends PanelProps<SimpleOptions> {}
export const SimplePanel: React.FC<Props> = ({ options, data, width, height }) => { export const SimplePanel: React.FC<Props> = ({ options, data, width, height }) => {
const styles = getStyles(); const styles = getStyles();
let form; let form;
interface numberInput {
value: number;
}
let sendValue: numberInput = { value: options.default };
function FormWithInput() { function FormWithInput() {
return ( return (
<form onSubmit={sendRequest} className={styles.form}> <Form
<label> defaultValues={sendValue}
{options.text}: onSubmit={(userinput: numberInput) => {
<input type="number" name="testinput" /> console.log(userinput.value);
</label> sendRequest(userinput.value);
<input type="submit" value="Send" /> }}
</form> >
{({ register, errors }) => {
return (
<div>
<Field label={options.text}>
<Input css={undefined} id="test" type="number" step={0.01} {...register('value')} />
</Field>
<Button type="submit">Test Button</Button>
</div>
);
}}
</Form>
); );
} }
function FormWithoutInput() { function FormWithoutInput() {
return ( return (
<form> <Form
<input type="submit" value="Send" /> defaultValues={sendValue}
</form> onSubmit={(userinput: numberInput) => {
console.log(userinput.value);
sendRequest(userinput.value);
}}
>
{({ register, errors }) => {
return (
<div>
<Button type="submit">Test Button</Button>
</div>
);
}}
</Form>
); );
} }
function sendRequest(event: any) { function sendRequest(event: number) {
fetch(options.url + { event }).then(() => alert('It worked')); //console.log(event);
fetch(options.url + event).then(response => console.log(response));
} }
if (options.showInputField) { if (options.showInputField) {

View File

@@ -20,6 +20,11 @@ export const plugin = new PanelPlugin<SimpleOptions>(SimplePanel).setPanelOption
name: 'Destination URL', name: 'Destination URL',
description: 'The destination URL for the request' description: 'The destination URL for the request'
}) })
.addNumberInput({
path: 'default',
name: 'default number',
description: 'a default number for the input'
})
/* .addRadio({ /* .addRadio({
path: 'seriesCountSize', path: 'seriesCountSize',
defaultValue: 'sm', defaultValue: 'sm',

View File

@@ -2,4 +2,5 @@ export interface SimpleOptions {
text: string; text: string;
showInputField: boolean; showInputField: boolean;
url: string; url: string;
default: number;
} }

File diff suppressed because it is too large Load Diff