Skip to content

Commit

Permalink
Ensure serialize() is used by agg param type.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Apr 21, 2020
1 parent 9ff4f83 commit 09d97e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ const metricAggFilter = [
'!geo_centroid',
];

const parentPipelineType = i18n.translate(
export const parentPipelineType = i18n.translate(
'data.search.aggs.metrics.parentPipelineAggregationsSubtypeTitle',
{
defaultMessage: 'Parent Pipeline Aggregations',
}
);

const parentPipelineAggHelper = {
export const parentPipelineAggHelper = {
subtype: parentPipelineType,
params() {
return [
Expand All @@ -56,13 +56,9 @@ const parentPipelineAggHelper = {
name: 'customMetric',
type: 'agg',
allowedAggs: metricAggFilter,
makeAgg(termsAgg, state: any) {
state = state || { type: 'count' };

makeAgg(termsAgg, state = { type: 'count' }) {
const metricAgg = termsAgg.aggConfigs.createAggConfig(state, { addToAggConfigs: false });

metricAgg.id = termsAgg.id + '-metric';

return metricAgg;
},
modifyAggConfigOnSearchRequestStart: forwardModifyAggConfigOnSearchRequestStart(
Expand All @@ -89,5 +85,3 @@ const parentPipelineAggHelper = {
return subAgg ? subAgg.type.getFormat(subAgg) : new (FieldFormat.from(identity))();
},
};

export { parentPipelineAggHelper, parentPipelineType };
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ const metricAggFilter: string[] = [
];
const bucketAggFilter: string[] = [];

const siblingPipelineType = i18n.translate(
export const siblingPipelineType = i18n.translate(
'data.search.aggs.metrics.siblingPipelineAggregationsSubtypeTitle',
{
defaultMessage: 'Sibling pipeline aggregations',
}
);

const siblingPipelineAggHelper = {
export const siblingPipelineAggHelper = {
subtype: siblingPipelineType,
params() {
return [
Expand All @@ -59,11 +59,9 @@ const siblingPipelineAggHelper = {
type: 'agg',
allowedAggs: bucketAggFilter,
default: null,
makeAgg(agg: IMetricAggConfig, state: any) {
state = state || { type: 'date_histogram' };
makeAgg(agg: IMetricAggConfig, state = { type: 'date_histogram' }) {
const orderAgg = agg.aggConfigs.createAggConfig(state, { addToAggConfigs: false });
orderAgg.id = agg.id + '-bucket';

return orderAgg;
},
modifyAggConfigOnSearchRequestStart: forwardModifyAggConfigOnSearchRequestStart(
Expand All @@ -76,11 +74,9 @@ const siblingPipelineAggHelper = {
type: 'agg',
allowedAggs: metricAggFilter,
default: null,
makeAgg(agg: IMetricAggConfig, state: any) {
state = state || { type: 'count' };
makeAgg(agg: IMetricAggConfig, state: { type: 'count' }) {
const orderAgg = agg.aggConfigs.createAggConfig(state, { addToAggConfigs: false });
orderAgg.id = agg.id + '-metric';

return orderAgg;
},
modifyAggConfigOnSearchRequestStart: forwardModifyAggConfigOnSearchRequestStart(
Expand All @@ -98,5 +94,3 @@ const siblingPipelineAggHelper = {
: new (FieldFormat.from(identity))();
},
};

export { siblingPipelineAggHelper, siblingPipelineType };
8 changes: 4 additions & 4 deletions src/plugins/data/public/search/aggs/param_types/agg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* under the License.
*/

import { AggConfig, IAggConfig } from '../agg_config';
import { AggConfig, IAggConfig, AggConfigSerialized } from '../agg_config';
import { BaseParamType } from './base';

export class AggParamType<TAggConfig extends IAggConfig = IAggConfig> extends BaseParamType<
TAggConfig
> {
makeAgg: (agg: TAggConfig, state?: any) => TAggConfig;
makeAgg: (agg: TAggConfig, state?: AggConfigSerialized) => TAggConfig;
allowedAggs: string[] = [];

constructor(config: Record<string, any>) {
Expand All @@ -42,11 +42,11 @@ export class AggParamType<TAggConfig extends IAggConfig = IAggConfig> extends Ba
}
if (!config.serialize) {
this.serialize = (agg: TAggConfig) => {
return agg.toJSON();
return agg.serialize();
};
}
if (!config.deserialize) {
this.deserialize = (state: unknown, agg?: TAggConfig): TAggConfig => {
this.deserialize = (state: AggConfigSerialized, agg?: TAggConfig): TAggConfig => {
if (!agg) {
throw new Error('aggConfig was not provided to AggParamType deserialize function');
}
Expand Down

0 comments on commit 09d97e5

Please sign in to comment.