WIP
This commit is contained in:
+25
-3
@@ -10,7 +10,8 @@ import {
|
|||||||
TransformerCategory,
|
TransformerCategory,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { t } from '@grafana/i18n';
|
import { t } from '@grafana/i18n';
|
||||||
import { fieldMatchersUI, InlineField, InlineFieldRow, Select, useStyles2 } from '@grafana/ui';
|
import { Checkbox, fieldMatchersUI, InlineField, InlineFieldRow, Select, useStyles2 } from '@grafana/ui';
|
||||||
|
import { FieldNamePicker } from '@grafana/ui/internal';
|
||||||
|
|
||||||
import { getTransformationContent } from '../docs/getTransformationContent';
|
import { getTransformationContent } from '../docs/getTransformationContent';
|
||||||
import { FieldToConfigMappingEditor } from '../fieldToConfigMapping/FieldToConfigMappingEditor';
|
import { FieldToConfigMappingEditor } from '../fieldToConfigMapping/FieldToConfigMappingEditor';
|
||||||
@@ -21,6 +22,13 @@ import { getConfigFromDataTransformer, ConfigFromQueryTransformOptions } from '.
|
|||||||
|
|
||||||
export interface Props extends TransformerUIProps<ConfigFromQueryTransformOptions> {}
|
export interface Props extends TransformerUIProps<ConfigFromQueryTransformOptions> {}
|
||||||
|
|
||||||
|
const fieldNamePickerSettings = {
|
||||||
|
editor: FieldNamePicker,
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
settings: { width: 24, isClearable: false },
|
||||||
|
};
|
||||||
|
|
||||||
export function ConfigFromQueryTransformerEditor({ input, onChange, options }: Props) {
|
export function ConfigFromQueryTransformerEditor({ input, onChange, options }: Props) {
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
|
|
||||||
@@ -41,6 +49,13 @@ export function ConfigFromQueryTransformerEditor({ input, onChange, options }: P
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onMappingChange = (value: SelectableValue<boolean>) => {
|
||||||
|
onChange({
|
||||||
|
...options,
|
||||||
|
isMapping: value.value || false,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const onMatcherChange = (value: SelectableValue<string>) => {
|
const onMatcherChange = (value: SelectableValue<string>) => {
|
||||||
onChange({ ...options, applyTo: { id: value.value! } });
|
onChange({ ...options, applyTo: { id: value.value! } });
|
||||||
};
|
};
|
||||||
@@ -85,14 +100,21 @@ export function ConfigFromQueryTransformerEditor({ input, onChange, options }: P
|
|||||||
onChange={onMatcherConfigChange}
|
onChange={onMatcherConfigChange}
|
||||||
/>
|
/>
|
||||||
</InlineField>
|
</InlineField>
|
||||||
|
<InlineField>
|
||||||
|
<Checkbox
|
||||||
|
label={t('transformers.config-from-query-transformer-editor.label-mapping', 'Map results')}
|
||||||
|
onChange={onMappingChange}
|
||||||
|
value={options.isMapping}
|
||||||
|
/>
|
||||||
|
</InlineField>
|
||||||
</InlineFieldRow>
|
</InlineFieldRow>
|
||||||
<InlineFieldRow>
|
<InlineFieldRow>
|
||||||
{configFrame && (
|
{configFrame && !options.isMapping && (
|
||||||
<FieldToConfigMappingEditor
|
<FieldToConfigMappingEditor
|
||||||
frame={configFrame}
|
frame={configFrame}
|
||||||
mappings={options.mappings}
|
mappings={options.mappings}
|
||||||
onChange={(mappings) => onChange({ ...options, mappings })}
|
onChange={(mappings) => onChange({ ...options, mappings })}
|
||||||
withReducers
|
withReducers={!options.isMapping}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</InlineFieldRow>
|
</InlineFieldRow>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export interface ConfigFromQueryTransformOptions {
|
|||||||
configRefId?: string;
|
configRefId?: string;
|
||||||
mappings: FieldToConfigMapping[];
|
mappings: FieldToConfigMapping[];
|
||||||
applyTo?: MatcherConfig;
|
applyTo?: MatcherConfig;
|
||||||
|
isMapping?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractConfigFromQuery(options: ConfigFromQueryTransformOptions, data: DataFrame[]) {
|
export function extractConfigFromQuery(options: ConfigFromQueryTransformOptions, data: DataFrame[]) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export interface FieldToConfigMapping {
|
|||||||
reducerId?: ReducerID;
|
reducerId?: ReducerID;
|
||||||
handlerKey: string | null;
|
handlerKey: string | null;
|
||||||
handlerArguments?: HandlerArguments;
|
handlerArguments?: HandlerArguments;
|
||||||
|
sourceFieldName?: string; // for mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user