-
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.
[vega] Handle removal of deprecated date histogram interval (#109090)
* [vega] Handle removal of deprecated date histogram interval Fixes: #106352 * fix CI * add deprecation_interval_info * add test * Update vega_info_message.tsx * fix types * Update es_query_parser.ts * apply comments * fix error Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Uladzislau Lasitsa <[email protected]>
- Loading branch information
1 parent
a753f83
commit 61410a3
Showing
11 changed files
with
332 additions
and
75 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
135 changes: 135 additions & 0 deletions
135
src/plugins/vis_types/vega/public/components/deprecated_interval_info.test.tsx
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,135 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { shouldShowDeprecatedHistogramIntervalInfo } from './deprecated_interval_info'; | ||
|
||
describe('shouldShowDeprecatedHistogramIntervalInfo', () => { | ||
test('should show deprecated histogram interval', () => { | ||
expect( | ||
shouldShowDeprecatedHistogramIntervalInfo({ | ||
data: { | ||
url: { | ||
body: { | ||
aggs: { | ||
test: { | ||
date_histogram: { | ||
interval: 'day', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
).toBeTruthy(); | ||
|
||
expect( | ||
shouldShowDeprecatedHistogramIntervalInfo({ | ||
data: [ | ||
{ | ||
url: { | ||
body: { | ||
aggs: { | ||
test: { | ||
date_histogram: { | ||
interval: 'day', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
url: { | ||
body: { | ||
aggs: { | ||
test: { | ||
date_histogram: { | ||
calendar_interval: 'day', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}) | ||
).toBeTruthy(); | ||
}); | ||
|
||
test('should not show deprecated histogram interval', () => { | ||
expect( | ||
shouldShowDeprecatedHistogramIntervalInfo({ | ||
data: { | ||
url: { | ||
body: { | ||
aggs: { | ||
test: { | ||
date_histogram: { | ||
interval: { '%autointerval%': true }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
).toBeFalsy(); | ||
|
||
expect( | ||
shouldShowDeprecatedHistogramIntervalInfo({ | ||
data: { | ||
url: { | ||
body: { | ||
aggs: { | ||
test: { | ||
auto_date_histogram: { | ||
field: 'bytes', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
).toBeFalsy(); | ||
|
||
expect( | ||
shouldShowDeprecatedHistogramIntervalInfo({ | ||
data: [ | ||
{ | ||
url: { | ||
body: { | ||
aggs: { | ||
test: { | ||
date_histogram: { | ||
calendar_interval: 'week', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
url: { | ||
body: { | ||
aggs: { | ||
test: { | ||
date_histogram: { | ||
fixed_interval: '23d', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}) | ||
).toBeFalsy(); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx
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,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiCallOut, EuiButtonIcon } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { VegaSpec } from '../data_model/types'; | ||
import { getDocLinks } from '../services'; | ||
|
||
import { BUCKET_TYPES } from '../../../../data/public'; | ||
|
||
export const DeprecatedHistogramIntervalInfo = () => ( | ||
<EuiCallOut | ||
className="hide-for-sharing" | ||
data-test-subj="deprecatedHistogramIntervalInfo" | ||
size="s" | ||
title={ | ||
<FormattedMessage | ||
id="visTypeVega.deprecatedHistogramIntervalInfo.message" | ||
defaultMessage="Combined 'interval' field has been deprecated in favor of two new, | ||
explicit fields: 'calendar_interval' and 'fixed_interval'. {dateHistogramDoc}" | ||
values={{ | ||
dateHistogramDoc: ( | ||
<EuiButtonIcon | ||
iconType="popout" | ||
href={getDocLinks().links.aggs.date_histogram} | ||
target="_blank" | ||
/> | ||
), | ||
}} | ||
/> | ||
} | ||
iconType="help" | ||
/> | ||
); | ||
|
||
export const shouldShowDeprecatedHistogramIntervalInfo = (spec: VegaSpec) => { | ||
const data = Array.isArray(spec.data) ? spec?.data : [spec.data]; | ||
|
||
return data.some((dataItem = {}) => { | ||
const aggs = dataItem.url?.body?.aggs ?? {}; | ||
|
||
return Object.keys(aggs).some((key) => { | ||
const dateHistogram = aggs[key]?.[BUCKET_TYPES.DATE_HISTOGRAM] || {}; | ||
return 'interval' in dateHistogram && typeof dateHistogram.interval !== 'object'; | ||
}); | ||
}); | ||
}; |
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
45 changes: 45 additions & 0 deletions
45
src/plugins/vis_types/vega/public/components/vega_info_message.tsx
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,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { useMemo } from 'react'; | ||
import { parse } from 'hjson'; | ||
import { ExperimentalMapLayerInfo, shouldShowMapLayerInfo } from './experimental_map_vis_info'; | ||
import { | ||
DeprecatedHistogramIntervalInfo, | ||
shouldShowDeprecatedHistogramIntervalInfo, | ||
} from './deprecated_interval_info'; | ||
|
||
import type { Vis } from '../../../../visualizations/public'; | ||
import type { VegaSpec } from '../data_model/types'; | ||
|
||
const parseSpec = (spec: string) => { | ||
if (spec) { | ||
try { | ||
return parse(spec, { legacyRoot: false, keepWsc: true }); | ||
} catch (e) { | ||
// spec is invalid | ||
} | ||
} | ||
}; | ||
|
||
const InfoMessage = ({ spec }: { spec: string }) => { | ||
const vegaSpec: VegaSpec = useMemo(() => parseSpec(spec), [spec]); | ||
|
||
if (!vegaSpec) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
{shouldShowMapLayerInfo(vegaSpec) && <ExperimentalMapLayerInfo />} | ||
{shouldShowDeprecatedHistogramIntervalInfo(vegaSpec) && <DeprecatedHistogramIntervalInfo />} | ||
</> | ||
); | ||
}; | ||
|
||
export const getInfoMessage = (vis: Vis) => <InfoMessage spec={vis.params.spec} />; |
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.