Skip to content

Commit

Permalink
restructure fix
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Jun 18, 2021
1 parent 0fe6452 commit 717ba62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/plugins/data/common/search/aggs/agg_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { IAggType } from './agg_type';
import { writeParams } from './agg_params';
import { IAggConfigs } from './agg_configs';
import { parseTimeShift } from './utils';
import { calculateBounds } from '../../query';

type State = string | number | boolean | null | undefined | SerializableState;

Expand Down Expand Up @@ -193,9 +192,7 @@ export class AggConfig {
} else if (!this.aggConfigs.timeRange) {
return;
}
const resolvedBounds = calculateBounds(this.aggConfigs.timeRange, {
forceNow: this.aggConfigs.forceNow,
});
const resolvedBounds = this.aggConfigs.getResolvedTimeRange()!;
return moment.duration(moment(resolvedBounds.max).diff(resolvedBounds.min));
}
return parsedTimeShift;
Expand Down
11 changes: 10 additions & 1 deletion src/plugins/data/common/search/aggs/agg_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IAggType } from './agg_type';
import { AggTypesRegistryStart } from './agg_types_registry';
import { AggGroupNames } from './agg_groups';
import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern';
import { TimeRange, getTime, isRangeFilter } from '../../../common';
import { TimeRange, getTime, isRangeFilter, calculateBounds } from '../../../common';
import { IBucketAggConfig } from './buckets';
import { insertTimeShiftSplit, mergeTimeShifts } from './utils/time_splits';

Expand Down Expand Up @@ -127,6 +127,15 @@ export class AggConfigs {
this.aggs.forEach(updateAggTimeRange);
}

getResolvedTimeRange() {
return (
this.timeRange &&
calculateBounds(this.timeRange, {
forceNow: this.forceNow,
})
);
}

// clone method will reuse existing AggConfig in the list (will not create new instances)
clone({ enabledOnly = true } = {}) {
const filterAggs = (agg: AggConfig) => {
Expand Down

0 comments on commit 717ba62

Please sign in to comment.