Skip to content

Commit

Permalink
fix bug and another consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Nov 17, 2021
1 parent 99673cd commit b4d509e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
44 changes: 21 additions & 23 deletions x-pack/plugins/lens/public/indexpattern_datasource/to_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { GenericIndexPatternColumn } from './indexpattern';
import { operationDefinitionMap } from './operations';
import { IndexPattern, IndexPatternPrivateState, IndexPatternLayer } from './types';
import { DateHistogramIndexPatternColumn, RangeIndexPatternColumn } from './operations/definitions';
import { isColumnOfType } from './operations/definitions/helpers';
import { FormattedIndexPatternColumn } from './operations/definitions/column_types';
import { isColumnFormatted, isColumnOfType } from './operations/definitions/helpers';

type OriginalColumn = { id: string } & GenericIndexPatternColumn;

Expand Down Expand Up @@ -148,32 +149,29 @@ function getExpressionForLayer(
},
};
}, {} as Record<string, OriginalColumn>);

const columnsWithFormatters = columnEntries.filter(
([, col]) =>
isColumnOfType<RangeIndexPatternColumn>('range', col) &&
(col.params?.format || col.params?.parentFormat)
) as Array<[string, RangeIndexPatternColumn]>;
const formatterOverrides: ExpressionAstFunction[] = columnsWithFormatters.map(
([id, col]: [string, RangeIndexPatternColumn]) => {
// TODO: improve the type handling here
const parentFormat = 'parentFormat' in col.params ? col.params!.parentFormat! : undefined;
const format = col.params!.format;
(isColumnOfType<RangeIndexPatternColumn>('range', col) && col.params?.parentFormat) ||
(isColumnFormatted(col) && col.params?.format)
) as Array<[string, RangeIndexPatternColumn | FormattedIndexPatternColumn]>;
const formatterOverrides: ExpressionAstFunction[] = columnsWithFormatters.map(([id, col]) => {
// TODO: improve the type handling here
const parentFormat = 'parentFormat' in col.params! ? col.params!.parentFormat! : undefined;
const format = col.params!.format;

const base: ExpressionAstFunction = {
type: 'function',
function: 'lens_format_column',
arguments: {
format: format ? [format.id] : [''],
columnId: [id],
decimals: typeof format?.params?.decimals === 'number' ? [format.params.decimals] : [],
parentFormat: parentFormat ? [JSON.stringify(parentFormat)] : [],
},
};
const base: ExpressionAstFunction = {
type: 'function',
function: 'lens_format_column',
arguments: {
format: format ? [format.id] : [''],
columnId: [id],
decimals: typeof format?.params?.decimals === 'number' ? [format.params.decimals] : [],
parentFormat: parentFormat ? [JSON.stringify(parentFormat)] : [],
},
};

return base;
}
);
return base;
});

const firstDateHistogramColumn = columnEntries.find(
([, col]) => col.operationType === 'date_histogram'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
TypedLensByValueInput,
PersistedIndexPatternLayer,
PieVisualizationState,
TermsIndexPatternColumn,
} from '../../../lens/public';
import { FilterStateStore, DataView } from '../../../../../src/plugins/data/common';
import { useKibana } from '../common/lib/kibana';
Expand Down Expand Up @@ -88,7 +89,7 @@ function getLensAttributes(
},
orderDirection: 'desc',
},
},
} as TermsIndexPatternColumn,
'ed999e9d-204c-465b-897f-fe1a125b39ed': {
sourceField: 'Records',
isBucketed: false,
Expand Down

0 comments on commit b4d509e

Please sign in to comment.