-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into lens/operation-orde…
…ring
- Loading branch information
Showing
17 changed files
with
563 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
x-pack/legacy/plugins/lens/public/indexpattern_plugin/auto_date.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { TimeBuckets } from 'ui/time_buckets'; | ||
import dateMath from '@elastic/datemath'; | ||
import { | ||
ExpressionFunction, | ||
KibanaContext, | ||
} from '../../../../../../src/plugins/expressions/common'; | ||
|
||
interface LensAutoDateProps { | ||
aggConfigs: string; | ||
} | ||
|
||
export function getAutoInterval(ctx?: KibanaContext | null) { | ||
if (!ctx || !ctx.timeRange) { | ||
return; | ||
} | ||
|
||
const { timeRange } = ctx; | ||
const buckets = new TimeBuckets(); | ||
buckets.setInterval('auto'); | ||
buckets.setBounds({ | ||
min: dateMath.parse(timeRange.from), | ||
max: dateMath.parse(timeRange.to, { roundUp: true }), | ||
}); | ||
|
||
return buckets.getInterval(); | ||
} | ||
|
||
/** | ||
* Convert all 'auto' date histograms into a concrete value (e.g. 2h). | ||
* This allows us to support 'auto' on all date fields, and opens the | ||
* door to future customizations (e.g. adjusting the level of detail, etc). | ||
*/ | ||
export const autoDate: ExpressionFunction< | ||
'lens_auto_date', | ||
KibanaContext | null, | ||
LensAutoDateProps, | ||
string | ||
> = { | ||
name: 'lens_auto_date', | ||
aliases: [], | ||
help: '', | ||
context: { | ||
types: ['kibana_context', 'null'], | ||
}, | ||
args: { | ||
aggConfigs: { | ||
types: ['string'], | ||
default: '""', | ||
help: '', | ||
}, | ||
}, | ||
fn(ctx: KibanaContext, args: LensAutoDateProps) { | ||
const interval = getAutoInterval(ctx); | ||
|
||
if (!interval) { | ||
return args.aggConfigs; | ||
} | ||
|
||
const configs = JSON.parse(args.aggConfigs) as Array<{ | ||
type: string; | ||
params: { interval: string }; | ||
}>; | ||
|
||
const updatedConfigs = configs.map(c => { | ||
if (c.type !== 'date_histogram' || !c.params || c.params.interval !== 'auto') { | ||
return c; | ||
} | ||
|
||
return { | ||
...c, | ||
params: { | ||
...c.params, | ||
interval: interval.expression, | ||
}, | ||
}; | ||
}); | ||
|
||
return JSON.stringify(updatedConfigs); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.