Skip to content

Commit

Permalink
Add Date Time Parameter (#17)
Browse files Browse the repository at this point in the history
* Update Dashboard

* Update README

* Remove unused import from Server

* Add Date Time parameter
  • Loading branch information
mikhail-vl authored May 11, 2022
1 parent 32f3aeb commit d25b990
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ yarn run start
## Features

- Provides functionality to create customizable forms.
- Allows to specify GET request to get initial values and POST, PUT, PATCH request to send values updated in the form.
- Allows to fully customize Submit button.
- Supports String, Number, Boolean, Radio, Slider and Select elements.
- Supported Parameters:
- Date and Time Input
- Number Input
- Number Slider
- Radio Group with Boolean options
- Radio Group with Custom options
- Select with Custom options
- String Input
- Text Area
- Supports the Custom Code after Initial and Update requests.
- Allows to specify GET request to get initial values and POST, PUT, PATCH request to send values updated in the form.
- Allows to customize Submit, Reset buttons.

## Feedback

Expand Down
15 changes: 11 additions & 4 deletions provisioning/dashboards/panels.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"step": 1,
"title": "Step",
"type": "slider",
"value": 1
"value": 5
},
{
"id": "select",
Expand Down Expand Up @@ -224,15 +224,22 @@
"id": "text",
"rows": 4,
"title": "Text",
"type": "textarea"
"type": "textarea",
"value": "Text"
},
{
"id": "dateTime",
"title": "DateTime",
"type": "datetime",
"value": "2022-03-31T04:17:49.000Z"
}
],
"reset": {
"backgroundColor": "purple",
"foregroundColor": "yellow",
"icon": "process",
"text": "Reset",
"variant": "hidden"
"variant": "secondary"
},
"submit": {
"backgroundColor": "purple",
Expand Down Expand Up @@ -271,6 +278,6 @@
"timezone": "",
"title": "Panels",
"uid": "O4tc_E6Gz",
"version": 13,
"version": 16,
"weekStart": ""
}
1 change: 0 additions & 1 deletion server/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const http = require('http');
const fs = require('fs');

/**
* Server Port
Expand Down
15 changes: 14 additions & 1 deletion src/components/FormPanel/FormPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { ChangeEvent, useEffect, useState } from 'react';
import { css, cx } from '@emotion/css';
import { PanelProps, SelectableValue } from '@grafana/data';
import { DateTime, PanelProps, SelectableValue } from '@grafana/data';
import { getTemplateSrv, locationService } from '@grafana/runtime';
import {
Alert,
Button,
ButtonGroup,
DateTimePicker,
FieldSet,
InlineField,
InlineFieldRow,
Expand Down Expand Up @@ -259,6 +260,18 @@ export const FormPanel: React.FC<Props> = ({ options, width, height, onOptionsCh
</InlineField>
)}

{parameter.type === InputParameterType.DATETIME && (
<InlineField label={parameter.title} grow labelWidth={10}>
<DateTimePicker
date={parameter.value}
onChange={(dateTime: DateTime) => {
parameter.value = dateTime;
onOptionsChange(options);
}}
/>
</InlineField>
)}

{parameter.type === InputParameterType.SLIDER && parameter.value != null && (
<InlineField label={parameter.title} grow labelWidth={10}>
<Slider
Expand Down
29 changes: 17 additions & 12 deletions src/constants/parameter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SelectableValue } from '@grafana/data';
import { CapitalizeFirstLetter } from '../utils';

/**
* Input Parameter Type
Expand All @@ -12,39 +11,45 @@ export const enum InputParameterType {
SLIDER = 'slider',
SELECT = 'select',
TEXTAREA = 'textarea',
SECRET = 'secret',
DATETIME = 'datetime',
}

/**
* Input Parameter Type Options
*/
export const InputParameterTypeOptions: SelectableValue[] = [
{
value: InputParameterType.BOOLEAN,
label: CapitalizeFirstLetter(InputParameterType.BOOLEAN),
value: InputParameterType.DATETIME,
label: 'Date and Time Input',
},
{
value: InputParameterType.NUMBER,
label: CapitalizeFirstLetter(InputParameterType.NUMBER),
label: 'Number Input',
},
{
value: InputParameterType.RADIO,
label: CapitalizeFirstLetter(InputParameterType.RADIO),
value: InputParameterType.SLIDER,
label: 'Number Slider',
},
{
value: InputParameterType.SELECT,
label: CapitalizeFirstLetter(InputParameterType.SELECT),
value: InputParameterType.BOOLEAN,
label: 'Radio Group with Boolean options',
},
{
value: InputParameterType.SLIDER,
label: CapitalizeFirstLetter(InputParameterType.SLIDER),
value: InputParameterType.RADIO,
label: 'Radio Group with Custom options',
},
{
value: InputParameterType.SELECT,
label: 'Select with Custom options',
},
{
value: InputParameterType.STRING,
label: CapitalizeFirstLetter(InputParameterType.STRING),
label: 'String Input',
},
{
value: InputParameterType.TEXTAREA,
label: CapitalizeFirstLetter(InputParameterType.TEXTAREA),
label: 'Text Area',
},
];

Expand Down

0 comments on commit d25b990

Please sign in to comment.