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] Rename operations to map exposed names for Formula #94710

Merged
merged 19 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions x-pack/plugins/lens/public/indexpattern_datasource/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
IndexPatternField,
IndexPatternLayer,
} from './types';
import { updateLayerIndexPattern } from './operations';
import { updateLayerIndexPattern, translateToOperationName } from './operations';
import { DateRange, ExistingFields } from '../../common/types';
import { BASE_API_URL } from '../../common';
import {
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function loadIndexPatterns({
const restriction =
typeMeta.aggs && typeMeta.aggs[agg] && typeMeta.aggs[agg][field.name];
if (restriction) {
restrictionsObj[agg] = restriction;
restrictionsObj[translateToOperationName(agg)] = restriction;
}
});
if (Object.keys(restrictionsObj).length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const createMockedRestrictedIndexPattern = () => {
interval: 1000,
},
},
average: {
avg: {
bytes: {
agg: 'avg',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { adjustTimeScaleOnOtherColumnChange } from '../../time_scale_utils';
import { OperationDefinition } from '..';
import { getFormatFromPreviousColumn } from '../helpers';

const OPERATION_NAME = 'differences';
export const OPERATION_NAME = 'differences';

const ofName = buildLabelFunction((name?: string) => {
return i18n.translate('xpack.lens.indexPattern.derivativeOf', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,12 @@ export const operationDefinitionMap: Record<
(definitionMap, definition) => ({ ...definitionMap, [definition.type]: definition }),
{}
);

/**
* Cannot map the prev names, but can guarantee the new names are matching up using the type system
*/
export const renameOperationsMapping: Record<string, GenericOperationDefinition['type']> = {
avg: 'average',
cardinality: 'unique_count',
derivative: 'differences',
Copy link
Contributor

Choose a reason for hiding this comment

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

Our derivative/differences implementation is not based on the Elasticsearch aggregation, it shouldn't show up here.

Copy link
Contributor Author

@dej611 dej611 Mar 24, 2021

Choose a reason for hiding this comment

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

I thought about it, but wanted to create a generic function for the renaming. Do you think this may lead to issues?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm more concerned about this being confusing - Elasticsearch derivative and Lens differences do not share anything, so it doesn't make sense to map one to the other.

};
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ import {
operationDefinitions,
GenericOperationDefinition,
OperationType,
renameOperationsMapping,
} from './definitions';
import { IndexPattern, IndexPatternField } from '../types';
import { documentField } from '../document_field';

export { operationDefinitionMap } from './definitions';

/**
* Map aggregation names from Elasticsearch to Lens names.
* Used when loading indexpatterns to map metadata (i.e. restrictions)
*/
export function translateToOperationName(agg: string): OperationType {
return agg in renameOperationsMapping ? renameOperationsMapping[agg] : (agg as OperationType);
}
/**
* Returns all available operation types as a list at runtime.
* This will be an array of each member of the union type `OperationType`
Expand Down