Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Add median operation #79453

Merged
merged 4 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ export function DimensionEditor(props: DimensionEditorProps) {
<EuiListGroup
className={sideNavItems.length > 3 ? 'lnsIndexPatternDimensionEditor__columns' : ''}
gutterSize="none"
listItems={sideNavItems}
listItems={
// add a padding item containing a non breakable space if the number of operations is not even
// otherwise the column layout will break within an element
sideNavItems.length % 2 === 1 ? [...sideNavItems, { label: '\u00a0' }] : sideNavItems
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution is fine with me so long as it doesn't create an item that behaves inertactable with a blank label.

}
maxWidth={false}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,11 @@ describe('IndexPatternDimensionEditorPanel', () => {
'Average',
'Count',
'Maximum',
'Median',
'Minimum',
'Sum',
'Unique count',
'\u00a0',
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
SumIndexPatternColumn,
maxOperation,
MaxIndexPatternColumn,
medianOperation,
MedianIndexPatternColumn,
} from './metrics';
import { dateHistogramOperation, DateHistogramIndexPatternColumn } from './date_histogram';
import { countOperation, CountIndexPatternColumn } from './count';
Expand All @@ -43,6 +45,7 @@ export type IndexPatternColumn =
| AvgIndexPatternColumn
| CardinalityIndexPatternColumn
| SumIndexPatternColumn
| MedianIndexPatternColumn
| CountIndexPatternColumn;

export type FieldBasedIndexPatternColumn = Extract<IndexPatternColumn, { sourceField: string }>;
Expand All @@ -59,6 +62,7 @@ const internalOperationDefinitions = [
averageOperation,
cardinalityOperation,
sumOperation,
medianOperation,
countOperation,
rangeOperation,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export type SumIndexPatternColumn = MetricColumn<'sum'>;
export type AvgIndexPatternColumn = MetricColumn<'avg'>;
export type MinIndexPatternColumn = MetricColumn<'min'>;
export type MaxIndexPatternColumn = MetricColumn<'max'>;
export type MedianIndexPatternColumn = MetricColumn<'median'>;

export const minOperation = buildMetricOperation<MinIndexPatternColumn>({
type: 'min',
Expand Down Expand Up @@ -137,3 +138,15 @@ export const sumOperation = buildMetricOperation<SumIndexPatternColumn>({
values: { name },
}),
});

export const medianOperation = buildMetricOperation<MedianIndexPatternColumn>({
type: 'median',
displayName: i18n.translate('xpack.lens.indexPattern.median', {
defaultMessage: 'Median',
}),
ofName: (name) =>
i18n.translate('xpack.lens.indexPattern.medianOf', {
defaultMessage: 'Median of {name}',
values: { name },
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ describe('getOperationTypesForField', () => {
},
Object {
"field": "bytes",
"operationType": "min",
"operationType": "max",
"type": "field",
},
Object {
"field": "bytes",
"operationType": "max",
"operationType": "min",
"type": "field",
},
Object {
Expand All @@ -338,6 +338,11 @@ describe('getOperationTypesForField', () => {
"operationType": "cardinality",
"type": "field",
},
Object {
"field": "bytes",
"operationType": "median",
"type": "field",
},
],
},
]
Expand Down