Transformations: Support time format when converting time to strings (#63826)

This commit is contained in:
Ryan McKinley
2023-03-01 20:00:53 -08:00
committed by GitHub
parent bc1c54ca17
commit a4fc8b9fca
4 changed files with 77 additions and 13 deletions

View File

@@ -14,8 +14,9 @@ import {
ConvertFieldTypeOptions,
ConvertFieldTypeTransformerOptions,
} from '@grafana/data/src/transformations/transformers/convertFieldType';
import { Button, InlineField, InlineFieldRow, Input, Select } from '@grafana/ui';
import { Button, InlineField, InlineFieldRow, Input, Select, getFieldTypeIconName } from '@grafana/ui';
import { FieldNamePicker } from '@grafana/ui/src/components/MatchersUI/FieldNamePicker';
import { findField } from 'app/features/dimensions';
const fieldNamePickerSettings: StandardEditorsRegistryItem<string, FieldNamePickerConfigSettings> = {
settings: { width: 24, isClearable: false },
@@ -27,11 +28,11 @@ export const ConvertFieldTypeTransformerEditor = ({
onChange,
}: TransformerUIProps<ConvertFieldTypeTransformerOptions>) => {
const allTypes: Array<SelectableValue<FieldType>> = [
{ value: FieldType.number, label: 'Numeric' },
{ value: FieldType.string, label: 'String' },
{ value: FieldType.time, label: 'Time' },
{ value: FieldType.boolean, label: 'Boolean' },
{ value: FieldType.other, label: 'JSON' },
{ value: FieldType.number, label: 'Number', icon: getFieldTypeIconName(FieldType.number) },
{ value: FieldType.string, label: 'String', icon: getFieldTypeIconName(FieldType.string) },
{ value: FieldType.time, label: 'Time', icon: getFieldTypeIconName(FieldType.time) },
{ value: FieldType.boolean, label: 'Boolean', icon: getFieldTypeIconName(FieldType.boolean) },
{ value: FieldType.other, label: 'JSON', icon: getFieldTypeIconName(FieldType.other) },
];
const onSelectField = useCallback(
@@ -122,6 +123,11 @@ export const ConvertFieldTypeTransformerEditor = ({
<Input value={c.dateFormat} placeholder={'e.g. YYYY-MM-DD'} onChange={onInputFormat(idx)} width={24} />
</InlineField>
)}
{c.destinationType === FieldType.string && (c.dateFormat || findField(input?.[0], c.targetField)) && (
<InlineField label="Date format" tooltip="Specify the output format.">
<Input value={c.dateFormat} placeholder={'e.g. YYYY-MM-DD'} onChange={onInputFormat(idx)} width={24} />
</InlineField>
)}
<Button
size="md"
icon="trash-alt"