diff --git a/packages/grafana-ui/src/components/Forms/InlineField.tsx b/packages/grafana-ui/src/components/Forms/InlineField.tsx index 3e90f436314..e6d9542f07a 100644 --- a/packages/grafana-ui/src/components/Forms/InlineField.tsx +++ b/packages/grafana-ui/src/components/Forms/InlineField.tsx @@ -59,19 +59,11 @@ const getStyles = (theme: GrafanaTheme, grow?: boolean) => { container: css` display: flex; flex-direction: row; - align-items: center; + align-items: flex-start; text-align: left; position: relative; flex: ${grow ? 1 : 0} 0 auto; margin: 0 ${theme.spacing.xs} ${theme.spacing.xs} 0; `, - wrapper: css` - display: flex; - width: 100%; - `, - - fillContainer: css` - flex-grow: 1; - `, }; }; diff --git a/packages/grafana-ui/src/components/Forms/InlineFieldRow.tsx b/packages/grafana-ui/src/components/Forms/InlineFieldRow.tsx index ed079306ec5..be01e437357 100644 --- a/packages/grafana-ui/src/components/Forms/InlineFieldRow.tsx +++ b/packages/grafana-ui/src/components/Forms/InlineFieldRow.tsx @@ -1,6 +1,7 @@ import React, { FC, HTMLProps, ReactNode } from 'react'; import { css, cx } from 'emotion'; import { useStyles } from '../../themes'; +import { GrafanaTheme } from '@grafana/data'; export interface Props extends Omit, 'css'> { children: ReactNode | ReactNode[]; @@ -15,7 +16,7 @@ export const InlineFieldRow: FC = ({ children, className, ...htmlProps }) ); }; -const getStyles = () => { +const getStyles = (theme: GrafanaTheme) => { return { container: css` label: InlineFieldRow; diff --git a/packages/grafana-ui/src/components/Forms/InlineLabel.tsx b/packages/grafana-ui/src/components/Forms/InlineLabel.tsx index 3ed8e6afb0f..9c7b3c9972f 100644 --- a/packages/grafana-ui/src/components/Forms/InlineLabel.tsx +++ b/packages/grafana-ui/src/components/Forms/InlineLabel.tsx @@ -18,21 +18,31 @@ export interface Props extends Omit = ({ children, className, tooltip, width, ...rest }) => { +export const InlineLabel: FunctionComponent = ({ + children, + className, + tooltip, + width, + as: Component = 'label', + ...rest +}) => { const theme = useTheme(); const styles = getInlineLabelStyles(theme, width); return ( - + ); }; diff --git a/packages/grafana-ui/src/components/Forms/InlineSegmentGroup.tsx b/packages/grafana-ui/src/components/Forms/InlineSegmentGroup.tsx new file mode 100644 index 00000000000..e733a47e38b --- /dev/null +++ b/packages/grafana-ui/src/components/Forms/InlineSegmentGroup.tsx @@ -0,0 +1,37 @@ +import React, { FC } from 'react'; +import { cx, css } from 'emotion'; +import { GrafanaTheme } from '@grafana/data'; +import { useTheme } from '../../themes'; + +export interface Props { + grow?: boolean; + className?: string; +} + +/** @beta */ +export const InlineSegmentGroup: FC = ({ children, className, grow, ...htmlProps }) => { + const theme = useTheme(); + const styles = getStyles(theme, grow); + + return ( +
+ {children} +
+ ); +}; + +InlineSegmentGroup.displayName = 'InlineSegmentGroup'; + +const getStyles = (theme: GrafanaTheme, grow?: boolean) => { + return { + container: css` + display: flex; + flex-direction: row; + align-items: flex-start; + text-align: left; + position: relative; + flex: ${grow ? 1 : 0} 0 auto; + margin-bottom: ${theme.spacing.xs}; + `, + }; +}; diff --git a/packages/grafana-ui/src/components/index.ts b/packages/grafana-ui/src/components/index.ts index 99270e0b8d8..6469d52a6c2 100644 --- a/packages/grafana-ui/src/components/index.ts +++ b/packages/grafana-ui/src/components/index.ts @@ -152,6 +152,7 @@ export { Legend } from './Forms/Legend'; export { FieldSet } from './Forms/FieldSet'; export { FieldValidationMessage } from './Forms/FieldValidationMessage'; export { InlineField } from './Forms/InlineField'; +export { InlineSegmentGroup } from './Forms/InlineSegmentGroup'; export { InlineLabel } from './Forms/InlineLabel'; export { InlineFieldRow } from './Forms/InlineFieldRow'; export { FieldArray } from './Forms/FieldArray'; diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/BucketAggregationEditor.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/BucketAggregationEditor.tsx index 2976467f396..f026d5715f1 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/BucketAggregationEditor.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/BucketAggregationEditor.tsx @@ -1,5 +1,5 @@ import { MetricFindValue, SelectableValue } from '@grafana/data'; -import { Segment, SegmentAsync } from '@grafana/ui'; +import { InlineSegmentGroup, Segment, SegmentAsync } from '@grafana/ui'; import React, { FunctionComponent } from 'react'; import { useDispatch } from '../../../hooks/useStatelessReducer'; import { useDatasource } from '../ElasticsearchQueryContext'; @@ -53,22 +53,24 @@ export const BucketAggregationEditor: FunctionComponent return ( <> - dispatch(changeBucketAggregationType(value.id, e.value!))} - value={toOption(value)} - /> - - {isBucketAggregationWithField(value) && ( - + dispatch(changeBucketAggregationField(value.id, e.value))} - placeholder="Select Field" - value={value.field} + options={bucketAggOptions} + onChange={e => dispatch(changeBucketAggregationType(value.id, e.value!))} + value={toOption(value)} /> - )} + + {isBucketAggregationWithField(value) && ( + dispatch(changeBucketAggregationField(value.id, e.value))} + placeholder="Select Field" + value={value.field} + /> + )} + diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/MetricEditor.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/MetricEditor.tsx index 8b48c8025b2..c55287ced5b 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/MetricEditor.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/MetricEditor.tsx @@ -1,5 +1,5 @@ import { MetricFindValue, SelectableValue } from '@grafana/data'; -import { Segment, SegmentAsync, useTheme } from '@grafana/ui'; +import { InlineSegmentGroup, Segment, SegmentAsync, useTheme } from '@grafana/ui'; import { cx } from 'emotion'; import React, { FunctionComponent } from 'react'; import { useDatasource, useQuery } from '../ElasticsearchQueryContext'; @@ -88,31 +88,33 @@ export const MetricEditor: FunctionComponent = ({ value }) => { return ( <> - dispatch(changeMetricType(value.id, e.value!))} - value={toOption(value)} - /> - - {isMetricAggregationWithField(value) && !isPipelineAggregation(value) && ( - + dispatch(changeMetricField(value.id, e.value!))} - placeholder="Select Field" - value={value.field} + options={getTypeOptions(previousMetrics, datasource.esVersion)} + onChange={e => dispatch(changeMetricType(value.id, e.value!))} + value={toOption(value)} /> - )} - {isPipelineAggregation(value) && !isPipelineAggregationWithMultipleBucketPaths(value) && ( - dispatch(changeMetricField(value.id, e.value?.id!))} - options={previousMetrics} - value={value.field} - /> - )} + {isMetricAggregationWithField(value) && !isPipelineAggregation(value) && ( + dispatch(changeMetricField(value.id, e.value!))} + placeholder="Select Field" + value={value.field} + /> + )} + + {isPipelineAggregation(value) && !isPipelineAggregationWithMultipleBucketPaths(value) && ( + dispatch(changeMetricField(value.id, e.value?.id!))} + options={previousMetrics} + value={value.field} + /> + )} + {isMetricAggregationWithSettings(value) && } diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/QueryEditorRow.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/QueryEditorRow.tsx index b48f12354f0..b4dfe932fc2 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/QueryEditorRow.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/QueryEditorRow.tsx @@ -1,6 +1,5 @@ import { GrafanaTheme } from '@grafana/data'; -import { IconButton, stylesFactory, useTheme } from '@grafana/ui'; -import { getInlineLabelStyles } from '@grafana/ui/src/components/Forms/InlineLabel'; +import { IconButton, InlineFieldRow, InlineLabel, InlineSegmentGroup, stylesFactory, useTheme } from '@grafana/ui'; import { css } from 'emotion'; import { noop } from 'lodash'; import React, { FunctionComponent } from 'react'; @@ -23,44 +22,43 @@ export const QueryEditorRow: FunctionComponent = ({ const styles = getStyles(theme); return ( -
-
- {label} - {onHideClick && ( - - )} - -
+ + + + {label} + + {onHideClick && ( + + )} + + + + {children} -
+ ); }; const getStyles = stylesFactory((theme: GrafanaTheme) => { return { - root: css` + iconWrapper: css` display: flex; - margin-bottom: ${theme.spacing.xs}; - `, - label: css` - font-size: ${theme.typography.size.sm}; - margin: 0; `, icon: css` color: ${theme.colors.textWeak}; diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/SettingsEditorContainer.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/SettingsEditorContainer.tsx index 13d48b1d1d3..f8df93f57a7 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/SettingsEditorContainer.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/SettingsEditorContainer.tsx @@ -1,5 +1,5 @@ import { GrafanaTheme } from '@grafana/data'; -import { Icon, stylesFactory, useTheme } from '@grafana/ui'; +import { Icon, InlineSegmentGroup, stylesFactory, useTheme } from '@grafana/ui'; import { css, cx } from 'emotion'; import React, { FunctionComponent, useState } from 'react'; import { segmentStyles } from './styles'; @@ -32,21 +32,22 @@ interface Props { export const SettingsEditorContainer: FunctionComponent = ({ label, children, hidden = false }) => { const [open, setOpen] = useState(false); - const styles = getStyles(useTheme(), hidden); return ( -
- + +
+ - {open &&
{children}
} -
+ {open &&
{children}
} +
+ ); };