Skip to content

Commit

Permalink
Use panel types enum
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof committed Nov 19, 2020
1 parent 9fcab26 commit 3909685
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
20 changes: 8 additions & 12 deletions src/plugins/vis_type_timeseries/common/panel_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@
* under the License.
*/

import { $Values } from '@kbn/utility-types';

export const PANEL_TYPES = {
TABLE: 'table',
GAUGE: 'gauge',
MARKDOWN: 'markdown',
TOP_N: 'top_n',
TIMESERIES: 'timeseries',
METRIC: 'metric',
};

export type PANEL_TYPES = $Values<typeof PANEL_TYPES>;
export enum PANEL_TYPES {
TABLE = 'table',
GAUGE = 'gauge',
MARKDOWN = 'markdown',
TOP_N = 'top_n',
TIMESERIES = 'timeseries',
METRIC = 'metric',
}
2 changes: 1 addition & 1 deletion src/plugins/vis_type_timeseries/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { TypeOf } from '@kbn/config-schema';
import { metricsItems, panel, seriesItems, visPayloadSchema } from './vis_schema';
import type { PANEL_TYPES } from './panel_types';
import { PANEL_TYPES } from './panel_types';
import { TimeseriesUIRestrictions } from './ui_restrictions';

export type SeriesItemsSchema = TypeOf<typeof seriesItems>;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_timeseries/common/ui_restrictions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const DEFAULT_UI_RESTRICTION: UIRestrictions = {
* @constant
* @public
*/
export const limitOfSeries = {
export const limitOfSeries: Partial<Record<PANEL_TYPES, number>> = {
[PANEL_TYPES.GAUGE]: 1,
[PANEL_TYPES.METRIC]: 2,
};
9 changes: 8 additions & 1 deletion src/plugins/vis_type_timeseries/common/vis_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,14 @@ export const panel = schema.object({
),
time_field: stringOptionalNullable,
time_range_mode: stringOptionalNullable,
type: stringRequired,
type: schema.oneOf([
schema.literal('table'),
schema.literal('gauge'),
schema.literal('markdown'),
schema.literal('top_n'),
schema.literal('timeseries'),
schema.literal('metric'),
]),
});

export const visPayloadSchema = schema.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const getActiveSeries = (panel: PanelSchema) => {
}

// Toogle visibility functionality for 'gauge', 'markdown' is not accessible
const shouldNotApplyFilter = [PANEL_TYPES.GAUGE, PANEL_TYPES.MARKDOWN].includes(panel.type);
const shouldNotApplyFilter =
PANEL_TYPES.GAUGE === panel.type || PANEL_TYPES.MARKDOWN === panel.type;

return visibleSeries.filter((series) => !series.hidden || shouldNotApplyFilter);
};

0 comments on commit 3909685

Please sign in to comment.