Skip to content

Commit

Permalink
Make time_zone parameter properly volatile (#35536) (#35558)
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes authored and lukeelmers committed Apr 25, 2019
1 parent c69c416 commit d728c89
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { timefilter } from 'ui/timefilter';

const config = chrome.getUiSettingsClient();

describe('params', function () {
describe('date_histogram params', function () {

let paramWriter;
let writeInterval;
Expand Down Expand Up @@ -152,6 +152,12 @@ describe('params', function () {
expect(output.params).to.have.property('time_zone', 'Europe/Riga');
});

it('should use the fixed time_zone from the index pattern typeMeta', () => {
_.set(paramWriter.indexPattern, ['typeMeta', 'aggs', 'date_histogram', timeField, 'time_zone'], 'Europe/Rome');
const output = paramWriter.write({ field: timeField });
expect(output.params).to.have.property('time_zone', 'Europe/Rome');
});

afterEach(() => {
config.get.restore();
config.isDefault.restore();
Expand Down
29 changes: 19 additions & 10 deletions src/ui/public/agg_types/buckets/date_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,25 @@ export const dateHistogramBucketAgg = new BucketAggType({
},
{
name: 'time_zone',
default: () => {
const isDefaultTimezone = config.isDefault('dateFormat:tz');
return isDefaultTimezone ? detectedTimezone || tzOffset : config.get('dateFormat:tz');
},
serialize() {
// We don't want to store the `time_zone` parameter ever in the saved object for the visualization.
// If we would store this changing the time zone in Kibana would not affect any already saved visualizations
// anymore, which is not the desired behavior. So always returning undefined here, makes sure we're never
// saving that parameter and just keep it "transient".
return undefined;
default: undefined,
// We don't ever want this parameter to be serialized out (when saving or to URLs)
// since we do all the logic handling it "on the fly" in the `write` method, to prevent
// time_zones being persisted into saved_objects
serialize: () => undefined,
write: (agg, output) => {
// If a time_zone has been set explicitly always prefer this.
let tz = agg.params.time_zone;
if (!tz && agg.params.field) {
// If a field has been configured check the index pattern's typeMeta if a date_histogram on that
// field requires a specific time_zone
tz = _.get(agg.getIndexPattern(), ['typeMeta', 'aggs', 'date_histogram', agg.params.field.name, 'time_zone']);
}
if (!tz) {
// If the index pattern typeMeta data, didn't had a time zone assigned for the selected field use the configured tz
const isDefaultTimezone = config.isDefault('dateFormat:tz');
tz = isDefaultTimezone ? detectedTimezone || tzOffset : config.get('dateFormat:tz');
}
output.params.time_zone = tz;
},
},
{
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/rollup/public/visualize/editor_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ export function initEditorConfig() {

// Set date histogram time zone based on rollup capabilities
if (aggTypeName === 'date_histogram') {
const timezone = fieldAgg.time_zone || 'UTC';
const interval = fieldAgg.interval;
return {
time_zone: {
fixedValue: timezone,
},
interval: {
fixedValue: 'custom',
},
Expand Down

0 comments on commit d728c89

Please sign in to comment.