From e5823ec3f369a28de693f4edc8cae41a035267ae Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Thu, 30 Jul 2020 13:15:26 +0300 Subject: [PATCH] TSVB Inaccurate Group By (#73683) (#73776) Closes: #62081 --- .../common/{panel_types.js => panel_types.ts} | 0 .../common/ui_restrictions.ts | 11 +++++++++++ .../components/panel_config/gauge.js | 5 ++++- .../components/panel_config/metric.js | 4 +++- ...t_active_series.js => get_active_series.ts} | 18 +++++++++++++++--- 5 files changed, 33 insertions(+), 5 deletions(-) rename src/plugins/vis_type_timeseries/common/{panel_types.js => panel_types.ts} (100%) rename src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/{get_active_series.js => get_active_series.ts} (54%) diff --git a/src/plugins/vis_type_timeseries/common/panel_types.js b/src/plugins/vis_type_timeseries/common/panel_types.ts similarity index 100% rename from src/plugins/vis_type_timeseries/common/panel_types.js rename to src/plugins/vis_type_timeseries/common/panel_types.ts diff --git a/src/plugins/vis_type_timeseries/common/ui_restrictions.ts b/src/plugins/vis_type_timeseries/common/ui_restrictions.ts index 4508735f39ff90..e2911eb2d70e3b 100644 --- a/src/plugins/vis_type_timeseries/common/ui_restrictions.ts +++ b/src/plugins/vis_type_timeseries/common/ui_restrictions.ts @@ -17,6 +17,8 @@ * under the License. */ +import { PANEL_TYPES } from './panel_types'; + /** * UI Restrictions keys * @constant @@ -56,3 +58,12 @@ export type TimeseriesUIRestrictions = { export const DEFAULT_UI_RESTRICTION: UIRestrictions = { '*': true, }; + +/** limit on the number of series for the panel + * @constant + * @public + */ +export const limitOfSeries = { + [PANEL_TYPES.GAUGE]: 1, + [PANEL_TYPES.METRIC]: 2, +}; diff --git a/src/plugins/vis_type_timeseries/public/application/components/panel_config/gauge.js b/src/plugins/vis_type_timeseries/public/application/components/panel_config/gauge.js index eda49ccdca1783..18380680283ef5 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/panel_config/gauge.js +++ b/src/plugins/vis_type_timeseries/public/application/components/panel_config/gauge.js @@ -46,6 +46,9 @@ import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; import { QueryBarWrapper } from '../query_bar_wrapper'; import { getDefaultQueryLanguage } from '../lib/get_default_query_language'; +import { limitOfSeries } from '../../../../common/ui_restrictions'; +import { PANEL_TYPES } from '../../../../common/panel_types'; + class GaugePanelConfigUi extends Component { constructor(props) { super(props); @@ -110,7 +113,7 @@ class GaugePanelConfigUi extends Component { { - const shouldNotApplyFilter = ['gauge', 'markdown'].includes(panel.type); - return (panel.series || []).filter((series) => !series.hidden || shouldNotApplyFilter); +import { PanelSchema } from '../../../../common/types'; +import { PANEL_TYPES } from '../../../../common/panel_types'; +import { limitOfSeries } from '../../../../common/ui_restrictions'; + +export const getActiveSeries = (panel: PanelSchema) => { + let visibleSeries = panel.series || []; + + if (panel.type in limitOfSeries) { + visibleSeries = visibleSeries.slice(0, limitOfSeries[panel.type]); + } + + // Toogle visibility functionality for 'gauge', 'markdown' is not accessible + const shouldNotApplyFilter = [PANEL_TYPES.GAUGE, PANEL_TYPES.MARKDOWN].includes(panel.type); + + return visibleSeries.filter((series) => !series.hidden || shouldNotApplyFilter); };